Code Monkey home page Code Monkey logo

golang-training's Introduction

Golang for Backend Developer

For more detail, please visit wiki

About the instructor

Phu, Tran Phong Developer and Instructor

I'm Phu, I'm a developer with a passion for teaching. I'm an academic advisor and instructor at Nordic Coder. My expertise and skills are about big data, distributed system, continuous deployment. I have been teaching many courses about backend and frontend such as Golang/Nodejs/PHP, ES/MySQL and Reactjs/Angular. I've helped students learn to code, improve their skills. I've been invited/collaborated by companies such as ABC to build the courses for training their employees.

I spend most of my time to researching latest methodologies, technologies, skills which should be have for developers to help them learn to make code better, code for fun and love, and make hard concepts easy to understand.

Welcome to my course, I am on way to help you.

About this course

This course is designed to get you up and running as fast as possible with Go. We'll quickly cover the basics, then dive into some of the more advanced features of the language.

After finishing this course, students will be able to learn how to:

  • Build high-performance concurrent programs with Golang
  • Build modern programs with Golang and its ecosystem such as CI/CD, GRPC
  • Build their own programs with hands-on mentoring from instructor

Course syllabus

Topic 1

  • An Introduction to Programming with Go and TDD
  • Overview on the fastest growing language and why we should learn Golang
  • Set up environments & code organization
  • Go characteristics and principles
  • How Go runs in single CPU and multiple CPUs
  • Reflection and Go's reflect package
  • Exercise: converting CSV to YAML using pointer
  • Exercise: cloning Lodash/Underscore to deep dive into Go
  • Exercise: practicing TDD methodology

Topic 2

  • Pointer in Go
  • Discover goroutines, channel, defer, panic, recover
  • Error handling in Go
  • Pipeline programming in Go
  • Working with database/mysql
  • Diving into Golang by designing a scripting/job
  • Strategy to watch scripting/job
  • Guide to setting up Docker/Laradock to install MySQL
  • Exercise: building a crawler
  • Exercise: following TDD and HTTP mock test

Topic 3

  • Diving into Golang by designing a RESTful API
  • CRUD service using Go with Gin/Echo framework
  • Login and JWT Authentication
  • HTTP Protocol, Cookie, Session
  • Load Balancing with Nginx, high performance, and scalability
  • Exercise: building a note service for Todo MVC application
  • Exercise: building an auto increment number and issues with multiple-CPU problems.
  • Exercise: writing Unit Testing Code and DB mock test

Topic 4

  • Design and apply microservices/serverless architecture using Go
  • RPC, GRPC and benefits from GRPC
  • How to design a new system with GRPC
  • How to integrate GRPC to an existing system
  • Exercise: using GRPC to refactor note service from topic 2
  • Exercise: API caching, DB connection pool
  • Exercise: writing a Voucher service

Topic 5

  • Understand about string operations and UTF8 encoding in Go
  • Best practices to develop a project with Go & final project
  • CI/CD, logging and monitoring on Production environment with ELK stack
  • Deploy a CI/CD for note services with Jenkins/K8S
  • Overview and requirements of the Final Project
  • Review and feedback on the course

Topic 6

  • Build your own open source software
  • Build a helper lib (ex: porting underscore)
  • Or build a http router
  • Or build a (micro) service to generate fake data
  • Or build an application with your own idea

Pre-work

A mini project to demonstrate students’ knowledge at input level

  • With a given URL of news website (Eg vnexpress.net, thesaigontimes.vn,...), create a crawler that:
  • Task 1: Can fetch the whole data from a news website then parse the data into specific piece as: title, published date, summary, body and author
  • Task 2: With any URLs found in the previously fetched data, repeat the task 1 until reaching maximum of 5 levels.

Final project

The final project is up to students with mentoring from instructor. The objective of the project is to:

  • Demonstrate understanding of Golang and its ecosystem.
  • Apply knowledge gained during the course by building an application/program such as a helper lib (ex: porting underscore), an http router, a (micro) service to generate fake data or create API for blog, e-commerce, Todo app, etc.

golang-training's People

Contributors

tpphu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-training's Issues

Thảo luận về nội dung 2 tuần học tiếp theo.

Chúng ta đã trải qua xem như 3 tuần về các chủ đề khác nhau

  1. Học về ngôn ngữ, viết mấy cái helpers function
  2. Học về crawler, để biết cách viết một cái job, backend hay viết job để xử lý các bài toán dạng như vậy
  3. Học về viết RestAPI
    Thiết kế chương trình sẽ còn 2 tuần nữa
    Sẽ tập trung giúp các bạn tư duy và hoàn thiện chương trình, deployment, testing, v.v...
    Và giúp các bạn làm một bài tập cuối cùng (final project)
    Tuy nhiên Phú nghĩ sẽ là thiếu sót nếu không dạy cho các bạn thêm một số khái niệm về microservices, với grpc, service discovery
    Nhưng vì còn 2 tuần nếu dạy cho các bạn cái này, sẽ là một lượng kiến thức không nhỏ, mà nếu các bạn không tự học thêm thì sẽ không vượt qua được.
    Nên Phú vẫn đang rất phân vân, không biết phải xử lý tình huống này như thế nào
    Bởi có một vài bạn trong lớp thì chịu học và làm bài tập, vượt khó để làm ở nhà, một vài bạn thì lại không có thời gian.
    Các bạn cho ý kiến nha.
    A) Hoàn thiện kiến thức lại ở những điểm mà mọi người chưa hiểu trong 3 tuần qua, và giúp mọi người làm final project của mình
    B) Tiếp tục học về microservices, grpc, service discovery
    Tất nhiên các bạn vẫn phải viết unit testing, làm CI/CD v.v.. 😄
    Nói chung kiến thức 3 tuần qua Phú nghĩ là cũng khá kute, giúp các bạn từ đó tư duy tiếp, vì thường backend chỉ có 3 bài toán cơ bản đó 😄
    Giờ thì thế giới thay đổi zồi, nên sẽ phức tạp hơn chút xíu ở một vài khía cạnh khác
    Các bạn si nghĩ, thật nghiêm túc nha, rồi trả lời mình
    Thường các bạn hào hứng cái gì cũng thích học mà hem có thích làm 😄

Upgrade thêm chương trình crawler

Theo như buổi học các bạn được khuyến khích/đề nghị làm thêm các yếu tố sau.

  1. Thiết kế chương trình để chạy trên nhiều instances với biến .env để xác định số lượng instance (node) cần chạy và instance hiện tại.
  2. Thiết kế chương trình để crawl được theo kiểu bất đồng bộ/đồng thời nhiều url, nhưng có limit về số lượng network được gọi.
  3. Viết chương trình cho đúng với việc cập nhật url đang running và idle.
  4. Add thêm parser vào chương trình
  5. Các thiết kế khác/bài toán khác mà các bạn nghĩ là các bạn muốn làm.

Thảo luận về pointer của Go

Ngữ cảnh:

Một bạn trong lớp khi học tới code về testing.T thì không hiểu khai báo:

func Test<TenFunctionCuaMinh>(t *testing.T) {

mục đích con trỏ để làm gì?

Nhờ xây dựng danh sách về tools, resource, link hay để chia sẽ cho nhau

Hi các bạn,

Mình nghĩ ai trong chúng ta trong quãng đường đi code cũng có không ít điều hay muốn chia sẽ:

  1. Về công cụ lập trình, tools
  2. Về các resource hay như ebook, khóa học v.v...
  3. Về cá link hay cần đọc.

Nên mình tạo ra thread này để chúng ta cùng chia sẽ với nhau nha.

Cảm ơn các bạn.

Thảo luận về việc xây dựng hệ thống crawler

Most features

  • Design Database for two missions: (1) to store crawled info/data, (2) to monitor/analyze/alert if software does not not work normally.
  • Design a crawler which is easy to scale
  • Plugin/Extension/Add-on architect to attach new site quickly without downtime
  • Avoid to be banned.

Database Design

Db có 2 yếu tố, 1 về nghiệp vụ Phú sẽ không bàn ở đây. Còn mình sẽ thiết kế để làm monitoring/analyzer/alert là chính, để biết hiện tại hệ thống đang xử lý những gì, đang bị lỗi ở domain nào, nguyên nhân gì v.v…

Software scaling

Để chạy với khả năng mở rộng cái cần là tư duy theo hướng gọi request, ajax và dùng json, html/jquery để parse thông tin. Nếu dùng browser như selenium, hay thậm chí headless browser như: https://github.com/GoogleChrome/puppeteer thì khả năng scale sẽ khó. Tuy nhiên các bạn có thể thử để có feeling.

Thậm chí chuẩn bị cả giải pháp về login.

Plugin architect

Mình sẽ thiết kế theo hướng generic để chỉ cần add thêm define của một domain khác là ready. Không phải code lại làm gì. Thậm chí có giao diện để vào cấu hình. Stop/Start bằng tool dashboard không cần phải restart hệ thống. Nếu muốn làm theo hướng này.

Dynamic and smart proxy usage

Proxy là phần khó nhất của hệ thống crawler, phải đảm bảo các yếu tố.

Chỉ có n request đến một domain trên 1 IP trong cùng một thời điểm. Chú ý là không phải request nào cũng có response giống nhau, nên phải tính theo thời gian trả về. Tránh DOS server.
Trong một khoảng thời gian t chỉ gọi k request đến domain để không bj chặn. Theo rule của các ông system admin hay làm.

Vì mỗi IP tương đương với một VPS, và quan trọng nữa là có thể proxy sẽ phục vụ nhiều account (nếu mua loại này), thậm chí mỗi server chỉ có thể gởi một lượng request nhất định do VPS có cấu hình thấp như 1-2CPU, và 1-2G RAM. Nên do vậy, tổng số request trên cùng một VPS ở một thời điểm phải thiết kế giới hạn theo con số x nào đó. Nguyên nhân là do vấn đề lệ thuộc vào nhà cung cấp proxy. Công ty cũng không thể tự làm cái này. Bởi vì, rất khó linh hoạt trong việc đổi IP, và mua ở số lượng lớn.
Phải đổi proxy dễ dàng, nếu vì code lỗi hay hư mà domain nó chặn cái IPs đó.

Nếu một request đến domain bị lỗi thì phải switch sang proxy khác, tức là cơ chế retry thông qua proxy.

Challenge: Pentagonal Number

Challenge

Have the function PentagonalNumber(num) read num which will be a positive integer and determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration. For example, in the image below you can see that on the first iteration there is only a single dot, on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots.

Image

Your program should return the number of dots that exist in the whole pentagon on the Nth iteration.

Sample Test Cases

Input:2
Output:6

Input:5
Output:51

Credits: https://www.coderbyte.com/editor/guest:Pentagonal%20Number:Go

Convert CSV To YAM

Cho các bạn một file, mô tả cấu trúc tỉnh thành,quận huyện,phường xã như bên dưới

RegionId,RegionName,DistrictId,DistrictName,WardId,WardName
1,Hồ Chí Minh,1,Quận 1,26734,Phường Tân Định
1,Hồ Chí Minh,1,Quận 1,26737,Phường Đa Kao
1,Hồ Chí Minh,1,Quận 1,26740,Phường Bến Nghé
1,Hồ Chí Minh,1,Quận 1,26743,Phường Bến Thành
1,Hồ Chí Minh,1,Quận 1,26746,Phường Nguyễn Thái Bình
1,Hồ Chí Minh,1,Quận 1,26749,Phường Phạm Ngũ Lão
1,Hồ Chí Minh,1,Quận 1,26752,Phường Cầu Ông Lãnh
1,Hồ Chí Minh,1,Quận 1,26755,Phường Cô Giang

Hãy chuyển sang file yaml với format như sau:

- id: 1
  name: Hồ Chí Minh
  districts:
  - id: 1
    name: Quận 1
    wards:
    - id: 26734
      name: Phường Tân Định
    - id: 26737
      name: Phường Đa Kao
    - id: 26740
      name: Phường Bến Nghé
    - id: 26743
      name: Phường Bến Thành
    - id: 26746
      name: Phường Nguyễn Thái Bình
    - id: 26749
      name: Phường Phạm Ngũ Lão
    - id: 26752
      name: Phường Cầu Ông Lãnh
    - id: 26755
      name: Phường Cô Giang

Week 1 - Keynotes

  1. Bài tập về nhà về clone lodash mục đích nhằm để chúng ta hiểu về ngôn ngữ Go.
  2. Các bạn cũng nên dành thời gian để làm lại bài tập về pointer
  3. Các bạn có thể trao đổi thêm trên thread này nha.

Ve concurrency

ConcurrencyConcepts

Thử nghiệm về việc modify cái file proto

Thử nghiệm sẽ như thế nào nếu trong quá trình chạy chương trình mà:

  1. File proto thay đổi
  2. Nhưng chỉ 1in2 client hoặc server được build với với file proto đó.

Để quan sát xem sẽ có các lỗi hay chương trình sẽ hoạt động thế nào?

Challenge: Maximum Square

Challenge

Have the function MaximalSquare(strArr) take the strArr parameter being passed which will be a 2D matrix of 0 and 1's, and determine the area of the largest square submatrix that contains all 1's. A square submatrix is one of equal width and height, and your program should return the area of the largest submatrix that contains only 1's. For example: if strArr is ["10100", "10111", "11111", "10010"] then this looks like the following matrix:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

For the input above, you can see the bolded 1's create the largest square submatrix of size 2x2, so your program should return the area which is 4. You can assume the input will not be empty.

Sample Test Cases

Case 1

Input:["0111", "1111", "1111", "1111"]
Output:9

Case 2

Input:["0111", "1101", "0111"]
Output:1

Xây dựng dự án open source về Proxy cho bài toán crawler

Các giải pháp chung là:

Mình sẽ làm một service sao cho:


  1. Mỗi một ip/proxy chỉ gọi đến một domain nào đó tại một thời điểm (concurrent) là n request (thường an toàn thì n = 1)


2. Mỗi một proxy chỉ cho phép tại một thời điểm, chỉ được gọi tối đa k request, vì proxy được nhà cung cấp bán cho nhiều thằng, gọi nhiều nó sẽ không bán cho mình nữa (k có thể bằng 10,20,50, tùy mình test)


  1. Mỗi một domain, chỉ cho phép gọi m request đến nói trong cùng một thời điểm, vì để tránh DDOS cái website đó, gọi nhiều nó có thể chết, không phải web nào cũng mạnh như vnexpress
Em có thể viết cái proxy này dưới dạng claim/release

Nếu lấy cái proxy đó xài thì đánh dấu là lấy nó ra, để gọi cho domain là gì?
Thì em sẽ làm được thuật toán như vậy.
Không cần cao siêu đâu.


Còn design có thể dùng http hoặc rpc (để tăng tốc communicate)
Ve nguyen tac minh design 2 diem:

- findAValidProxy(domain string)


- releaseProxy(proxy string, domain string)
findAndClaimAValidProxy(domain string)



> Cau hinh cho domain
thi minh lam file *.yml
1.

  • No toi da co bao nhieu request toi 1 thoi diem
2.
  • No cho phep 1 proxy goi den bao nhieu lan tai mot thoi diem

  • No cho phep goi bao nhieu requests trong khoang thoi gian t

    Vi du: 10 request/1phut


> Cau hinh cho file proxy


  • Add danh sach proxy
    
- Moi proxy dc phep goi bao nhieu request cung mot thoi diem

  • Timeout cua proxy



=> Khi ma khong co release, hoac la destination khong response ve


Week 2 - Keynotes

Discussion - How to build a crawler

  • Design Database for two missions: (1) to store crawled info/data, (2) to monitor/analyze/alert if software does not not work normally.
  • Design a crawler which is easy to scale
  • Plugin/Extension/Add-on architect to attach new site quickly without downtime
  • Avoid to be banned.

Database Design

Db có 2 yếu tố, 1 về nghiệp vụ Phú sẽ không bàn ở đây. Còn mình sẽ thiết kế để làm monitoring/analyzer/alert là chính, để biết hiện tại hệ thống đang xử lý những gì, đang bị lỗi ở domain nào, nguyên nhân gì v.v…

Software scaling

Để chạy với khả năng mở rộng cái cần là tư duy theo hướng gọi request, ajax và dùng json, html/jquery để parse thông tin. Nếu dùng browser như selenium, hay thậm chí headless browser như: https://github.com/GoogleChrome/puppeteer thì khả năng scale sẽ khó. Tuy nhiên các bạn có thể thử để có feeling.

Thậm chí chuẩn bị cả giải pháp về login.

Plugin architect

Mình sẽ thiết kế theo hướng generic để chỉ cần add thêm define của một domain khác là ready. Không phải code lại làm gì. Thậm chí có giao diện để vào cấu hình. Stop/Start bằng tool dashboard không cần phải restart hệ thống. Nếu muốn làm theo hướng này.

Dynamic and smart proxy usage

Proxy là phần khó nhất của hệ thống crawler, phải đảm bảo các yếu tố.

Chỉ có n request đến một domain trên 1 IP trong cùng một thời điểm. Chú ý là không phải request nào cũng có response giống nhau, nên phải tính theo thời gian trả về. Tránh DOS server.
Trong một khoảng thời gian t chỉ gọi k request đến domain để không bj chặn. Theo rule của các ông system admin hay làm.

Vì mỗi IP tương đương với một VPS, và quan trọng nữa là có thể proxy sẽ phục vụ nhiều account (nếu mua loại này), thậm chí mỗi server chỉ có thể gởi một lượng request nhất định do VPS có cấu hình thấp như 1-2CPU, và 1-2G RAM. Nên do vậy, tổng số request trên cùng một VPS ở một thời điểm phải thiết kế giới hạn theo con số x nào đó. Nguyên nhân là do vấn đề lệ thuộc vào nhà cung cấp proxy. Công ty cũng không thể tự làm cái này. Bởi vì, rất khó linh hoạt trong việc đổi IP, và mua ở số lượng lớn.
Phải đổi proxy dễ dàng, nếu vì code lỗi hay hư mà domain nó chặn cái IPs đó.

Nếu một request đến domain bị lỗi thì phải switch sang proxy khác, tức là cơ chế retry thông qua proxy.

Thảo luận về việc clone Underscore với Golang

Ý tưởng

Chúng ta cần xây dựng hệ thống này, với mục đích tạo ra một thư viện các functions dạng helper cho cá nhân, nhằm thúc đẩy các việc:

  • Giữ lại các đoạn code tốt của bạn thân để sử dụng cho các projects hoặc chia sẻ code cho người khác.
  • Có thể dễ dàng tối ưu lại code trong tương lai.
  • Tương lai có thể trở thành một open source nổi tiếng trở thành profile nổi tiếng cho bản thân.

Giải đáp thắc mắc về transformation

Ngữ cảnh

  1. Ngữ cảnh 1

When building an API, you may need a transformation layer that sits between your Eloquent models and the JSON responses that are actually returned to your application's users. Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON.

giống như model user có field password
khi em query trả về 1 model user, trong đó mặc định password

  1. Ngữ cảnh 2

model em muon field password đc hash thì sao thầy, ví dụ md5

Challenge: Pentagonal Number

Challenge

Have the function MaximalSquare(strArr) take the strArr parameter being passed which will be a 2D matrix of 0 and 1's, and determine the area of the largest square submatrix that contains all 1's. A square submatrix is one of equal width and height, and your program should return the area of the largest submatrix that contains only 1's. For example: if strArr is ["10100", "10111", "11111", "10010"] then this looks like the following matrix:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

For the input above, you can see the bolded 1's create the largest square submatrix of size 2x2, so your program should return the area which is 4. You can assume the input will not be empty.

Sample Test Cases

Case 1

Input:["0111", "1111", "1111", "1111"]
Output:9

Case 2

Input:["0111", "1101", "0111"]
Output:1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.