The project is a background management platform based on gin framework. Although many people think that go is used to develop high-performance server-side projects, it is inevitable that there is a need to do web management side. You can't use other languages to develop it. Therefore, the ginadmin project has been integrated. Please give more comments and corrections!
Rbac
Logging
Template
Paginate
Docker deployment
Static resource packaging
Performance monitoring
Clone the project
git clone https://github.com/gphper/ginadmin.git
Download mod
go mod download
Config configs/config.yaml
[mysql]
username=root
password=123456
database=db_beego
host=127.0.0.1
port=3306
max_open_conn=50
max_idle_conn=20
[redis]
addr=localhost:6379
db=0
password=""
[session]
session_name=gosession_id
[base]
port=:8091
Run go run main.go
Visit http://localhost:port/admin/login。Account:admin Password:111111
Replace configs/config.yaml
[mysql]
username=docker
password=123456
database=docker_mysql
host=localmysql
port=3306
max_open_conn=50
max_idle_conn=20
[session]
session_name=gosession_id
[base]
host=0.0.0.0
port=20010
fill_data=true
Run docker-compose up
|--api // Api Controllers
|--build
|--cmd
|--configs // Configration
|--deployments // docker-compose deployment
|--internal
|--logs // Logging
|--pkg // Common method
|--web //Static resources
pkg/comment/util.go
PageOperation
adminDb := models.Db.Table("admin_users").Select("nickname","username").Where("uid != ?", 1)
adminUserData := comment.PageOperation(c, adminDb, 1, &adminUserList)
{{ .adminUserData.PageHtml }}
System Log
Set the routing middleware to collect system logs and error logs. internal/router/default.go
Custom Log
Use loggers.LogInfo()
in github.com/gphper/ginadmin/pkg/loggers
loggers.LogInfo("admin", "this is a info message", map[string]string{
"user_info": "this is a user info",
})
Switching storage media
System Log in internal/router/default.go
switch storage media
Custom Log in loggers.LogInfo
method usefacade.NewZaplog
and facade.NewRedislog
switch storage media
Models must define TableName() string
method, write the pointer implementing the structure into the GetModels
method.
func GetModels() []interface{} {
return []interface{}{
&AdminUsers{},
&AdminGroup{},
}
}
Model needs to inherit BaseModle
and implement TableName
method. If it needs to initialize and fill data, it needs to implement FillData()
method and write the code to be executed for data filling into the function body. Please refer to AdminUsers
for details.
You can set full_ Data
and migrate_ table
in the ini configuration file to control whether the data table and data are automatically migrated and seeded when the program is restarted.
pkg/cron/cron.go
add timed task.First, in configs/config.go
add struct type of configuration item,eg:
type AppConf struct {
BaseConf `ini:"base"`
}
type BaseConf struct {
Port string `ini:"port"`
}
Second, in configs/config.yaml
add configuration information
[base]
port=:8091
Using configuration information in code.
configs.App.BaseConf.Port
web/views/template
目录下面,并且分目录存储,调用时按照 目录/模板名称
的方式调用In internal/menu/menu.go
define permission name,then edit permissions in user group management.
casbin版集成了casbin权限管理框架,官方地址:casbin
框架中的常用方法定义在 comment/auth/casbinauth/asbin.go
文件中
在控制器中可用从 gin.context
获取登录用户信息
info,_ := c.Get("userInfo")
template 中判断权限的函数 judgeContainPriv
定义在 pkg/template/default.go
文件下
"judgeContainPriv": func(username string, obj string, act string) bool {
if username == "admin" {
return true
}
ok, err := casbinauth.Check(username, obj, act)
if !ok || err != nil {
return false
}
return true
},
Use swagg generate api doc.
swag init -g cmd/ginadmin/main.go
On root path run go build .\cmd\ginadmin\
,then visit http://localhost:20010/swagger/index.html
go build -tags=release .\cmd\ginadmin
go build -tags=embed .\cmd\ginadmin
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。