2 Star 17 Fork 10

GPER / ginadmin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_en.md 6.74 KB
一键复制 编辑 原始数据 按行查看 历史
GPER 提交于 2022-11-09 20:09 . 配置文件替换成yaml

GinAdmin

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!

login index

Dependence

Function list

:white_check_mark:Rbac

:white_check_mark:Logging

:white_check_mark:Template

:white_check_mark:Paginate

:white_check_mark:Docker deployment

:white_check_mark:Static resource packaging

:white_check_mark:Performance monitoring

Documents

:small_blue_diamond:Demourl

:small_blue_diamond:Getting Started

  1. Clone the project

    git clone https://github.com/gphper/ginadmin.git
  2. Download mod

    go mod download
  3. 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
  4. Run go run main.go Visit http://localhost:port/admin/login。Account:admin Password:111111

:small_blue_diamond:docker-compose

  1. 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
  2. Run docker-compose up

:small_blue_diamond:Project Directories

|--api  // Api Controllers
|--build 
|--cmd 
|--configs // Configration
|--deployments // docker-compose deployment
|--internal 
|--logs // Logging
|--pkg // Common method
|--web //Static resources

:small_blue_diamond:Paginate

  1. Use pkg/comment/util.go PageOperation
    adminDb := models.Db.Table("admin_users").Select("nickname","username").Where("uid != ?", 1)
    adminUserData := comment.PageOperation(c, adminDb, 1, &adminUserList)
  2. Use in template
    {{ .adminUserData.PageHtml }}

:small_blue_diamond:Logging

  1. System Log

    Set the routing middleware to collect system logs and error logs. internal/router/default.go

  2. 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",
    })
  3. 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

:small_blue_diamond:ORM

  1. Models must define TableName() string method, write the pointer implementing the structure into the GetModels method.

    func GetModels() []interface{} {
    	return []interface{}{
    		&AdminUsers{},
    		&AdminGroup{},
    	}
    }
  2. 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.

  3. 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.

:small_blue_diamond:Crontab

  • In pkg/cron/cron.go add timed task.

:small_blue_diamond:Configration

  1. 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"`
    }
  2. Second, in configs/config.yaml add configuration information

    [base]
    port=:8091
  3. Using configuration information in code.

    configs.App.BaseConf.Port

:small_blue_diamond:Template

  • 所有的后台模板都写到 web/views/template 目录下面,并且分目录存储,调用时按照 目录/模板名称 的方式调用

:small_blue_diamond:Rbac

  • 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
    },

:small_blue_diamond:API Doc

:small_blue_diamond:Deployment

  • Generate online version go build -tags=release .\cmd\ginadmin
  • Packaged static resource deployment go build -tags=embed .\cmd\ginadmin

:small_blue_diamond:Performance monitoring

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/gphper/ginadmin.git
git@gitee.com:gphper/ginadmin.git
gphper
ginadmin
ginadmin
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891