Project Structure

go-zero has its own project structure, usually generated through goctl.

Project dimension

  1. .
  2. ├── consumer
  3. ├── go.mod
  4. ├── internal
  5. └── model
  6. ├── job
  7. ├── pkg
  8. ├── restful
  9. ├── script
  10. └── service
  • consumer service consumer: queue
  • internal: project Internal Accessible Public Module
  • job: cron job service
  • pkg: External Accessible Public Module
  • restul:HTTP service directory, store services at service level
  • script:script service directory, store script as dimension service
  • service: gRPC service directory, store service as dimension

Service dimension

  1. example
  2. ├── etc
  3. └── example.yaml
  4. ├── main.go
  5. └── internal
  6. ├── config
  7. └── config.go
  8. ├── handler
  9. ├── xxxhandler.go
  10. └── xxxhandler.go
  11. ├── logic
  12. └── xxxlogic.go
  13. ├── svc
  14. └── servicecontext.go
  15. └── types
  16. └── types.go
  • example:single service directory, usually a microservice name
  • etc:Static Profile Directory
  • main.go:program boot entry file
  • internal:Internal file for a single service, only the current service is visible
  • config:Static Configuration File Static Body Declaration Directory
  • handler:handler directory, optional, this layer will be managed by the general HTTP service,handler as fixed suffix
  • logic:business directory, all business encoding files are stored below this directory,logic as fixed suffix
  • svc:Depends on Injection directory, all the required dependencies of the logic layer are required to make explicit injections here
  • types:structural directory