Skip to content

Latest commit

 

History

History
254 lines (184 loc) · 6.74 KB

README_en.md

File metadata and controls

254 lines (184 loc) · 6.74 KB

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

  • golang > 1.8
  • Gin
  • BootStrap
  • LayUi
  • WebUpload
  • Light Year Admin Using Iframe

Function list

✅Rbac

✅Logging

✅Template

✅Paginate

✅Docker deployment

✅Static resource packaging

✅Performance monitoring

Documents

  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

  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

|--api  // Api Controllers
|--build 
|--cmd 
|--configs // Configration
|--deployments // docker-compose deployment
|--internal 
|--logs // Logging
|--pkg // Common method
|--web //Static resources
  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 }}
  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

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

  • In pkg/cron/cron.go add timed task.
  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
  • 所有的后台模板都写到 web/views/template 目录下面,并且分目录存储,调用时按照 目录/模板名称 的方式调用

🔹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
    },
  • Generate online version go build -tags=release .\cmd\ginadmin
  • Packaged static resource deployment go build -tags=embed .\cmd\ginadmin