go-demo web
Build & Run
go mod download
go build
./web
Systemd
可执行目录结构:
/usr/local/demo-web
├── web
└── web.yaml
Systemd 脚本:
cp init/demo-web.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start demo-web
Air 热加载
go install github.com/cosmtrek/air@latest
air init
air
Swagger
安装本地的 swagger 程序:
go install github.com/swaggo/swag/cmd/swag
项目已经集成 gin-swagger, 在项目目录下执行:
swag init -g internal/web/swagger.go -o "docs"
可修改 Air 参数实现热加载自动生成 Swagger:
[build]
cmd = "swag init -g internal/web/swagger.go -o docs && go build -o ./tmp/main ."
访问 Swagger: http://localhost:8080/swagger/index.html
pprof
go tool pprof http://localhost:8080/debug/pprof/heap
go tool pprof http://localhost:8080/debug/pprof/profile
go tool pprof http://localhost:8080/debug/pprof/block