diff --git a/README.md b/README.md index 8bf043d..f7d3e29 100644 --- a/README.md +++ b/README.md @@ -16,25 +16,33 @@ GO + Gin + Gorm + jwt - config - application_config.go 配置文件解析配置 - common.go 全局变量 + - context_config.go 上下文预留配置 - datasource_config.go 数据源配置 - log_config.go 日志配置 - - dao - - user_dao.go user's sql - - entity - - user.go user's gorm struct - 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 + - user_dao.go user's sql + - entity + - user.go user's gorm struct + - service + - user_service.go user's service + - pkg 第三方依赖包目录 - - rest - - urls.go 路由配置(绑定路径和处理器之间的关系) - util - util.go 工具类 - application.yml 主配置文件 - application-dev.yml 环境配置文件 - main.go 应用入口 + - urls.go 路由配置(绑定路径和处理器之间的关系) # go.mod 依赖说明文件 ``` diff --git a/src/config/datasource_config.go b/src/config/datasource_config.go index e60c10c..33cd67f 100644 --- a/src/config/datasource_config.go +++ b/src/config/datasource_config.go @@ -7,7 +7,7 @@ import ( _ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/postgres" //_ "github.com/jinzhu/gorm/dialects/sqlite" - "lingye-gin/src/entity" + "lingye-gin/src/modules/system/entity" "strings" ) diff --git a/src/middleware/gin_router.go b/src/middleware/gin_router.go index 920f5d9..3fbe04a 100644 --- a/src/middleware/gin_router.go +++ b/src/middleware/gin_router.go @@ -3,8 +3,8 @@ package middleware import ( "fmt" "github.com/gin-gonic/gin" + "lingye-gin/src" "lingye-gin/src/config" - "lingye-gin/src/rest" "strings" ) @@ -19,11 +19,11 @@ func (v GinRouter) Init(r *gin.Engine) { // 一般路由映射关系 groupMap := make(map[string]*gin.RouterGroup) // api路由映射关系 - apiUrls := make([]rest.RequestApi, 0) + apiUrls := make([]main.RequestApi, 0) // api组名称 apiGroupName := "api" - for _, normalRa := range rest.Urls { + for _, normalRa := range main.Urls { // 判断是否在某一组下 if strings.Compare(normalRa.GroupName, "") == 0 { // 批量处理 @@ -68,7 +68,7 @@ func (v GinRouter) Init(r *gin.Engine) { config.Logger.Info("GinRouter Ok") } -func handle(request rest.RequestApi, engine *gin.Engine) bool { +func handle(request main.RequestApi, engine *gin.Engine) bool { // get if strings.Compare(request.Mode, "get") == 0 { engine.GET(request.RelativePath, request.HandleFunction) @@ -92,7 +92,7 @@ func handle(request rest.RequestApi, engine *gin.Engine) bool { return false } -func handleGroup(request rest.RequestApi, group *gin.RouterGroup) bool { +func handleGroup(request main.RequestApi, group *gin.RouterGroup) bool { // get if strings.Compare(request.Mode, "get") == 0 { group.GET(request.RelativePath, request.HandleFunction) diff --git a/src/middleware/jwt_engine.go b/src/middleware/jwt_engine.go index 88d8999..a43d5ad 100644 --- a/src/middleware/jwt_engine.go +++ b/src/middleware/jwt_engine.go @@ -4,7 +4,7 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" "lingye-gin/src/config" - "lingye-gin/src/entity" + "lingye-gin/src/modules/system/entity" "net/http" "strings" "time" diff --git a/src/dao/user_dao.go b/src/modules/system/dao/user_dao.go similarity index 94% rename from src/dao/user_dao.go rename to src/modules/system/dao/user_dao.go index 961ea35..78a8b81 100644 --- a/src/dao/user_dao.go +++ b/src/modules/system/dao/user_dao.go @@ -2,8 +2,8 @@ package dao import ( "lingye-gin/src/config" - "lingye-gin/src/entity" - "lingye-gin/src/service/query" + "lingye-gin/src/modules/system/entity" + "lingye-gin/src/modules/system/service/query" "lingye-gin/src/util" ) diff --git a/src/entity/user.go b/src/modules/system/entity/user.go similarity index 100% rename from src/entity/user.go rename to src/modules/system/entity/user.go diff --git a/src/rest/api/user_rest.go b/src/modules/system/rest/user_rest.go similarity index 92% rename from src/rest/api/user_rest.go rename to src/modules/system/rest/user_rest.go index e7b7ce6..d644b66 100644 --- a/src/rest/api/user_rest.go +++ b/src/modules/system/rest/user_rest.go @@ -1,10 +1,10 @@ -package api +package rest import ( "github.com/gin-gonic/gin" - "lingye-gin/src/service" - "lingye-gin/src/service/dto" - "lingye-gin/src/service/query" + "lingye-gin/src/modules/system/service" + "lingye-gin/src/modules/system/service/dto" + "lingye-gin/src/modules/system/service/query" "lingye-gin/src/util" "net/http" ) diff --git a/src/service/dto/user_dto.go b/src/modules/system/service/dto/user_dto.go similarity index 100% rename from src/service/dto/user_dto.go rename to src/modules/system/service/dto/user_dto.go diff --git a/src/service/query/user_query.go b/src/modules/system/service/query/user_query.go similarity index 100% rename from src/service/query/user_query.go rename to src/modules/system/service/query/user_query.go diff --git a/src/service/user_service.go b/src/modules/system/service/user_service.go similarity index 84% rename from src/service/user_service.go rename to src/modules/system/service/user_service.go index cf21fe2..78e4a0a 100644 --- a/src/service/user_service.go +++ b/src/modules/system/service/user_service.go @@ -1,10 +1,10 @@ package service import ( - "lingye-gin/src/dao" - "lingye-gin/src/entity" - "lingye-gin/src/service/dto" - "lingye-gin/src/service/query" + "lingye-gin/src/modules/system/dao" + "lingye-gin/src/modules/system/entity" + "lingye-gin/src/modules/system/service/dto" + "lingye-gin/src/modules/system/service/query" "lingye-gin/src/util" ) diff --git a/src/rest/sign_rest.go b/src/test/sign_rest.go similarity index 96% rename from src/rest/sign_rest.go rename to src/test/sign_rest.go index dfd7576..f62556f 100644 --- a/src/rest/sign_rest.go +++ b/src/test/sign_rest.go @@ -1,4 +1,4 @@ -package rest +package test import ( "github.com/gin-gonic/gin" diff --git a/src/rest/v1/student_rest.go b/src/test/v1/student_rest.go similarity index 100% rename from src/rest/v1/student_rest.go rename to src/test/v1/student_rest.go diff --git a/src/rest/v2/student_rest.go b/src/test/v2/student_rest.go similarity index 100% rename from src/rest/v2/student_rest.go rename to src/test/v2/student_rest.go diff --git a/src/rest/urls.go b/src/urls.go similarity index 78% rename from src/rest/urls.go rename to src/urls.go index b2a6a1c..0e4971e 100644 --- a/src/rest/urls.go +++ b/src/urls.go @@ -1,10 +1,11 @@ -package rest +package main import ( "github.com/gin-gonic/gin" - "lingye-gin/src/rest/api" - v1 "lingye-gin/src/rest/v1" - v2 "lingye-gin/src/rest/v2" + "lingye-gin/src/modules/system/rest" + "lingye-gin/src/test" + v1 "lingye-gin/src/test/v1" + v2 "lingye-gin/src/test/v2" "lingye-gin/src/util" ) @@ -24,9 +25,9 @@ type RequestApi struct { // 定义变长数组变量 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 // 获取所有学生 {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}, // api jwt // 获取所有用户 - {GroupName: "api", Mode: "get", RelativePath: "/users", HandleFunction: api.DescribeUsers}, + {GroupName: "api", Mode: "get", RelativePath: "/users", HandleFunction: rest.DescribeUsers}, // 根据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更新用户 - {GroupName: "api", Mode: "put", RelativePath: "/users/:id", HandleFunction: api.ModifyUserById}, + {GroupName: "api", Mode: "put", RelativePath: "/users/:id", HandleFunction: rest.ModifyUserById}, // 根据ID删除用户 - {GroupName: "api", Mode: "delete", RelativePath: "/users/:id", HandleFunction: api.DeleteUserById}, + {GroupName: "api", Mode: "delete", RelativePath: "/users/:id", HandleFunction: rest.DeleteUserById}, }