parent
8ec36e0028
commit
f6fc4ea83c
22
README.md
22
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 日志配置
|
||||
- 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
|
||||
- middleware
|
||||
- gin_engine.go gin配置
|
||||
- gin_router.go 路由载入配置
|
||||
- jwt_engine.go jwt配置
|
||||
- redis_client.go redis配置
|
||||
- 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 依赖说明文件
|
||||
```
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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"
|
||||
)
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package rest
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
|
@ -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},
|
||||
}
|
Loading…
Reference in New Issue