baishaojie 652673c0ff Merge branch 'feature/new-scheduled' of baishaojie/tmrgo into master | 6 mēneši atpakaļ | |
---|---|---|
comm | 1 gadu atpakaļ | |
conf | 6 mēneši atpakaļ | |
demo | 1 gadu atpakaļ | |
dist | 7 mēneši atpakaļ | |
docs | 1 gadu atpakaļ | |
html | 1 gadu atpakaļ | |
http | 6 mēneši atpakaļ | |
mdns | 1 gadu atpakaļ | |
middleware | 1 gadu atpakaļ | |
migration | 7 mēneši atpakaļ | |
models | 7 mēneši atpakaļ | |
module | 7 mēneši atpakaļ | |
pkg | 1 gadu atpakaļ | |
scripts | 1 gadu atpakaļ | |
service | 7 mēneši atpakaļ | |
test | 1 gadu atpakaļ | |
uploads | 7 mēneši atpakaļ | |
.drone-bak.yml | 7 mēneši atpakaļ | |
.gitignore | 1 gadu atpakaļ | |
Dockerfile | 7 mēneši atpakaļ | |
KPTAdmin64.exe | 6 mēneši atpakaļ | |
LICENSE | 1 gadu atpakaļ | |
Makefile | 7 mēneši atpakaļ | |
README.md | 1 gadu atpakaļ | |
go.mod | 7 mēneši atpakaļ | |
go.sum | 7 mēneši atpakaļ | |
linux64.bat | 1 gadu atpakaļ | |
main.go | 1 gadu atpakaļ | |
win32.bat | 10 mēneši atpakaļ | |
win64.bat | 10 mēneši atpakaļ |
一个go api 后端例子,包含JWT,RBAC(Casbin),增删改查, 一键生成 Restful API接口(不依赖orm)。
利用的casbin库, 将 user role menu 进行自动关联
项目启动时,会自动加载权限. 如有更改,会删除对应的权限,重新加载.
用户关联角色
角色关联菜单
权限关系为:
角色(role.name,menu.path,menu.method)
用户(user.username,role.name)
例如:
test /api/v1/users GET
zhuhongbin test
当zhuhongbin GET /api/v1/users 地址的时候,会去检查权限,因为他属于test组,同时组有对应权限,所以本次请求会通过。
用户 admin 有所有的权限,不进行权限匹配
登录接口 /auth 不进行验证
请求和接收 都是 传递 json 格式 数据
例如: 访问 /auth 获取token { "username": "admin", "password": "123456" } 访问 /api/v1/users 请求头设置 Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Create a go database and import SQL
创建一个库,然后导入sql,创建表!
You should modify conf/app.ini
[database]
Type = mysql
User = root
Password =
Host = 127.0.0.1:3306
Name = go
TablePrefix = go_
yum install go -y
cd $GOPATH/src/github.com/kptyun/go-admin
go build main.go
go run main.go
## 热编译,开发时使用
go get github.com/silenceper/gowatch
gowatch
Project information and existing API
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
Listening port is 8000
默认 账户 密码 都为 123456
不用orm依赖,直接输入表名字就可以 增删改查
get http://127.0.0.1:8000/api/restful/go_user
get http://127.0.0.1:8000/api/restful/go_user/1
post http://127.0.0.1:8000/api/restful/go_user
数据格式 json 支持批量
[{
"username":"hequan",
"password":"hequan1",
"created_on": "0",
"modified_on":"0",
"deleted_on":"0"
}]
put http://127.0.0.1:8000/api/restful/go_user/2
数据格式 json
{
"password":"654321"
}
delete http://127.0.0.1:8000/api/restful/go_user/2
- RESTful API
- Gorm
- logging
- Jwt-go
- Swagger
- Gin
- Graceful restart or stop (fvbock/endless)
- App configurable
- 一键生成 Restful API接口
##更新注释
swag init
TODO 列表