goark is a Go backend engineering practice project based on Gin. It provides a layered, maintainable, and scalable service structure with multiple app modules.
- Clear Project Structure: Inspired by project-layout, follows layered architecture principles, organized for team collaboration and long-term maintenance.
- Common Component Integration: Includes built-in examples for MySQL, Redis, and Elasticsearch.
- Full Link Logging: Provides a custom logging package
glogbased onzap, supporting full trace ID propagation across MySQL, Redis, ES, and HTTP calls. - Code Generation Tool: Comes with a command-line tool
goclithat can generate standardized code (including model, dao, object, dto, code, service, controller, router layers) based on config. - Swagger API Documentation: Automatically generate interactive API docs using
swaggofor easier frontend-backend collaboration and testing. - Docker Support: Includes a basic
Dockerfilefor containerized deployment. - Makefile Toolchain: Provides a rich set of make commands to simplify code build, run, generation, Swagger docs, and Docker deployment.
- Growing Golib Library: Common utility components are abstracted and reusable via the golib package.
Follows project-layout. Current structure:
.
├── apps
│ ├── demo
│ │ ├── cmd
│ │ ├── client
│ │ ├── config
│ │ ├── dao
│ │ ├── model
│ │ ├── docs
│ │ ├── internal
│ │ │ ├── controller
│ │ │ ├── dto
│ │ │ ├── router
│ │ │ └── service
│ │ ├── middleware
│ │ ├── object
│ │ └── scripts
│ └── iam
│ ├── cmd
│ ├── config
│ ├── docs
│ ├── dao
│ ├── model
│ ├── internal
│ │ ├── controller
│ │ ├── dto
│ │ ├── router
│ │ └── service
│ ├── object
│ └── scripts
├── pkg
│ ├── code
│ ├── dbclient
│ ├── testsetup
│ └── utils
└── scriptsInstall the CLI tool:
go install github.com/morehao/gocli@latestEnsure a code_gen.yaml config file exists under the application directory, e.g., goark/apps/demo/config/code_gen.yaml.
Run code generation commands:
# Generate full module based on table
make codegen APP=demo COMMAND=module
# Generate only model code
make codegen APP=demo COMMAND=model
# Generate API endpoint code
make codegen APP=demo COMMAND=apiSee generate for full documentation.
Install Swagger tool:
go install github.com/swaggo/swag/cmd/swag@latestGenerate Swagger docs:
make swag APP=demoAccess docs at (dev mode):
http://localhost:8099/demo/redocs
Build Docker image:
make docker-build APP=demoRun container:
make docker-run APP=demoInstall the cutter tool:
go install github.com/morehao/gocli@latestRun under the root of the template project (e.g., ./):
gocli cutter -d /goProject/yourAppNameThis will scaffold a new project named yourAppName under /goProject based on the current template.
See cutter for more usage details.
All related components are implemented in the golib package.