Skip to content

EngineerProOrg/BE-K09

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Newsfeed

https://drive.google.com/file/d/1Qnca6dITavOpRk4mYVik2BCb-G9nsaPi/view

  1. Init project structure We will have 3 services in this project:
  • HTTP server: works like a gateway to receive HTTP requests, validate and forward data to internal GRPC services.
  • User GRPC server: CRUD for users, posts, follows, likes, and comments
  • Newsfeed GRPC server: creates and returns newsfeed.

The project will be structured with the following folders:

  • /cmd: The entry point for each service, containing main function. We will initializes all configs, service dependencies and the main services will be called to run here.
  • /config: Configurations will be stored here.
  • /pkg: Our backend implementation will be here. We can use /internal with the same purpose with /pkg. It's based on personal choice.
    • /pkg/handler: This folder will handle the request/response to each service. For HTTP server, it will have a HTTP server (gin). For GRPC servers, it will have a GRPC server attached with GRPC handler. The data model for these handlers will be XxxRequest and XxxResponse structs.
    • /pkg/service: This folder will store the business logic. The data model is business model. Handler and Repo layers will communicate with this Service layer by the business model here.
    • /pkg/repo: This is where we perform the actual operations to the external storage, such as database, cache, message queues ... The data model is defined based on each external storage library.
    • /pkg/util: Utility functions defined here.
  1. Handler
  2. Service
  3. Repo
  4. Setup local external dependencies
  • MySQL:
    • Steps: pull image -> run mysql container with configs -> run SQL to create schemas
    • Pull: docker pull mysql
    • Run: docker run --name newsfeed-db -e MYSQL_ROOT_PASSWORD=123456 -p 33334:3306 -v {{absolute_path}}/data/mysql:/var/lib/mysql mysql
    • Exec mysql client in container: docker exec -it newsfeed-db mysql -p
  • Redis: TBD
  • Kafka: TBD
  • Prometheus/Grafana: TBD
  1. Generate GRPC servers and clients code:
  1. Run demo:
  • Setup MySQL in Section 5.
  • Run User GRPC server: go run cmd/user_grpc/main.go
  • Run HTTP server: go run cmd/http/main.go
  • Test request:
curl --location 'localhost:33333/signup' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "user_name": "testuser",
  "password": "123456",
  "first_name": "Test",
  "last_name": "User",
  "dob": "01-01-2000",
  "email": "[email protected]"
  }'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages