Golang Programming Course with Real Project CRM eCommerce
Course - Go Backend Architecture
-
01
: Go backend: Các kiến trúc phổ phiến khởi tạo dự án BackEnd -
02
: Go backend: Setup dự án BackEnd- directory_structure
- run command
go mod init github.com/danhbuidcn/go_backend_api go mod tidy
-
03
: Go backend: GIN vs ROUTER- install gin web framework
go get -u github.com/gin-gonic/gin
- run
go run cmd/server/main.go
and callcurl http://0.0.0.0:8002/v1/ping/1515\?uid='12313'
- install gin web framework
-
04
: Go Backend: GIN vs MVC- run
go run cmd/server/main.go
and callcurl http://0.0.0.0:8002/v1/user/1
- run
-
05
: Go Backend: GIN vs ERROR HANDLER -
06
: Go backend: GIN vs LOGGER HANDLER- install zap
go get -u go.uber.org/zap
- run
go run cmd/cli/main.log.go
- install zap
-
07
: Go backend: GIN vs VIPER- install viper
go get github.com/spf13/viper
: a complete configuration solution - run
go run cmd/cli/viper/main.viper.go
- install viper
-
08
: Go Backend: GIN vs MIDDLEWARES- run
go run cmd/server/main.go
- call
curl http://0.0.0.0:8002/v1/ping/1515\?uid='12313'
- call
curl -H "Authorization: valid-token" http://0.0.0.0:8002/v1/user/1
- run
-
09
: Go Backend: GIN vs TEST MOCK- run
go get github.com/stretchr/testify
orgo mod tidy
- run test
cd tests/basic go test --v --coverprofile=coverage.out // OR go tool cover --html=coverage.out -o coverage.html open coverage.html
- run
-
10
: Go Backend: Cấu trúc file main.go cho DỰ ÁN LỚN- run
go run cmd/server/main.go
- run
-
11
: Go Backend: QUẢN LÝ LOGs CHO DỰ ÁN LỚN- run
go get gopkg.in/natefinch/lumberjack.v2
make run
- run
-
12
: Go Backend: Làm việc với Mysql Pool, Tại sao lại là Pool- run
go get -u gorm.io/gorm
gorm package - run
go get github.com/google/uuid
- setup docker mysql
docker-compose up -d docker exec -it mysql_shopdevgo bash # mysql -u root -proot > use shopdevgo > show tables; > desc go_db_user;
- run benchmark
cd tests/benchmark go test -bench=. -benchmem -count 5
- run
-
13
: Go Backend: Làm việc với Redis sentinel, cluster, Tại sao lại là Sentinel- install redis
go get github.com/redis/go-redis/v9
- install debugging
go install github.com/go-delve/delve/cmd/dlv@latest
- install redis
-
14
: Go Backend: Router cho TEAM LỚN -
15
: Go Kafka Backend: Kafka thực hành về mua bán cổ phiếu với các tình huống (xem Kafka section)- installation kafka:
go get -u github.com/segmentio/kafka-go
- run
docker-compose up -d go run cmd/cli/kafka/kafka.go curl -X POST "http://127.0.0.1:8999/action/stock?msg=HPG&type=MUA" // create topic docker exec -it broker kafka-topics --create --topic user_topic_001 --bootstrap-server broker:9091 --partitions 3 --replication-factor 1 docker exec -it broker kafka-topics --bootstrap-server broker:9091 --list // list consumer group docker exec -it broker kafka-consumer-groups --bootstrap-server broker:9091 --list // ensure JMX is opening docker exec -it kafka-ui /bin/sh nc -vz broker 19101
- access
http://localhost:8080/
- installation kafka:
-
16
: Go Interview: Không sử dụng Interface có được không? ĐƯỢC vs MẤT khi không sử dụng? -
17
: Go Backend: Interface cách triển khai nếu bạn là member -
18
: Go Backend: Nói về Dependency Injection và sủ dụng Wire trong dự án -
19
: Migrating Schema with GORM to MYSQL and DUMP Database- mysql command to go model
-- db up DROP TABLE IF EXISTS `go_crm_user`; -- new CREATE TABLE `go_crm_user` ( `user_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Account ID', `user_email` varchar(30) NOT NULL DEFAULT '' COMMENT 'Email', `user_phone` varchar(15) NOT NULL DEFAULT '' COMMENT 'Phone Number', `user_username` varchar(30) NOT NULL DEFAULT '' COMMENT 'Username', `user_password` varchar(32) NOT NULL DEFAULT '' COMMENT 'Password', `user_created_at` int NOT NULL DEFAULT '0' COMMENT 'Creation Time', `user_updated_at` int NOT NULL DEFAULT '0' COMMENT 'Update Time', `user_create_ip_at` varchar(12) NOT NULL DEFAULT '' COMMENT 'Creation IP', `user_last_login_at` int NOT NULL DEFAULT '0' COMMENT 'Last Login Time', `user_last_login_ip_at` varchar(12) NOT NULL DEFAULT '' COMMENT 'Last Login IP', `user_login_times` int NOT NULL DEFAULT '0' COMMENT 'Login Times', `user_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Status 1:enable, 0:disable, -1:deleted', PRIMARY KEY (`user_id`), KEY `idx_email` (`user_email`), KEY `idx_phone` (`user_phone`), KEY `idx_username` (`user_username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Account'; DESC go_crm_user;
docker-compose up go get -u gorm.io/gen make run // command to export database to .sql file docker exec -it mysql_shopdevgo mysqldump -uroot -proot --databases shopdevgo --add-drop-database --add-drop-table --add-drop-trigger --add-locks --no-data > migrations/shopdevgo.sql
-
20
: Chiến đấu DOCKER, sai lầm cách build này Level 0, 1- comand : gin
cd demo_docker go mod init example.com/demo_docker touch main.go touch Dockerfile go get -u github.com/gin-gonic/gin touch test.http go run . GET http://localhost:8080/ping
- build Dockerfile from hub.docker
-
21
: Chiến đấu với Docker Link, Docker Compose build Project Level 2- build go with docker and link to mysql container
docker-compose up -d # run mysql container docker build . -t backend_api # build go project docker network connect bridge mysql_shopdevgo # connect bridge to mysql_shopdevgo network docker run --link mysql_shopdevgo:mysql_shopdevgo -p 8002:8002 backend_api docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis docker start backend_shopdevgo # star backend_api if it's unhealthy
-
22
: Công ty đề nghị chuyển GORM sang SQLC như thế nào?- command
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest cd sqlc_practice sqlc generate go run cmd/main.go
-
23
: Goose (A database migration tool) hiệu suất cao của dân BACKEND- Goose install:
go install github.com/pressly/goose/v3/cmd/goose@latest
- Command:
cd goose go mod init example.com/goose-demo goose --version cd sql goose/sql$ goose create order sql goose/sql$ docker-compose up -d goose/sql$ goose mysql "root:root@tcp(127.0.0.1:3308)/shopdevgo" up goose/sql$ goose mysql "root:root@tcp(127.0.0.1:3308)/shopdevgo" down cd .. goose$ make down goose$ make up
- Goose install:
-
24
: User Register Send OTP To Email Template- smtp
- REST Client tool to send requests
- command:
cp .env.sample .env // update your key docker-compose down -v // down and remove volume docker-compose build --no-cache // Cần build lại mỗi lần thay đổi mã nguồn, nếu sử dụng scratch docker-compose up docker ps -a --filter "name=_shopdevgo" docker logs backend_shopdevgo docker exec -it backend_shopdevgo sh
- Using SendGrid's Go Library
- Setting sendgrid:
- app.sendgrid.com/settings/sender_auth/senders => tạo sender [email protected]
- Send request and view app.sendgrid.com/email_activity
-
25
: Loại đại ca GORM thay thế tân binh GOOSE vs SQLC hệ thống trở nên mạnh mẽ- Command
docker-compose up docker ps --filter "name=_shopdevgo" sudo chmod -R 777 internal/model/goose_db_version.gen.go docker exec -it mysql_shopdevgo bash bash# mysql -uroot -proot mysql> use shopdevgo; mysql> show tables; goose -dir sql/schema create pre_go_crm_user_c sql make upse go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest sqlc generate
-
26
: Làm việc Microservices, go handler OTP, java send OTP to Aws -
27
: Triển khai Kafka Microservices- Command:
docker-compose up
- Tuy cập
http://localhost:8080
tạo topicotp-auth-topic
01: kafka dùng khi nào ?
Kafka đã thay đổi hệ thống eCommerce trở nên mạnh mẽ như thế nào so với cách cũ02: kafka có 7 mấu chốt
Kafka: Đây là 7 thứ đủ để bắt đầu cuộc chiến TOPIC, PARTITIONs và Consumer Group03: kafka vs stocks
Kafka: Ứng dụng thực tế hệ thống MUA BÁN Backend API04: sync data from mysql to kafka
KỸ SƯ CAO CẤP: Cách đồng bộ dữ liệu Mysql to Kafka sử dụng Debezium với N Tables tốc độ REALTIME
- godepgraph: godepgraph is a packages dependency graph visualization tool for your local go module project.