layout-go-zero
Golang服务开发架构
目录结构
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
路由规则
请求方法 | API 示例 | 说明 |
---|
GET | /user | 获取列表 |
GET | /user/{id} | 获取详情 |
POST | /user | 新增 |
PUT | /user/{id} | 修改 |
DELETE | /user/{id} | 删除 |
所有命令
启动web服务:
$ go run ./app/user_http/main.go
启动定时服务:
$ go run ./cron/main.go
启动队列服务:
$ go run ./queue/main.go
生成web文档:
$ swag init --parseDependency --parseInternal -g ./app/user_http/main.go -o ./app/user_http/docs
cmd命令:
$ go run ./inlet/cmd -h
Default will run "serve" command, you can use "-h" flag to see all subcommands
Usage:
[command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
make Generate file and code
migrate Run database migration
seed Insert fake data to the database
service 业务层cmd
Flags:
-h, --help help for this command
-p, --path string example: --path=./config/setting.yaml (default "./config/setting.yaml")
Use " [command] --help" for more information about a command.
make 命令:
$ go run ./cmd/main.go make -h
Generate file and code
Usage:
make [command]
Available Commands:
cmd_service Create a command, should be snake_case, example: make cmd_service user user
controller Create api controller,example: make controller user_http user
factory Create model's factory file, example: make factory user
gen Generate file and code, example: make gen
migration Create a migration file, example: make migration user
model Crate model file, example: make model user
request Create request file, example make request user_http user
route Crate route file, example: make route user_http user
seeder Create seeder file, example: make seeder user
Flags:
-h, --help help for make
Use " make [command] --help" for more information about a command.
migrate 命令:
$ go run ./cmd/main.go migrate -h
Run database migration
Usage:
migrate [command]
Available Commands:
down Reverse the up command
fresh Drop all tables and re-run all migrations
refresh Reset and re-run all migrations
reset Rollback all orm migrations
up Run unMigrated migrations
Flags:
-h, --help help for migrate
Use " migrate [command] --help" for more information about a command.
seed 命令:
$ go run ./cmd/main.go seed -h
Insert fake data to the orm
Usage:
seed [flags]
Flags:
-h, --help help for seed