From dfe513192675121704e0ba6c41d47665bab2ca82 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 2 Jul 2021 15:22:13 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=B3=A8=E9=87=8A=E6=A0=BC=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=8E=A8=E8=8D=90=E7=9A=84=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?.https://github.com/golang/go/wiki/CodeReviewComments#comment-s?= =?UTF-8?q?entences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/template/server/api.go.tpl | 6 ++ server/resource/template/server/model.go.tpl | 2 + server/resource/template/server/router.go.tpl | 1 + .../resource/template/server/service.go.tpl | 72 +++++++++---------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/server/resource/template/server/api.go.tpl b/server/resource/template/server/api.go.tpl index 9df3e153..0ab3dea7 100644 --- a/server/resource/template/server/api.go.tpl +++ b/server/resource/template/server/api.go.tpl @@ -10,6 +10,7 @@ import ( "go.uber.org/zap" ) +// Create{{.StructName}} 创建{{.StructName}} // @Tags {{.StructName}} // @Summary 创建{{.StructName}} // @Security ApiKeyAuth @@ -29,6 +30,7 @@ func Create{{.StructName}}(c *gin.Context) { } } +// Delete{{.StructName}} 删除{{.StructName}} // @Tags {{.StructName}} // @Summary 删除{{.StructName}} // @Security ApiKeyAuth @@ -48,6 +50,7 @@ func Delete{{.StructName}}(c *gin.Context) { } } +// Delete{{.StructName}}ByIds 批量删除{{.StructName}} // @Tags {{.StructName}} // @Summary 批量删除{{.StructName}} // @Security ApiKeyAuth @@ -67,6 +70,7 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { } } +// Update{{.StructName}} 更新{{.StructName}} // @Tags {{.StructName}} // @Summary 更新{{.StructName}} // @Security ApiKeyAuth @@ -86,6 +90,7 @@ func Update{{.StructName}}(c *gin.Context) { } } +// Find{{.StructName}} 用id查询{{.StructName}} // @Tags {{.StructName}} // @Summary 用id查询{{.StructName}} // @Security ApiKeyAuth @@ -105,6 +110,7 @@ func Find{{.StructName}}(c *gin.Context) { } } +// Get{{.StructName}}List 分页获取{{.StructName}}列表 // @Tags {{.StructName}} // @Summary 分页获取{{.StructName}}列表 // @Security ApiKeyAuth diff --git a/server/resource/template/server/model.go.tpl b/server/resource/template/server/model.go.tpl index bbc7331b..b0b14e83 100644 --- a/server/resource/template/server/model.go.tpl +++ b/server/resource/template/server/model.go.tpl @@ -5,6 +5,7 @@ import ( "gin-vue-admin/global" ) +// {{.StructName}} 结构体 // 如果含有time.Time 请自行import time包 type {{.StructName}} struct { global.GVA_MODEL {{- range .Fields}} @@ -16,6 +17,7 @@ type {{.StructName}} struct { } {{ if .TableName }} +// TableName {{.StructName}} 表名 func ({{.StructName}}) TableName() string { return "{{.TableName}}" } diff --git a/server/resource/template/server/router.go.tpl b/server/resource/template/server/router.go.tpl index 87c41885..0e649589 100644 --- a/server/resource/template/server/router.go.tpl +++ b/server/resource/template/server/router.go.tpl @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" ) +// Init{{.StructName}}Router 初始化 {{.StructName}} 路由信息 func Init{{.StructName}}Router(Router *gin.RouterGroup) { {{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord()) { diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index 323f7956..b9b5111f 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -6,67 +6,67 @@ import ( "gin-vue-admin/model/request" ) -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Create{{.StructName}} -//@description: 创建{{.StructName}}记录 -//@param: {{.Abbreviation}} model.{{.StructName}} -//@return: err error - +// Create{{.StructName}} 创建{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Create{{.StructName}} +// @description: 创建{{.StructName}}记录 +// @param: {{.Abbreviation}} model.{{.StructName}} +// @return: err error func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Create(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Delete{{.StructName}} -//@description: 删除{{.StructName}}记录 -//@param: {{.Abbreviation}} model.{{.StructName}} -//@return: err error - +// Delete{{.StructName}} 删除{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Delete{{.StructName}} +// @description: 删除{{.StructName}}记录 +// @param: {{.Abbreviation}} model.{{.StructName}} +// @return: err error func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Delete{{.StructName}}ByIds -//@description: 批量删除{{.StructName}}记录 -//@param: ids request.IdsReq -//@return: err error - +// Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Delete{{.StructName}}ByIds +// @description: 批量删除{{.StructName}}记录 +// @param: ids request.IdsReq +// @return: err error func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Update{{.StructName}} -//@description: 更新{{.StructName}}记录 -//@param: {{.Abbreviation}} *model.{{.StructName}} -//@return: err error - +// Update{{.StructName}} 更新{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Update{{.StructName}} +// @description: 更新{{.StructName}}记录 +// @param: {{.Abbreviation}} *model.{{.StructName}} +// @return: err error func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Get{{.StructName}} -//@description: 根据id获取{{.StructName}}记录 -//@param: id uint -//@return: err error, {{.Abbreviation}} model.{{.StructName}} - +// Get{{.StructName}} 根据id获取{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Get{{.StructName}} +// @description: 根据id获取{{.StructName}}记录 +// @param: id uint +// @return: err error, {{.Abbreviation}} model.{{.StructName}} func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error return } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Get{{.StructName}}InfoList -//@description: 分页获取{{.StructName}}记录 -//@param: info request.{{.StructName}}Search -//@return: err error, list interface{}, total int64 - +// Get{{.StructName}}InfoList 分页获取{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Get{{.StructName}}InfoList +// @description: 分页获取{{.StructName}}记录 +// @param: info request.{{.StructName}}Search +// @return: err error, list interface{}, total int64 func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) From 7d94a53c39f14dc523e2aeef146049a94ef4b9f6 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 2 Jul 2021 17:01:30 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=E4=B8=ADAPI=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=8F=8F=E8=BF=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/view/systemTools/autoCode/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index 9804e036..98a75982 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -60,7 +60,7 @@ - + From 537057c86aa8959f6142a03d17b19680c91648d3 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 2 Jul 2021 17:03:49 +0800 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81=E4=B8=AD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/view/systemTools/autoCode/index.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index 98a75982..d627aa42 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -58,7 +58,7 @@ - + @@ -199,7 +199,7 @@ export default { packageName: [ { required: true, - message: '文件名称:sys_xxxx_xxxx', + message: '文件名称:sysXxxxXxxx', trigger: 'blur' } ] From f77d6b92094b555e35f2271e72aa1aeb84164acc Mon Sep 17 00:00:00 2001 From: SliverHorn <45428434+SliverHorn@users.noreply.github.com> Date: Fri, 2 Jul 2021 17:18:51 +0800 Subject: [PATCH 4/9] Update service.go.tpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 回参与入参,我觉得可以去掉,基本调用的时候都知道是什么类型,就没必要写了 --- .../resource/template/server/service.go.tpl | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index b9b5111f..b1da36c5 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -7,66 +7,42 @@ import ( ) // Create{{.StructName}} 创建{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Create{{.StructName}} -// @description: 创建{{.StructName}}记录 -// @param: {{.Abbreviation}} model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Create(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}} 删除{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Delete{{.StructName}} -// @description: 删除{{.StructName}}记录 -// @param: {{.Abbreviation}} model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Delete{{.StructName}}ByIds -// @description: 批量删除{{.StructName}}记录 -// @param: ids request.IdsReq -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error return err } // Update{{.StructName}} 更新{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Update{{.StructName}} -// @description: 更新{{.StructName}}记录 -// @param: {{.Abbreviation}} *model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } // Get{{.StructName}} 根据id获取{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Get{{.StructName}} -// @description: 根据id获取{{.StructName}}记录 -// @param: id uint -// @return: err error, {{.Abbreviation}} model.{{.StructName}} +// Author [piexlmax](https://github.com/piexlmax) func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error return } // Get{{.StructName}}InfoList 分页获取{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Get{{.StructName}}InfoList -// @description: 分页获取{{.StructName}}记录 -// @param: info request.{{.StructName}}Search -// @return: err error, list interface{}, total int64 +// Author [piexlmax](https://github.com/piexlmax) func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) @@ -102,4 +78,4 @@ func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, err = db.Count(&total).Error err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error return err, {{.Abbreviation}}s, total -} \ No newline at end of file +} From f96b415d4d21707a32ba6bc495ace73b6073c0d6 Mon Sep 17 00:00:00 2001 From: SliverHorn <45428434+SliverHorn@users.noreply.github.com> Date: Sat, 3 Jul 2021 00:29:16 +0800 Subject: [PATCH 5/9] Update Dockerfile --- server/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index 57ccc63f..8be43216 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,11 +1,9 @@ FROM golang:alpine -ENV GO111MODULE=on -ENV GOPROXY=https://goproxy.io,direct WORKDIR /go/src/gin-vue-admin COPY . . -RUN go env && go build -o server . +RUN go generate && go env && go build -o server . FROM alpine:latest LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com" From 0b04c0b47167adc00d4d5fe4d0ee9e31cb08caa4 Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Sat, 3 Jul 2021 08:08:39 +0800 Subject: [PATCH 6/9] update: README.md and README-en.md --- README-en.md | 281 ++++++++++++++++++----------------------------- README.md | 302 +++++++++++++++++++-------------------------------- 2 files changed, 216 insertions(+), 367 deletions(-) diff --git a/README-en.md b/README-en.md index fdc1bd81..7a107c0e 100644 --- a/README-en.md +++ b/README-en.md @@ -3,36 +3,43 @@
- - + + - +
English | [简体中文](./README.md) +[gitee](https://gitee.com/pixelmax/gin-vue-admin): https://gitee.com/pixelmax/gin-vue-admin + +[github](https://github.com/flipped-aurora/gin-vue-admin): https://github.com/flipped-aurora/gin-vue-admin + +[Vue3 version branch address](https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop): https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop + +[Approval flow branch](https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow): https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow + # Project Guidelines [Online Documentation](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/ - +[From the environment to the deployment of teaching videos](https://www.bilibili.com/video/BV1fV411y7dT) [Development Steps](https://www.gin-vue-admin.com/docs/help) (Contributor: LLemonGreen And Fann) -- Web UI Framework:[element-ui](https://github.com/ElemeFE/element) -- Server Framework:[gin](https://github.com/gin-gonic/gin) ## 1. Basic Introduction ### 1.1 Project Introduction -[Online Demo](http://demo.gin-vue-admin.com/) +> Gin-vue-admin is a backstage management system based on [vue](https://vuejs.org) and [gin](https://gin-gonic.com), which separates the front and rear of the full stack. It integrates jwt authentication, dynamic routing, dynamic menu, casbin authentication, form generator, code generator and other functions. It provides a variety of sample files, allowing you to focus more time on business development. + +[Online Demo](http://demo.gin-vue-admin.com): http://demo.gin-vue-admin.com username:admin password:123456 -> Gin-vue-admin is a full-stack (frontend and backend separation) framework designed for management system. -> It integrates multiple functions, such as JWT authentication, dynamic routing, dynamic menu, casbin authentication, form generator, code generator, etc. So that you can focus more time on your business Requirements. +### 1.2 Contributing Guide Hi! Thank you for choosing gin-vue-admin. @@ -40,7 +47,6 @@ Gin-vue-admin is a full-stack (frontend and backend separation) framework for de We are excited that you are interested in contributing to gin-vue-admin. Before submitting your contribution though, please make sure to take a moment and read through the following guidelines. -### 1.2 Contributing Guide #### 1.2.1 Issue Guidelines - Issues are exclusively for bug reports, feature requests and design-related topics. Other questions may be closed directly. If any questions come up when you are using Element, please hit [Gitter](https://gitter.im/element-en/Lobby) for help. @@ -72,81 +78,34 @@ We are excited that you are interested in contributing to gin-vue-admin. Before - node version > v8.6.0 - golang version >= v1.14 - IDE recommendation: Goland -- We recommend you to apply for your own cloud service in QINIU. Replace the public key, private key, warehouse name and default url address with your own, so as not to mess up the test database. +- initialization project: different versions of the database are not initialized. See synonyms at initialization https://www.gin-vue-admin.com/docs/first +- Replace the Qiniuyun public key, private key, warehouse name and default url address in the project to avoid data confusion in the test file. ``` -> Use docker-compose to experience this project -- Installation docker-compose [Official document](https://docs.docker.com/compose/install/) - - ```shell script - # Install on Linux - # 1.1 Run this command to download the current stable version of Docker Compose - sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - # 1.2 Apply executable permissions to binary files - sudo chmod +x /usr/local/bin/docker-compose - ``` - - ```shell script - # Use Python's pip installation - pip3 install docker-compose -i https://pypi.tuna.tsinghua.edu.cn/simple - ``` - - Use Docker Desktop - - Windows: https://hub.docker.com/editions/community/docker-ce-desktop-windows - - Mac: https://hub.docker.com/editions/community/docker-ce-desktop-mac/ - -- Use git to clone this project - - ```git - git clone https://github.com/flipped-aurora/gin-vue-admin.git - ``` - -- Use docker-compose up to start the startup project with one click - - ```shell script - # Use docker-compose to start four containers - docker-compose up - # If you modify some configuration options, you can use this command to repackage the image - docker-compose up --build - # Use docker-compose to start in the background - docker-compose up -d - ``` - - - Web project preview [http://127.0.0.1:8000](http://127.0.0.1:8000) - - - swagger APIs [http://127.0.0.1:8888/swagger/index.html](http://127.0.0.1:8888/swagger/index.html) - -- If the internal ip of the server's 177.7.0.12 container is occupied, the place to be modified is - - - Replace 177.7.0.12 on line 39 of [docker-compose.yaml](./docker-compose.yaml) with the ip you want - - Replace 177.7.0.12 in line 20 of [.docker-compose/nginx/conf.d/my.conf](./.docker-compose/nginx/conf.d/my.conf) with the ip you want - -- docker-compose uses a custom docker network - - - ```dockerfile - networks: - network: - ipam: - driver: default - config: - - subnet: '177.7.0.0/16' - ``` - - - Subnet address, the default gateway is 177.7.0.1 (docker-compose V2 needs to write, V3 does not need),For specific information, see the [official document](https://docs.docker.com/compose/compose-file/#ipv4_address-ipv6_address) - - - The default network name is gin-vue-admin_network, and the default is bridge mode - - - If the subnet is modified, the ipv4_address of each service needs to be modified, and the ip of the server on line 20 of [.docker-compose/nginx/conf.d/my.conf](.docker-compose/nginx/conf.d/my.conf) also needs to be modified - -> **Use docker-compose to deploy this project need attention** - -- For mysql database, please use a local database installed on the server disk. - - Avoid using mysql in the docker container, there may be write problems, io is lower than the host machine, docker's persistence mechanism problem -- [init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql) is for docker-compose ==experience this project==, prohibit the use of [init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql) to initialize project data, Database initialization[Please use this method](https://www.gin-vue-admin.com/docs/help#step1%EF%BC%9A%E6%95%B0%E6%8D%AE%E5%BA%93%E5%88%9D%E5%A7%8B%E5%8C%96) - - Use [init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql) to initialize all problems, please bear it yourself, and have nothing to do with this project -- When deploying using docker-compose of this project,Please modify the [nginx configuration](.docker-compose/nginx/conf.d/my.conf), mysql configuration, networks configuration, redis configuration corresponding to [docker-compose.yaml](./docker-compose.yaml), and make changes as needed. - -### 2.1 Web +### 2.1 server project + +use `Goland` And other editing tools,open server catalogue,You can't open it. `gin-vue-admin` root directory ```bash # clone the project -git clone https://github.com/piexlmax/gin-vue-admin.git +git clone https://github.com/flipped-aurora/gin-vue-admin.git +# open server catalogue +cd server + +# use go mod And install the go dependency package +go generate + +# Compile +go build -o server main.go (windows the compile command is go build -o server.exe main.go ) + +# Run binary +./server (windows The run command is server.exe) +``` + +### 2.1 web project + +```bash # enter the project directory cd web @@ -169,47 +128,6 @@ go list (go mod tidy) go build ``` -> Zap log library usage guide && configuration guide - -The configuration of the Zap log library selects zap under [config.yaml](./server/config.yaml) - -```yaml -# zap logger configuration -zap: - level: 'debug' - format: 'console' - prefix: '[GIN-VUE-ADMIN]' - director: 'log' - link_name: 'latest_log' - show_line: true - encode_level: 'LowercaseColorLevelEncoder' - stacktrace_key: 'stacktrace' - log_in_console: true -``` - -| Configuration Name | Type Of Configuration | Description | -| ------------------ | --------------------- | ------------------------------------------------------------ | -| level | string | For a detailed description of the level mode, please see the official [zap documentation](https://pkg.go.dev/go.uber.org/zap?tab=doc#pkg-constants)
info: info mode, stack information without errors, only output information
debug: debug mode, stack details with errors
warn:warn mode
error: error mode, stack details with error
dpanic: dpanic mode
panic: panic mode
fatal: fatal mode
| -| format | string | console: Output log in console format
json: json format output log | -| prefix | string | Log prefix | -| director | string | The folder to store the log can be modified, no need to create it manually | -| link_name | string | [A soft connection file](https://baike.baidu.com/item/%E8%BD%AF%E9%93%BE%E6%8E%A5) of link_name will be generated in the server directory, and the link is the latest log file of the director configuration item | -| show_line | bool | Display the line number, the default is true, it is not recommended to modify | -| encode_level | string | LowercaseLevelEncoder: lowercase
LowercaseColorLevelEncoder: lowercase with color
CapitalLevelEncoder: uppercase
CapitalColorLevelEncoder: uppercase with color | -| stacktrace_key | string | The name of the stack, that is, the key of josn when outputting the log in json format | -| log_in_console | bool | Whether to output to the console, the default is true | - -- Development environment || Debug environment configuration recommendations - - `level:debug` - - `format:console` - - `encode_level:LowercaseColorLevelEncoder`或者`encode_leve:CapitalColorLevelEncoder` -- Deployment environment configuration recommendations - - `level:error` - - `format:json` - - `encode_level: LowercaseLevelEncoder `或者 `encode_level:CapitalLevelEncoder` - - `log_in_console: false` -- Suggestions are only suggestions, you can proceed according to your own needs, and suggestions are for reference only - ### 2.3 API docs auto-generation using swagger #### 2.3.1 install swagger @@ -221,19 +139,20 @@ go get -u github.com/swaggo/swag/cmd/swag ##### (2) In mainland China -In mainland China, access to go.org/x is prohibited,we recommend [goproxy.io](https://goproxy.io/zh/) +In mainland China, access to go.org/x is prohibited,we recommend [goproxy.io](https://goproxy.io/zh/) or [goproxy.cn](https://goproxy.cn) ````bash -If you are using Go version 1.13 and above (recommended) -# Enable Go Modules function +# If you are using a version of Go 1.13 - 1.15 Need to set up manually GO111MODULE=on, The opening mode is as follows, If your Go version is 1.16 ~ Latest edition You can ignore the following step one +# Step one、Enable Go Modules Function go env -w GO111MODULE=on -# Configure GOPROXY environment variables -go env -w GOPROXY=https://goproxy.io,direct -If you are using Go version 1.12 and below -go env -w GO111MODULE=on -go env -w GOPROXY=https://goproxy.io +# Step two、Configuration GOPROXY Environment variable +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct -# Use the following command to download swag +# If you dislike trouble,You can use the go generate Automatically execute code before compilation, But this can't be used command line terminal of `Goland` or `Vscode` +cd server +go generate -run "go env -w .*?" + +# 使用如下命令下载swag go get -u github.com/swaggo/swag/cmd/swag ```` @@ -243,18 +162,19 @@ go get -u github.com/swaggo/swag/cmd/swag cd server swag init ```` -After executing the above command,`docs` will show in `server/`,then open your browser, jump into `http://localhost:8888/swagger/index.html` to see the swagger APIs. + +> After executing the above command,server directory will appear in the docs folder `docs.go`, `swagger.json`, `swagger.yaml` Three file updates,After starting the go service, type in the browser [http://localhost:8888/swagger/index.html](http://localhost:8888/swagger/index.html) You can view swagger document ## 3. 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). -- DB: `MySql`(5.6.44),using `gorm` to implement data manipulation, added support for SQLite databases. +- Frontend: using [Element](https://github.com/ElemeFE/element) based on [Vue](https://vuejs.org),to code the page. +- Backend: using [Gin](https://gin-gonic.com/) to quickly build basic RESTful API. [Gin](https://gin-gonic.com/)is a web framework written in Go (Golang). +- DB: `MySql`(5.6.44),using [gorm](http://gorm.io)` to implement data manipulation, added support for SQLite databases. - 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 to auto generate APIs docs。 -- Config: using `fsnotify` and `viper` to implement `yaml` config file。 -- Log: using `go-logging` record logs。 +- Config: using [fsnotify](https://github.com/fsnotify/fsnotify) and [viper](https://github.com/spf13/viper) to implement `yaml` config file。 +- Log: using [zap](https://github.com/uber-go/zap) record logs。 ## 4. Project Architecture @@ -269,19 +189,31 @@ After executing the above command,`docs` will show in `server/`,then open yo ### 4.3 Project Layout ``` - ├─server (backend) - │ ├─api (API entrance) - │ ├─config (config file) - │ ├─core (core code) - │ ├─docs (swagger APIs docs) - │ ├─global (global objet) - │ ├─initialiaze (initialiazation) - │ ├─middleware (middle ware) - │ ├─model (model and services) - │ ├─resource (resources, such as static pages, templates) - │ ├─router (routers) - │ ├─service (services) - │ └─utils (common utilities) + ├── server + ├── api (api entrance) + │ └── v1 (v1 version interface) + ├── config (configuration package) + ├── core (core document) + ├── docs (swagger document directory) + ├── global (global object) + ├── initialize (initialization) + │ └── internal (initialize internal function) + ├── middleware (middleware layer) + ├── model (model layer) + │ ├── request (input parameter structure) + │ └── response (out-of-parameter structure) + ├── packfile (static file packaging) + ├── resource (static resource folder) + │ ├── excel (excel import and export default path) + │ ├── page (form generator) + │ └── template (template) + ├── router (routing layer) + ├── service (service layer) + ├── source (source layer) + └── utils (tool kit) + ├── timer (timer interface encapsulation) + └── upload (oss interface encapsulation) + └─web (frontend) ├─public (deploy templates) └─src (source code) @@ -299,58 +231,59 @@ After executing the above command,`docs` will show in `server/`,then open yo ## 5. Features - Authority management: Authority management based on `jwt` and `casbin`. -- File upload & download: File upload operation based on Qiniu Cloud (In order to make it easier for everyone to test, I have provided various important tokens of my Qiniu test number, and I urge you not to make things a mess). -- Pagination Encapsulation:The frontend uses mixins to encapsulate paging, and the paging method can call mixins +- File upload and download: implement file upload operations based on `Qiniuyun', `Aliyun 'and `Tencent Cloud` (please develop your own application for each platform corresponding to `token` or `key` ). +- Pagination Encapsulation:The frontend uses `mixins` to encapsulate paging, and the paging method can call `mixins` . - 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 and menu 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. -- Configuration management: The configuration file can be modified in the web page (the test environment does not provide this function). -- Rich text editor: Embed MarkDown editor function. +- Configuration management: the configuration file can be modified in the foreground (this feature is not available in the online experience site). - Conditional search: Add an example of conditional search. - Restful example: You can see sample APIs in user management module. - -``` -fontend code file: src\view\superAdmin\api\api.vue -backend code file: model\dnModel\api.go -``` -- Multi-login restriction: Change `userMultipoint` to true in `system` in `config.yaml` (You need to configure redis and redis parameters yourself. During the test period, please report in time if there is a bug). + - Front-end file reference: [web/src/view/superAdmin/api/api.vue](https://github.com/flipped-aurora/gin-vue-admin/blob/master/web/src/view/superAdmin/api/api.vue). + - Stage reference: [server/router/sys_api.go](https://github.com/flipped-aurora/gin-vue-admin/blob/master/server/router/sys_api.go). +- Multi-login restriction: Change `user-multipoint` to true in `system` in `config.yaml` (You need to configure redis and redis parameters yourself. During the test period, please report in time if there is a bug). - Upload file by chunk:Provides examples of file upload and large file upload by chunk. - Form Builder:With the help of [@form-generator](https://github.com/JakHuang/form-generator). - Code generator: Providing backend with basic logic and simple curd code generator. -## 6. To-do list - -- [ ] upload & export Excel -- [ ] e-chart -- [ ] workflow, task transfer function -- [ ] frontend independent mode, mock +## 6. Knowledge base -## 7. Knowledge base - -### 7.1 Team blog +### 6.1 Team blog > https://www.yuque.com/flipped-aurora > >There are video courses about frontend framework in our blo. If you think the project is helpful to you, you can add my personal WeChat:shouzi_1994,your comments is welcomed。 -### 7.2 Video courses +### 6.2 Video courses (1) Development environment course + > Bilibili:https://www.bilibili.com/video/BV1Fg4y187Bw/ (2) Template course + > Bilibili:https://www.bilibili.com/video/BV16K4y1r7BD/ -(3)2.0 version introduction and development experience +(3) 2.0 version introduction and development experience + > Bilibili:https://www.bilibili.com/video/BV1aV411d7Gm#reply2831798461 -(4) Golang basic course (coming soon) +(4) Golang basic course > https://space.bilibili.com/322210472/channel/detail?cid=108884 -## 8. Contacts -### 8.1 Groups +(5) gin frame basic teaching + +> bilibili:https://space.bilibili.com/322210472/channel/detail?cid=126418&ctype=0 + +(6) gin-vue-admin version update introduction video +> bilibili:https://space.bilibili.com/322210472/channel/detail?cid=126418&ctype=0 + +## 7.Contacts + +### 7.1 Groups + #### QQ group: 622360840 | QQ group |d @@ -366,11 +299,11 @@ backend code file: model\dnModel\api.go #### [About Us](https://www.gin-vue-admin.com/about/) -## 9. Donate +## 8. Donate If you find this project useful, you can buy author a glass of juice :tropical_drink: [here](https://www.gin-vue-admin.com/docs/coffee) -## 10. Commercial considerations +## 9. Commercial considerations If you use this project for commercial purposes, please comply with the Apache2.0 agreement and retain the author's technical support statement. diff --git a/README.md b/README.md index 32213fc0..23bb7cff 100644 --- a/README.md +++ b/README.md @@ -3,44 +3,42 @@
- - + + - +
[English](./README-en.md) | 简体中文 -[gitee地址:https://gitee.com/pixelmax/gin-vue-admin](https://gitee.com/pixelmax/gin-vue-admin) +[gitee地址](https://gitee.com/pixelmax/gin-vue-admin): https://gitee.com/pixelmax/gin-vue-admin -[github地址:https://github.com/flipped-aurora/gin-vue-admin](https://github.com/flipped-aurora/gin-vue-admin) +[github地址](https://github.com/flipped-aurora/gin-vue-admin): https://github.com/flipped-aurora/gin-vue-admin -[vue3版本分支地址:https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop](https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop) +[vue3版本分支地址](https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop): https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop -[审批流分支:https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow](https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow) +[审批流分支](https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow): https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow # 项目文档 -[在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/ +[在线文档](https://www.gin-vue-admin.com) : https://www.gin-vue-admin.com [从环境到部署教学视频](https://www.bilibili.com/video/BV1fV411y7dT) [开发教学](https://www.gin-vue-admin.com/docs/help) (贡献者: LLemonGreen And Fann) -- 前端UI框架:[element-ui](https://github.com/ElemeFE/element) -- 后台框架:[gin](https://github.com/gin-gonic/gin) ## 1. 基本介绍 ### 1.1 项目介绍 -[在线预览](http://demo.gin-vue-admin.com/) +> Gin-vue-admin是一个基于 [vue](https://vuejs.org) 和 [gin](https://gin-gonic.com) 开发的全栈前后端分离的后台管理系统,集成jwt鉴权,动态路由,动态菜单,casbin鉴权,表单生成器,代码生成器等功能,提供多种示例文件,让您把更多时间专注在业务开发上。 + +[在线预览](http://demo.gin-vue-admin.com): http://demo.gin-vue-admin.com 测试用户名:admin 测试密码:123456 -> Gin-vue-admin是一个基于vue和gin开发的全栈前后端分离的后台管理系统,集成jwt鉴权,动态路由,动态菜单,casbin鉴权,表单生成器,代码生成器等功能,提供多种示例文件,让您把更多时间专注在业务开发上。 - ### 1.2 贡献指南 Hi! 首先感谢你使用 gin-vue-admin。 @@ -77,167 +75,68 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm - node版本 > v8.6.0 - golang版本 >= v1.14 - IDE推荐:Goland -- 初始化项目: 不同版本数据库初始化不通 参见https://www.gin-vue-admin.com/docs/server#1-%E5%88%9D%E5%A7%8B%E5%8C%96server%E9%A1%B9%E7%9B%AE +- 初始化项目: 不同版本数据库初始化不通 参见 https://www.gin-vue-admin.com/docs/first - 替换掉项目中的七牛云公钥,私钥,仓名和默认url地址,以免发生测试文件数据错乱 ``` -> 使用docker-compose体验本项目 -- 安装 docker-compose [官方文档](https://docs.docker.com/compose/install/) - - ```shell script - # 在Linux安装 - # 1.1 运行此命令以下载Docker Compose的当前稳定版本 - sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - # 1.2 将可执行权限应用于二进制文件 - sudo chmod +x /usr/local/bin/docker-compose - ``` - - ```shell script - # 使用Python的pip安装 - pip3 install docker-compose -i https://pypi.tuna.tsinghua.edu.cn/simple - ``` - - 使用 Docker Desktop - - Windows: https://hub.docker.com/editions/community/docker-ce-desktop-windows - - Mac: https://hub.docker.com/editions/community/docker-ce-desktop-mac/ - -- 使用git克隆本项目 - - ```git - git clone https://github.com/flipped-aurora/gin-vue-admin.git - ``` - -- 使用docker-compose up一键启动启动项目 - - ```shell script - # 使用docker-compose启动四个容器 - docker-compose up - # 如果您修改了某些配置选项,可以使用此命令重新打包镜像 - docker-compose up --build - # 使用docker-compose 后台启动 - docker-compose up -d - ``` - - - web项目预览 [http://127.0.0.1:8000](http://127.0.0.1:8000) - - - swagger文档 [http://127.0.0.1:8888/swagger/index.html](http://127.0.0.1:8888/swagger/index.html) - -- 如果server的177.7.0.12这个容器内部ip被占用了,需要修改地方为 +### 2.1 server项目 - - [docker-compose.yaml](./docker-compose.yaml)的第39行的177.7.0.12更换为你想要的ip - - [.docker-compose/nginx/conf.d/my.conf](./.docker-compose/nginx/conf.d/my.conf)的第20行的177.7.0.12更换为你想要的ip +使用 `Goland` 等编辑工具,打开server目录,不可以打开 gin-vue-admin 根目录 -- docker-compose使用自定义的一个docker网络 - - - ```dockerfile - networks: - network: - ipam: - driver: default - config: - - subnet: '177.7.0.0/16' - ``` - - - 子网地址, 默认网关是177.7.0.1(docker-compose V2需要写,V3则不需要),具体信息看[官方文档](https://docs.docker.com/compose/compose-file/#ipv4_address-ipv6_address) +```bash - - 默认的network名为gin-vue-admin_network,默认是bridge模式 +# 克隆项目 +git clone https://github.com/flipped-aurora/gin-vue-admin.git +# 进入server文件夹 +cd server - - 如果修改了子网,对应的每个service的ipv4_address都需要修改,还有[.docker-compose/nginx/conf.d/my.conf](./.docker-compose/nginx/conf.d/my.conf)的第20行的server的ip也需要修改 +# 使用 go mod 并安装go依赖包 +go generate -> **使用docker-compose进行部署本项目需注意的问题** +# 编译 +go build -o server main.go (windows编译命令为go build -o server.exe main.go ) -- dockerfile_server使用了多阶段构建,这是docker 17.05后引入的,因此安装的docker版本需要高于17.05 -- mysql数据库请使用装在服务器磁盘的本地数据库. - - 避免使用docker容器内的mysql,可能会出现写入的问题, io比宿主机低 docker的持久化机制问题 -- [init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql)是给docker-compose进行体验本项目的, 禁止[init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql)使用进行项目数据的初始化, 数据库初始化[请使用此方法](https://www.gin-vue-admin.com/docs/help#step1%EF%BC%9A%E6%95%B0%E6%8D%AE%E5%BA%93%E5%88%9D%E5%A7%8B%E5%8C%96) - - 使用[init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql)进行初始化出现的所有问题,请自行承担,与本项目无关 -- 使用本项目的docker-compose进行部署时,请修改[docker-compose.yaml](./docker-compose.yaml)对应的[nginx配置](.docker-compose/nginx/conf.d/my.conf),mysql配置,networks配置,redis配置,按需自行更改. +# 运行二进制 +./server (windows运行命令为 server.exe) +``` -### 2.1 web端 +### 2.2 web项目 ```bash -# clone the project -git clone https://github.com/piexlmax/gin-vue-admin.git - -# enter the project directory +# 进入web文件夹 cd web -# install dependency -npm install +# 安装依赖 +cnpm install || npm install -# develop +# 启动web项目 npm run serve ``` -### 2.2 server端 - -使用 goland等编辑工具,打开server目录,不可以打开 gin-vue-admin 根目录 - -```bash -# 使用 go.mod - -# 安装go依赖包 -go list (go mod tidy) - -# 编译 -go build -``` - -> Zap日志库使用指南&&配置指南 - -Zap日志库的配置选择在[config.yaml](./server/config.yaml)下的zap - -```yaml -# zap logger configuration -zap: - level: 'debug' - format: 'console' - prefix: '[GIN-VUE-ADMIN]' - director: 'log' - link_name: 'latest_log' - show_line: true - encode_level: 'LowercaseColorLevelEncoder' - stacktrace_key: 'stacktrace' - log_in_console: true -``` - -| 配置名 | 配置的类型 | 说明 | -| -------------- | ---------- | ------------------------------------------------------------ | -| level | string | level的模式的详细说明,请看[zap官方文档](https://pkg.go.dev/go.uber.org/zap?tab=doc#pkg-constants)
info: info模式,无错误的堆栈信息,只输出信息
debug:debug模式,有错误的堆栈详细信息
warn:warn模式
error: error模式,有错误的堆栈详细信息
dpanic: dpanic模式
panic: panic模式
fatal: fatal模式
| -| format | string | console: 控制台形式输出日志
json: json格式输出日志 | -| prefix | string | 日志的前缀 | -| director | string | 存放日志的文件夹,修改即可,不需要手动创建 | -| link_name | string | 在server目录下会生成一个link_name的[软连接文件](https://baike.baidu.com/item/%E8%BD%AF%E9%93%BE%E6%8E%A5),链接的是director配置项的最新日志文件 | -| show_line | bool | 显示行号, 默认为true,不建议修改 | -| encode_level | string | LowercaseLevelEncoder:小写
LowercaseColorLevelEncoder:小写带颜色
CapitalLevelEncoder: 大写
CapitalColorLevelEncoder: 大写带颜色 | -| stacktrace_key | string | 堆栈的名称,即在json格式输出日志时的josn的key | -| log_in_console | bool | 是否输出到控制台,默认为true | - -- 开发环境 || 调试环境配置建议 - - `level:debug` - - `format:console` - - `encode_level:LowercaseColorLevelEncoder`或者`encode_leve:CapitalColorLevelEncoder` -- 部署环境配置建议 - - `level:error` - - `format:json` - - `encode_level: LowercaseLevelEncoder `或者 `encode_level:CapitalLevelEncoder` - - `log_in_console: false` -- 建议只是建议,按照自己的需求进行即可,给出建议仅供参考 - ### 2.3 swagger自动化API文档 #### 2.3.1 安装 swagger ##### (1)可以访问外国网站 + ```` go get -u github.com/swaggo/swag/cmd/swag ```` ##### (2)无法访问外国网站 -由于国内没法安装 go.org/x 包下面的东西,推荐使用 [goproxy.io](https://goproxy.io/zh/) +由于国内没法安装 go.org/x 包下面的东西,推荐使用 [goproxy.cn](https://goproxy.cn) 或者 [goproxy.io](https://goproxy.io/zh/) ```bash -如果您使用的 Go 版本是 1.13 及以上(推荐) -# 启用 Go Modules 功能 +# 如果您使用的 Go 版本是 1.13 - 1.15 需要手动设置GO111MODULE=on, 开启方式如下命令, 如果你的 Go 版本 是 1.16 ~ 最新版 可以忽略以下步骤一 +# 步骤一、启用 Go Modules 功能 go env -w GO111MODULE=on -# 配置 GOPROXY 环境变量 -go env -w GOPROXY=https://goproxy.io,direct +# 步骤二、配置 GOPROXY 环境变量 +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct + +# 如果嫌弃麻烦,可以使用go generate 编译前自动执行代码, 不过这个不能使用 `Goland` 或者 `Vscode` 的 命令行终端 +cd server +go generate -run "go env -w .*?" # 使用如下命令下载swag go get -u github.com/swaggo/swag/cmd/swag @@ -245,25 +144,26 @@ go get -u github.com/swaggo/swag/cmd/swag #### 2.3.2 生成API文档 -```` +```` shell cd server swag init ```` -执行上面的命令后,server目录下会出现docs文件夹,登录 http://localhost:8888/swagger/index.html ,即可查看swagger文档 + +> 执行上面的命令后,server目录下会出现docs文件夹里的 `docs.go`, `swagger.json`, `swagger.yaml` 三个文件更新,启动go服务之后, 在浏览器输入 [http://localhost:8888/swagger/index.html](http://localhost:8888/swagger/index.html) 即可查看swagger文档 ## 3. 技术选型 -- 前端:用基于`vue`的`Element-UI`构建基础页面。 -- 后端:用`Gin`快速搭建基础restful风格API,`Gin`是一个go语言编写的Web框架。 -- 数据库:采用`MySql`(5.6.44)版本,使用`gorm`实现对数据库的基本操作,已添加对sqlite数据库的支持。 +- 前端:用基于 [Vue](https://vuejs.org) 的 [Element](https://github.com/ElemeFE/element) 构建基础页面。 +- 后端:用 [Gin](https://gin-gonic.com/) 快速搭建基础restful风格API,[Gin](https://gin-gonic.com/) 是一个go语言编写的Web框架。 +- 数据库:采用`MySql`(5.6.44)版本,使用 [gorm](http://gorm.cn) 实现对数据库的基本操作。 - 缓存:使用`Redis`实现记录当前活跃用户的`jwt`令牌并实现多点登录限制。 - API文档:使用`Swagger`构建自动化文档。 -- 配置文件:使用`fsnotify`和`viper`实现`yaml`格式的配置文件。 -- 日志:使用`go-logging`实现日志记录。 - +- 配置文件:使用 [fsnotify](https://github.com/fsnotify/fsnotify) 和 [viper](https://github.com/spf13/viper) 实现`yaml`格式的配置文件。 +- 日志:使用 [zap](https://github.com/uber-go/zap) 实现日志记录。 ## 4. 项目架构 + ### 4.1 系统架构图 ![系统架构图](http://qmplusimg.henrongyi.top/gva/gin-vue-admin.png) @@ -275,19 +175,31 @@ swag init ### 4.3 目录结构 ``` - ├─server (后端文件夹) - │ ├─api (API) - │ ├─config (配置包) - │ ├─core (內核) - │ ├─docs (swagger文档目录) - │ ├─global (全局对象) - │ ├─initialiaze (初始化) - │ ├─middleware (中间件) - │ ├─model (结构体层) - │ ├─resource (资源) - │ ├─router (路由) - │ ├─service (服务) - │ └─utils (公共功能) + ├── server + ├── api (api层) + │ └── v1 (v1版本接口) + ├── config (配置包) + ├── core (核心文件) + ├── docs (swagger文档目录) + ├── global (全局对象) + ├── initialize (初始化) + │ └── internal (初始化内部函数) + ├── middleware (中间件层) + ├── model (模型层) + │ ├── request (入参结构体) + │ └── response (出参结构体) + ├── packfile (静态文件打包) + ├── resource (静态资源文件夹) + │ ├── excel (excel导入导出默认路径) + │ ├── page (表单生成器) + │ └── template (模板) + ├── router (路由层) + ├── service (service层) + ├── source (source层) + └── utils (工具包) + ├── timer (定时器接口封装) + └── upload (oss接口封装) + └─web (前端文件) ├─public (发布模板) └─src (源码包) @@ -304,56 +216,60 @@ swag init ## 5. 主要功能 -- 权限管理:基于`jwt`和`casbin`实现的权限管理 -- 文件上传下载:实现基于七牛云的文件上传操作(为了方便大家测试,我公开了自己的七牛测试号的各种重要token,恳请大家不要乱传东西) -- 分页封装:前端使用mixins封装分页,分页方法调用mixins即可 +- 权限管理:基于`jwt`和`casbin`实现的权限管理。 +- 文件上传下载:实现基于`七牛云`, `阿里云`, `腾讯云` 的文件上传操作(请开发自己去各个平台的申请对应 `token` 或者对应`key`)。 +- 分页封装:前端使用 `mixins` 封装分页,分页方法调用 `mixins` 即可。 - 用户管理:系统管理员分配用户角色和角色权限。 - 角色管理:创建权限控制的主要对象,可以给角色分配不同api权限和菜单权限。 - 菜单管理:实现用户动态菜单配置,实现不同角色不同菜单。 - api管理:不同用户可调用的api接口的权限不同。 -- 配置管理:配置文件可前台修改(测试环境不开放此功能)。 -- 富文本编辑器:MarkDown编辑器功能嵌入。 +- 配置管理:配置文件可前台修改(在线体验站点不开放此功能)。 - 条件搜索:增加条件搜索示例。 -- restful示例:可以参考用户管理模块中的示例API。 -``` -前端文件参考: src\view\superAdmin\api\api.vue -后台文件参考: model\dnModel\api.go -``` -- 多点登录限制:需要在`config.yaml`中把`system`中的`useMultipoint`修改为true(需要自行配置Redis和Config中的Redis参数,测试阶段,有bug请及时反馈)。 +- restful示例:可以参考用户管理模块中的示例API。 + - 前端文件参考: [web/src/view/superAdmin/api/api.vue](https://github.com/flipped-aurora/gin-vue-admin/blob/master/web/src/view/superAdmin/api/api.vue) + - 后台文件参考: [server/router/sys_api.go](https://github.com/flipped-aurora/gin-vue-admin/blob/master/server/router/sys_api.go) +- 多点登录限制:需要在`config.yaml`中把`system`中的`use-multipoint`修改为true(需要自行配置Redis和Config中的Redis参数,测试阶段,有bug请及时反馈)。 - 分片长传:提供文件分片上传和大文件分片上传功能示例。 -- 表单生成器:表单生成器借助 [@form-generator](https://github.com/JakHuang/form-generator)。 -- 代码生成器:后台基础逻辑以及简单curd的代码生成器。 - -## 6. 计划任务 +- 表单生成器:表单生成器借助 [@form-generator](https://github.com/JakHuang/form-generator) 。 +- 代码生成器:后台基础逻辑以及简单curd的代码生成器。 -- [ ] 导入,导出Excel -- [ ] Echart图表支持 -- [ ] 单独前端使用模式以及数据模拟 +## 6. 知识库 -## 7. 知识库 -## 7.1 团队博客 +## 6.1 团队博客 > https://www.yuque.com/flipped-aurora > >内有前端框架教学视频。如果觉得项目对您有所帮助可以添加我的个人微信:shouzi_1994,欢迎您提出宝贵的需求。 -## 7.2 教学视频 +## 6.2 教学视频 (1)环境搭建 -> Bilibili:https://www.bilibili.com/video/BV1Fg4y187Bw/ (v1.0版本视频,v2.0操作相同目录不同) + +> bilibili:https://www.bilibili.com/video/BV1Fg4y187Bw/ (v1.0版本视频,v2.0操作相同目录不同) (2)模板使用 -> Bilibili:https://www.bilibili.com/video/BV16K4y1r7BD/ (v1.0版本视频,v2.0操作相同目录不同) + +> bilibili:https://www.bilibili.com/video/BV16K4y1r7BD/ (v1.0版本视频,v2.0操作相同目录不同) (3)2.0目录以及开发体验 -> Bilibili:https://www.bilibili.com/video/BV1aV411d7Gm#reply2831798461 -(4)golang基础教学视频录制中... -> https://space.bilibili.com/322210472/channel/detail?cid=108884 +> bilibili:https://www.bilibili.com/video/BV1aV411d7Gm#reply2831798461 + +(4)golang基础教学视频 + +> bilibili:https://space.bilibili.com/322210472/channel/detail?cid=108884 + +(5)gin框架基础教学 + +> bilibili:https://space.bilibili.com/322210472/channel/detail?cid=126418&ctype=0 + +(6)gin-vue-admin 版本更新介绍视频 + +> bilibili:https://space.bilibili.com/322210472/channel/detail?cid=126418&ctype=0 -## 8. 联系方式 +## 7. 联系方式 -### 8.1 技术群 +### 7.1 技术群 ### QQ交流群:622360840 | QQ 群 | @@ -369,10 +285,10 @@ swag init ### [关于我们](https://www.gin-vue-admin.com/about/) -## 9. 捐赠 +## 8. 捐赠 如果你觉得这个项目对你有帮助,你可以请作者喝饮料 :tropical_drink: [点我](https://www.gin-vue-admin.com/docs/coffee) -## 10. 商用注意事项 +## 9. 商用注意事项 如果您将此项目用于商业用途,请遵守Apache2.0协议并保留作者技术支持声明。 From 7a3f0ca7543d0de426aaec336d0bd655f47a8702 Mon Sep 17 00:00:00 2001 From: SliverHorn <45428434+SliverHorn@users.noreply.github.com> Date: Sun, 4 Jul 2021 16:01:20 +0800 Subject: [PATCH 7/9] Update sys_api.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改文件 - server/model/sys_api.go 修复问题 - gorm tag 编写错误,使用分号进行分割,而不是写两个gorm tag --- server/model/sys_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/sys_api.go b/server/model/sys_api.go index 20d9b657..03fbeba0 100644 --- a/server/model/sys_api.go +++ b/server/model/sys_api.go @@ -9,5 +9,5 @@ type SysApi struct { Path string `json:"path" gorm:"comment:api路径"` // api路径 Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述 ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组 - Method string `json:"method" gorm:"default:POST" gorm:"comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE + Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE } From a71cfe1de481f969f19b53a038d4699240812e94 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Wed, 7 Jul 2021 19:32:05 +0800 Subject: [PATCH 8/9] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0singleFlight?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E6=8E=A7=E5=88=B6jwt=E9=A2=81=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/global/global.go | 7 +++++-- server/go.mod | 1 + server/middleware/jwt.go | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/global/global.go b/server/global/global.go index 43577a4c..829714b0 100644 --- a/server/global/global.go +++ b/server/global/global.go @@ -3,6 +3,8 @@ package global import ( "gin-vue-admin/utils/timer" + "golang.org/x/sync/singleflight" + "go.uber.org/zap" "gin-vue-admin/config" @@ -18,6 +20,7 @@ var ( GVA_CONFIG config.Server GVA_VP *viper.Viper //GVA_LOG *oplogging.Logger - GVA_LOG *zap.Logger - GVA_Timer timer.Timer = timer.NewTimerTask() + GVA_LOG *zap.Logger + GVA_Timer timer.Timer = timer.NewTimerTask() + GVA_Concurrency_Control = &singleflight.Group{} ) diff --git a/server/go.mod b/server/go.mod index 231eed65..cf15d2c8 100644 --- a/server/go.mod +++ b/server/go.mod @@ -51,6 +51,7 @@ require ( github.com/unrolled/secure v1.0.7 go.uber.org/zap v1.10.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect google.golang.org/protobuf v1.24.0 // indirect gopkg.in/ini.v1 v1.55.0 // indirect diff --git a/server/middleware/jwt.go b/server/middleware/jwt.go index 56343a3e..9ab94cd6 100644 --- a/server/middleware/jwt.go +++ b/server/middleware/jwt.go @@ -7,11 +7,12 @@ import ( "gin-vue-admin/model/request" "gin-vue-admin/model/response" "gin-vue-admin/service" + "strconv" + "time" + "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" "go.uber.org/zap" - "strconv" - "time" ) func JWTAuth() gin.HandlerFunc { @@ -48,7 +49,7 @@ func JWTAuth() gin.HandlerFunc { } if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime { claims.ExpiresAt = time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime - newToken, _ := j.CreateToken(*claims) + newToken, _ := j.CreateTokenByOldToken(token, *claims) newClaims, _ := j.ParseToken(newToken) c.Header("new-token", newToken) c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10)) @@ -91,6 +92,14 @@ func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) { return token.SignedString(j.SigningKey) } +// CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题 +func (j *JWT) CreateTokenByOldToken(oldToken string, claims request.CustomClaims) (string, error) { + v, err, _ := global.GVA_Concurrency_Control.Do("JWT:"+oldToken, func() (interface{}, error) { + return j.CreateToken(claims) + }) + return v.(string), err +} + // 解析 token func (j *JWT) ParseToken(tokenString string) (*request.CustomClaims, error) { token, err := jwt.ParseWithClaims(tokenString, &request.CustomClaims{}, func(token *jwt.Token) (i interface{}, e error) { From 5039e9bf5f680344a74775809bff6272960082e7 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Fri, 9 Jul 2021 16:01:10 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0sync=E5=BA=93=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/go.mod b/server/go.mod index cf15d2c8..6eb7497d 100644 --- a/server/go.mod +++ b/server/go.mod @@ -51,7 +51,7 @@ require ( github.com/unrolled/secure v1.0.7 go.uber.org/zap v1.10.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect google.golang.org/protobuf v1.24.0 // indirect gopkg.in/ini.v1 v1.55.0 // indirect