Categorygithub.com/jangozw/go-quick-api
module
1.0.1
Repository: https://github.com/jangozw/go-quick-api.git
Documentation: pkg.go.dev

# README

go-quick-api

go api开发基础项目库,以gin框架为基础简要封装,广泛适用于快速web API开发

适合人群:

  • web工程师,curd必备利器
  • go新手,体验如何组织项目机构以及开发以一个轻量的完成应用,从0到1
  • 其他语言转go, 照猫画虎写一个接口实例感受项目流程用go如何实现

基础组件

运行

方式一: 在本地环境运行

1, clone 项目到本地

git clone [email protected]:jangozw/go-quick-api.git yourpath

2,修改根目录配置文件 config.ini,主要是修改数据库和redis账号密码,打开秒懂

3, 启动

go run cmd/app/main.go

方式二: docker 运行

1, 构建镜像

make build-docker

2, 启动

在根目录

docker-compose up

启动成功控制台: 22:9:39 app | [GIN-debug] GET / --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (3 handlers) [GIN-debug] POST /sample/login --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (3 handlers) 22:9:39 app | [GIN-debug] POST /sample/logout --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (4 handlers) [GIN-debug] POST /sample/user --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (4 handlers) [GIN-debug] GET /sample/user/list --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (4 handlers) [GIN-debug] GET /sample/user/detail --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (4 handlers) [GIN-debug] GET /v1/test --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (3 handlers) [GIN-debug] GET /v1/config --> github.com/jangozw/go-quick-api/pkg/app.WarpApi.func1 (4 handlers) [GIN-debug] Listening and serving HTTP on :8080

打印的是定义的api接口,此时可以请求了

请求接口

浏览器或postman输入:

http://127.0.0.1:8080

或直接命令行:

curl http://127.0.0.1:8080

请求登陆接口:

curl -X POST -H "Content-Type: application/json"  -d '{"mobile": "13012345678", "pwd": "123456"}' http://127.0.0.1:8080/sample/login

返回:

{"code":200,"msg":"请求成功","timestamp":1594910140,"data":{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVpZCI6MX0sImV4cCI6MTU5NTUxMDE0MCwiaXNzIjoiaXNzdWVyIn0.zpa5Bfmi31aSCSXBef7ixbt0aQ_Z5zkRsahkF6XttTE"}}

请求header的 Authorization 值设为登陆返回的token,即可访问其他需要验证身份的接口

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author