Golang 根据Gorm和Gin开发一个后台管理系统

回眸只為那壹抹淺笑 提交于 2021-01-13 08:24:33

    \\\\\\\\\\\

English | 简体中文

Project Guidelines

  • Web UI Framework:element-ui

  • Server Framework:gin

  • Grom Framework: gorm

1. Basic Introduction

1.1 Project structure

    │  ├─conf               (Config file)
│ ├─docs (swagger APIs docs)
│ ├─log (log file)
│ ├─public (public static file)
│ ├─static (head icon)
├─src
│ ├─controller (Controller)
│ ├─middleware (Middleware)
│ ├─models (Model entity)
│ ├─pkg (Project private package)
│ ├─adapter (Casbin adapter)
│ ├─app (Gin service response)
│ ├─codes (Response code)
│ ├─error (Project private error)
│ ├─gredis (Redis)
│ ├─query (Songo parase to SQL line)
│ ├─setting (Project setting)
│ ├─router (Router)
│ ├─rpc (RPC)
│ ├─service (services)
│ └─utils (common utilities)

1.1.1 Generate api docs

    cd grom-gin-admin
go get -u github.com/swaggo/swag/cmd/swag
swag init

1.2 Environment step

1.2.1 Install golang

  • If you have proxy to see olongfen.github.o

  • Else to see blog.olongfen.ltd

1.2.2 Install project Environment

In this project, my environment install by docker.

   git clone https://github.com/olongfen/gorm-gin-admin.git
    cd gorm-gin-admin
docker-compose up -d .

1.2.3 Project configure step

  • admin and general user rsa key

     admin.key admin.pub
    user.key user.pub
  • casbin model model_casbin.conf

  • project config

 when you run project the first that will be auto creating, and then you can run service, you can edit project config file
when project is running.

1.2.4 Run Service

    if you don't have config file which name project.config.yaml. you shuold run  project first auto generate config file,
then you try again can be running.
command: go run main.go

2. Technical selection

  • Frontend: using Element-UI based on vue,to code the page.

  • Backend: using Gin to quickly build basic RESTful API. Gin is a web framework written in Go (Golang).

  • Database: PostgreSQL ,using gorm2.0 to implement data manipulation.

  • Cache: using Redis to implement the recording of the JWT token of the currently active user and implement the multi-login restriction.

  • API: using Swagger of Gin to auto generate APIs docs。

  • Config: using gopkg.in/yaml.v2 to implement yaml config file。

  • Log: using github.com/sirupsen/logrus record logs。

3. Features

  • Authority management: Authority management based on jwt and casbin.

  • User management: The system administrator assigns user roles and role permissions.

  • Role management: Create the main object of permission control, and then assign different API permissions to the role.

  • Menu management: User dynamic menu configuration implementation, assigning different menus to different roles.

  • API management: Different users can call different API permissions.

4. To-do list

  •  upload & export Excel

  •  record manager actions

  •  RPC

  •  Cache token


本文分享自微信公众号 - Golang基础教程(olongfen)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!