1、变更项目结构

2、新增说明文档
This commit is contained in:
TianJun 2021-04-29 12:45:56 +08:00
parent 8ec36e0028
commit f6fc4ea83c
14 changed files with 44 additions and 35 deletions

View File

@ -16,25 +16,33 @@ GO + Gin + Gorm + jwt
- config - config
- application_config.go 配置文件解析配置 - application_config.go 配置文件解析配置
- common.go 全局变量 - common.go 全局变量
- context_config.go 上下文预留配置
- datasource_config.go 数据源配置 - datasource_config.go 数据源配置
- log_config.go 日志配置 - log_config.go 日志配置
- middleware
- gin_engine.go gin配置
- gin_panic.go 全局异常捕捉, 统一返回
- gin_router.go 路由载入配置
- jwt_engine.go jwt配置
- redis_client.go redis配置
- modules
- system 系统模块
- rest
- user_rest.go user's controller
- dao - dao
- user_dao.go user's sql - user_dao.go user's sql
- entity - entity
- user.go user's gorm struct - user.go user's gorm struct
- middleware - service
- gin_engine.go gin配置 - user_service.go user's service
- gin_router.go 路由载入配置
- jwt_engine.go jwt配置
- redis_client.go redis配置
- pkg 第三方依赖包目录 - pkg 第三方依赖包目录
- rest
- urls.go 路由配置(绑定路径和处理器之间的关系)
- util - util
- util.go 工具类 - util.go 工具类
- application.yml 主配置文件 - application.yml 主配置文件
- application-dev.yml 环境配置文件 - application-dev.yml 环境配置文件
- main.go 应用入口 - main.go 应用入口
- urls.go 路由配置(绑定路径和处理器之间的关系)
# go.mod 依赖说明文件 # go.mod 依赖说明文件
``` ```

View File

@ -7,7 +7,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres" _ "github.com/jinzhu/gorm/dialects/postgres"
//_ "github.com/jinzhu/gorm/dialects/sqlite" //_ "github.com/jinzhu/gorm/dialects/sqlite"
"lingye-gin/src/entity" "lingye-gin/src/modules/system/entity"
"strings" "strings"
) )

View File

@ -3,8 +3,8 @@ package middleware
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"lingye-gin/src"
"lingye-gin/src/config" "lingye-gin/src/config"
"lingye-gin/src/rest"
"strings" "strings"
) )
@ -19,11 +19,11 @@ func (v GinRouter) Init(r *gin.Engine) {
// 一般路由映射关系 // 一般路由映射关系
groupMap := make(map[string]*gin.RouterGroup) groupMap := make(map[string]*gin.RouterGroup)
// api路由映射关系 // api路由映射关系
apiUrls := make([]rest.RequestApi, 0) apiUrls := make([]main.RequestApi, 0)
// api组名称 // api组名称
apiGroupName := "api" apiGroupName := "api"
for _, normalRa := range rest.Urls { for _, normalRa := range main.Urls {
// 判断是否在某一组下 // 判断是否在某一组下
if strings.Compare(normalRa.GroupName, "") == 0 { if strings.Compare(normalRa.GroupName, "") == 0 {
// 批量处理 // 批量处理
@ -68,7 +68,7 @@ func (v GinRouter) Init(r *gin.Engine) {
config.Logger.Info("GinRouter Ok") config.Logger.Info("GinRouter Ok")
} }
func handle(request rest.RequestApi, engine *gin.Engine) bool { func handle(request main.RequestApi, engine *gin.Engine) bool {
// get // get
if strings.Compare(request.Mode, "get") == 0 { if strings.Compare(request.Mode, "get") == 0 {
engine.GET(request.RelativePath, request.HandleFunction) engine.GET(request.RelativePath, request.HandleFunction)
@ -92,7 +92,7 @@ func handle(request rest.RequestApi, engine *gin.Engine) bool {
return false return false
} }
func handleGroup(request rest.RequestApi, group *gin.RouterGroup) bool { func handleGroup(request main.RequestApi, group *gin.RouterGroup) bool {
// get // get
if strings.Compare(request.Mode, "get") == 0 { if strings.Compare(request.Mode, "get") == 0 {
group.GET(request.RelativePath, request.HandleFunction) group.GET(request.RelativePath, request.HandleFunction)

View File

@ -4,7 +4,7 @@ import (
"github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"lingye-gin/src/config" "lingye-gin/src/config"
"lingye-gin/src/entity" "lingye-gin/src/modules/system/entity"
"net/http" "net/http"
"strings" "strings"
"time" "time"

View File

@ -2,8 +2,8 @@ package dao
import ( import (
"lingye-gin/src/config" "lingye-gin/src/config"
"lingye-gin/src/entity" "lingye-gin/src/modules/system/entity"
"lingye-gin/src/service/query" "lingye-gin/src/modules/system/service/query"
"lingye-gin/src/util" "lingye-gin/src/util"
) )

View File

@ -1,10 +1,10 @@
package api package rest
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"lingye-gin/src/service" "lingye-gin/src/modules/system/service"
"lingye-gin/src/service/dto" "lingye-gin/src/modules/system/service/dto"
"lingye-gin/src/service/query" "lingye-gin/src/modules/system/service/query"
"lingye-gin/src/util" "lingye-gin/src/util"
"net/http" "net/http"
) )

View File

@ -1,10 +1,10 @@
package service package service
import ( import (
"lingye-gin/src/dao" "lingye-gin/src/modules/system/dao"
"lingye-gin/src/entity" "lingye-gin/src/modules/system/entity"
"lingye-gin/src/service/dto" "lingye-gin/src/modules/system/service/dto"
"lingye-gin/src/service/query" "lingye-gin/src/modules/system/service/query"
"lingye-gin/src/util" "lingye-gin/src/util"
) )

View File

@ -1,4 +1,4 @@
package rest package test
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"

View File

@ -1,10 +1,11 @@
package rest package main
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"lingye-gin/src/rest/api" "lingye-gin/src/modules/system/rest"
v1 "lingye-gin/src/rest/v1" "lingye-gin/src/test"
v2 "lingye-gin/src/rest/v2" v1 "lingye-gin/src/test/v1"
v2 "lingye-gin/src/test/v2"
"lingye-gin/src/util" "lingye-gin/src/util"
) )
@ -24,9 +25,9 @@ type RequestApi struct {
// 定义变长数组变量 // 定义变长数组变量
var Urls = [...]RequestApi{ var Urls = [...]RequestApi{
// 定义请求方式和路径 // 定义请求方式和路径
{Mode: "get", RelativePath: "/sn", HandleFunction: DescribeSign}, {Mode: "get", RelativePath: "/sn", HandleFunction: test.DescribeSign},
// 获取所有用户 // 获取所有用户
{Mode: "get", RelativePath: "/users", HandleFunction: api.DescribeUsers}, {Mode: "get", RelativePath: "/users", HandleFunction: rest.DescribeUsers},
// v1 // v1
// 获取所有学生 // 获取所有学生
{GroupName: "v1", Mode: "get", RelativePath: "/students", HandleFunction: v1.DescribeStudents}, {GroupName: "v1", Mode: "get", RelativePath: "/students", HandleFunction: v1.DescribeStudents},
@ -42,13 +43,13 @@ var Urls = [...]RequestApi{
{GroupName: "v2", GroupHandleFunction: util.VerifySign, Mode: "get", RelativePath: "/students", HandleFunction: v2.DescribeStudents}, {GroupName: "v2", GroupHandleFunction: util.VerifySign, Mode: "get", RelativePath: "/students", HandleFunction: v2.DescribeStudents},
// api jwt // api jwt
// 获取所有用户 // 获取所有用户
{GroupName: "api", Mode: "get", RelativePath: "/users", HandleFunction: api.DescribeUsers}, {GroupName: "api", Mode: "get", RelativePath: "/users", HandleFunction: rest.DescribeUsers},
// 根据ID获取用户 // 根据ID获取用户
{GroupName: "api", Mode: "get", RelativePath: "/users/:id", HandleFunction: api.DescribeUserById}, {GroupName: "api", Mode: "get", RelativePath: "/users/:id", HandleFunction: rest.DescribeUserById},
// 保存用户 // 保存用户
{GroupName: "api", Mode: "post", RelativePath: "/users", HandleFunction: api.CreateUser}, {GroupName: "api", Mode: "post", RelativePath: "/users", HandleFunction: rest.CreateUser},
// 根据ID更新用户 // 根据ID更新用户
{GroupName: "api", Mode: "put", RelativePath: "/users/:id", HandleFunction: api.ModifyUserById}, {GroupName: "api", Mode: "put", RelativePath: "/users/:id", HandleFunction: rest.ModifyUserById},
// 根据ID删除用户 // 根据ID删除用户
{GroupName: "api", Mode: "delete", RelativePath: "/users/:id", HandleFunction: api.DeleteUserById}, {GroupName: "api", Mode: "delete", RelativePath: "/users/:id", HandleFunction: rest.DeleteUserById},
} }