mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
feature(1.2.8): 使用 embed 打包静态资源
- go version 升级为 1.16 - 使用 embed 特性,将静态资源打包进二进制文件 - 优化代码
This commit is contained in:
@@ -3,10 +3,10 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ func (h *handler) Create() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createData := new(admin_service.CreateAdminData)
|
||||
createData := new(admin2.CreateAdminData)
|
||||
createData.Nickname = req.Nickname
|
||||
createData.Username = req.Username
|
||||
createData.Mobile = req.Mobile
|
||||
|
||||
@@ -3,9 +3,9 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ func (h *handler) CreateAdminMenu() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createData := new(admin_service.CreateMenuData)
|
||||
createData := new(admin2.CreateMenuData)
|
||||
createData.AdminId = int32(ids[0])
|
||||
createData.Actions = req.Actions
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -5,21 +5,21 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type detailResponse struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Menu []admin_service.ListMyMenuData `json:"menu"` // 菜单栏
|
||||
Username string `json:"username"` // 用户名
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Menu []admin2.ListMyMenuData `json:"menu"` // 菜单栏
|
||||
}
|
||||
|
||||
// Detail 管理员详情
|
||||
@@ -35,7 +35,7 @@ func (h *handler) Detail() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
res := new(detailResponse)
|
||||
|
||||
searchOneData := new(admin_service.SearchOneData)
|
||||
searchOneData := new(admin2.SearchOneData)
|
||||
searchOneData.Id = cast.ToInt32(c.UserID())
|
||||
searchOneData.IsUsed = 1
|
||||
|
||||
@@ -49,7 +49,7 @@ func (h *handler) Detail() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
menuCacheData, err := h.cache.Get(configs.RedisKeyPrefixLoginUser+password.GenerateLoginToken(searchOneData.Id)+":menu", cache.WithTrace(c.Trace()))
|
||||
menuCacheData, err := h.cache.Get(configs.RedisKeyPrefixLoginUser+password.GenerateLoginToken(searchOneData.Id)+":menu", redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
@@ -59,7 +59,7 @@ func (h *handler) Detail() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
var menuData []admin_service.ListMyMenuData
|
||||
var menuData []admin2.ListMyMenuData
|
||||
err = json.Unmarshal([]byte(menuCacheData), &menuData)
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -82,7 +82,7 @@ func (h *handler) List() core.HandlerFunc {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
searchData := new(admin_service.SearchData)
|
||||
searchData := new(admin2.SearchData)
|
||||
searchData.Page = page
|
||||
searchData.PageSize = pageSize
|
||||
searchData.Username = req.Username
|
||||
@@ -137,9 +137,9 @@ func (h *handler) List() core.HandlerFunc {
|
||||
Mobile: v.Mobile,
|
||||
IsUsed: cast.ToInt(v.IsUsed),
|
||||
IsOnline: isOnline,
|
||||
CreatedAt: v.CreatedAt.Format(time_parse.CSTLayout),
|
||||
CreatedAt: v.CreatedAt.Format(timeutil.CSTLayout),
|
||||
CreatedUser: v.CreatedUser,
|
||||
UpdatedAt: v.UpdatedAt.Format(time_parse.CSTLayout),
|
||||
UpdatedAt: v.UpdatedAt.Format(timeutil.CSTLayout),
|
||||
UpdatedUser: v.UpdatedUser,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -14,8 +14,8 @@ type listAdminMenuRequest struct {
|
||||
}
|
||||
|
||||
type listAdminMenuResponse struct {
|
||||
List []admin_service.ListMenuData `json:"list"`
|
||||
UserName string `json:"username"`
|
||||
List []admin2.ListMenuData `json:"list"`
|
||||
UserName string `json:"username"`
|
||||
}
|
||||
|
||||
// ListAdminMenu 菜单授权列表
|
||||
@@ -51,7 +51,7 @@ func (h *handler) ListAdminMenu() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
searchOneData := new(admin_service.SearchOneData)
|
||||
searchOneData := new(admin2.SearchOneData)
|
||||
searchOneData.Id = int32(ids[0])
|
||||
searchOneData.IsUsed = 1
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h *handler) ListAdminMenu() core.HandlerFunc {
|
||||
|
||||
res.UserName = info.Username
|
||||
|
||||
searchData := new(admin_service.SearchListMenuData)
|
||||
searchData := new(admin2.SearchListMenuData)
|
||||
searchData.AdminId = int32(ids[0])
|
||||
|
||||
listData, err := h.adminService.ListMenu(c, searchData)
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
searchOneData := new(admin_service.SearchOneData)
|
||||
searchOneData := new(admin2.SearchOneData)
|
||||
searchOneData.Username = req.Username
|
||||
searchOneData.Password = password.GeneratePassword(req.Password)
|
||||
searchOneData.IsUsed = 1
|
||||
@@ -90,7 +90,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
adminJsonInfo, _ := json.Marshal(adminCacheData)
|
||||
|
||||
// 将用户信息记录到 Redis 中
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token, string(adminJsonInfo), time.Hour*24, cache.WithTrace(c.Trace()))
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token, string(adminJsonInfo), time.Hour*24, redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
@@ -100,7 +100,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
searchMenuData := new(admin_service.SearchMyMenuData)
|
||||
searchMenuData := new(admin2.SearchMyMenuData)
|
||||
searchMenuData.AdminId = info.Id
|
||||
menu, err := h.adminService.MyMenu(c, searchMenuData)
|
||||
if err != nil {
|
||||
@@ -116,7 +116,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
menuJsonInfo, _ := json.Marshal(menu)
|
||||
|
||||
// 将菜单栏信息记录到 Redis 中
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token+":menu", string(menuJsonInfo), time.Hour*24, cache.WithTrace(c.Trace()))
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token+":menu", string(menuJsonInfo), time.Hour*24, redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
@@ -126,7 +126,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
searchActionData := new(admin_service.SearchMyActionData)
|
||||
searchActionData := new(admin2.SearchMyActionData)
|
||||
searchActionData.AdminId = info.Id
|
||||
action, err := h.adminService.MyAction(c, searchActionData)
|
||||
if err != nil {
|
||||
@@ -142,7 +142,7 @@ func (h *handler) Login() core.HandlerFunc {
|
||||
actionJsonInfo, _ := json.Marshal(action)
|
||||
|
||||
// 将可访问接口信息记录到 Redis 中
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token+":action", string(actionJsonInfo), time.Hour*24, cache.WithTrace(c.Trace()))
|
||||
err = h.cache.Set(configs.RedisKeyPrefixLoginUser+token+":action", string(actionJsonInfo), time.Hour*24, redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
@@ -23,13 +23,13 @@ type logoutResponse struct {
|
||||
// @Produce json
|
||||
// @Success 200 {object} logoutResponse
|
||||
// @Failure 400 {object} code.Failure
|
||||
// @Router /api/admin/login [post]
|
||||
// @Router /api/admin/logout [post]
|
||||
func (h *handler) Logout() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
res := new(logoutResponse)
|
||||
res.Username = c.UserName()
|
||||
|
||||
if !h.cache.Del(configs.RedisKeyPrefixLoginUser+c.GetHeader(configs.HeaderLoginToken), cache.WithTrace(c.Trace())) {
|
||||
if !h.cache.Del(configs.RedisKeyPrefixLoginUser+c.GetHeader(configs.HeaderLoginToken), redis.WithTrace(c.Trace())) {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.AdminLogOutError,
|
||||
|
||||
@@ -3,10 +3,10 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -47,7 +47,7 @@ func (h *handler) ModifyPassword() core.HandlerFunc {
|
||||
|
||||
userId := cast.ToInt32(c.UserID())
|
||||
|
||||
searchOneData := new(admin_service.SearchOneData)
|
||||
searchOneData := new(admin2.SearchOneData)
|
||||
searchOneData.Id = userId
|
||||
searchOneData.Password = password.GeneratePassword(req.OldPassword)
|
||||
searchOneData.IsUsed = 1
|
||||
|
||||
@@ -3,9 +3,9 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -30,7 +30,7 @@ type modifyPersonalInfoResponse struct {
|
||||
// @Param mobile formData string true "手机号"
|
||||
// @Success 200 {object} modifyPersonalInfoResponse
|
||||
// @Failure 400 {object} code.Failure
|
||||
// @Router /api/admin/modify_password [patch]
|
||||
// @Router /api/admin/modify_personal_info [patch]
|
||||
func (h *handler) ModifyPersonalInfo() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
req := new(modifyPersonalInfoRequest)
|
||||
@@ -46,7 +46,7 @@ func (h *handler) ModifyPersonalInfo() core.HandlerFunc {
|
||||
|
||||
userId := cast.ToInt32(c.UserID())
|
||||
|
||||
modifyData := new(admin_service.ModifyData)
|
||||
modifyData := new(admin2.ModifyData)
|
||||
modifyData.Nickname = req.Nickname
|
||||
modifyData.Mobile = req.Mobile
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
@@ -54,7 +54,7 @@ func (h *handler) Offline() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
b := h.cache.Del(configs.RedisKeyPrefixLoginUser+password.GenerateLoginToken(id), cache.WithTrace(c.Trace()))
|
||||
b := h.cache.Del(configs.RedisKeyPrefixLoginUser+password.GenerateLoginToken(id), redis.WithTrace(c.Trace()))
|
||||
if !b {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
|
||||
@@ -3,7 +3,7 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package admin_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -2,10 +2,10 @@ package admin_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/hash"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -84,17 +84,17 @@ type Handler interface {
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
hashids hash.Hash
|
||||
adminService admin_service.Service
|
||||
adminService admin2.Service
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
|
||||
adminService: admin_service.New(db, cache),
|
||||
adminService: admin2.New(db, cache),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/authorized_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
authorized2 "github.com/xinliangnote/go-gin-api/internal/services/authorized"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *handler) Create() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createData := new(authorized_service.CreateAuthorizedData)
|
||||
createData := new(authorized2.CreateAuthorizedData)
|
||||
createData.BusinessKey = req.BusinessKey
|
||||
createData.BusinessDeveloper = req.BusinessDeveloper
|
||||
createData.Remark = req.Remark
|
||||
|
||||
@@ -3,9 +3,9 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/authorized_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
authorized2 "github.com/xinliangnote/go-gin-api/internal/services/authorized"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h *handler) CreateAPI() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createAPIData := new(authorized_service.CreateAuthorizedAPIData)
|
||||
createAPIData := new(authorized2.CreateAuthorizedAPIData)
|
||||
createAPIData.BusinessKey = authorizedInfo.BusinessKey
|
||||
createAPIData.Method = req.Method
|
||||
createAPIData.API = req.API
|
||||
|
||||
@@ -3,7 +3,7 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,11 +3,11 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/authorized_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
authorized2 "github.com/xinliangnote/go-gin-api/internal/services/authorized"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -82,7 +82,7 @@ func (h *handler) List() core.HandlerFunc {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
searchData := new(authorized_service.SearchData)
|
||||
searchData := new(authorized2.SearchData)
|
||||
searchData.Page = page
|
||||
searchData.PageSize = pageSize
|
||||
searchData.BusinessKey = req.BusinessKey
|
||||
@@ -132,9 +132,9 @@ func (h *handler) List() core.HandlerFunc {
|
||||
BusinessDeveloper: v.BusinessDeveloper,
|
||||
Remark: v.Remark,
|
||||
IsUsed: cast.ToInt(v.IsUsed),
|
||||
CreatedAt: v.CreatedAt.Format(time_parse.CSTLayout),
|
||||
CreatedAt: v.CreatedAt.Format(timeutil.CSTLayout),
|
||||
CreatedUser: v.CreatedUser,
|
||||
UpdatedAt: v.UpdatedAt.Format(time_parse.CSTLayout),
|
||||
UpdatedAt: v.UpdatedAt.Format(timeutil.CSTLayout),
|
||||
UpdatedUser: v.UpdatedUser,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/authorized_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
authorized2 "github.com/xinliangnote/go-gin-api/internal/services/authorized"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -75,7 +75,7 @@ func (h *handler) ListAPI() core.HandlerFunc {
|
||||
|
||||
res.BusinessKey = authorizedInfo.BusinessKey
|
||||
|
||||
searchAPIData := new(authorized_service.SearchAPIData)
|
||||
searchAPIData := new(authorized2.SearchAPIData)
|
||||
searchAPIData.BusinessKey = authorizedInfo.BusinessKey
|
||||
|
||||
resListData, err := h.authorizedService.ListAPI(c, searchAPIData)
|
||||
|
||||
@@ -3,7 +3,7 @@ package authorized_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -2,10 +2,10 @@ package authorized_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/authorized_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
authorized2 "github.com/xinliangnote/go-gin-api/internal/services/authorized"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/hash"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -54,16 +54,16 @@ type Handler interface {
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
authorizedService authorized_service.Service
|
||||
cache redis.Repo
|
||||
authorizedService authorized2.Service
|
||||
hashids hash.Hash
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
authorizedService: authorized_service.New(db, cache),
|
||||
authorizedService: authorized2.New(db, cache),
|
||||
hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/env"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
@@ -72,10 +72,6 @@ func (h *handler) Email() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
viper.SetConfigName(env.Active().Value() + "_configs")
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath("./configs")
|
||||
|
||||
viper.Set("mail.host", req.Host)
|
||||
viper.Set("mail.port", cast.ToInt(req.Port))
|
||||
viper.Set("mail.user", req.User)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package config_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
@@ -21,10 +21,10 @@ type Handler interface {
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
|
||||
@@ -3,10 +3,10 @@ package cron_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/cron_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
cron2 "github.com/xinliangnote/go-gin-api/internal/services/cron"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h *handler) Create() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createData := new(cron_service.CreateCronTaskData)
|
||||
createData := new(cron2.CreateCronTaskData)
|
||||
createData.Name = req.Name
|
||||
createData.Spec = req.Spec
|
||||
createData.Command = req.Command
|
||||
|
||||
@@ -3,10 +3,10 @@ package cron_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/cron_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
cron2 "github.com/xinliangnote/go-gin-api/internal/services/cron"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -66,7 +66,7 @@ func (h *handler) Detail() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
searchOneData := new(cron_service.SearchOneData)
|
||||
searchOneData := new(cron2.SearchOneData)
|
||||
searchOneData.Id = cast.ToInt32(ids[0])
|
||||
|
||||
info, err := h.cronService.Detail(ctx, searchOneData)
|
||||
|
||||
@@ -3,7 +3,7 @@ package cron_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/db_repo/cron_task_repo"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/cron_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
cron2 "github.com/xinliangnote/go-gin-api/internal/services/cron"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -91,7 +91,7 @@ func (h *handler) List() core.HandlerFunc {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
searchData := new(cron_service.SearchData)
|
||||
searchData := new(cron2.SearchData)
|
||||
searchData.Page = req.Page
|
||||
searchData.PageSize = req.PageSize
|
||||
searchData.Name = req.Name
|
||||
@@ -151,9 +151,9 @@ func (h *handler) List() core.HandlerFunc {
|
||||
NotifyStatusText: cron_task_repo.NotifyStatusText[v.NotifyStatus],
|
||||
IsUsed: cast.ToInt(v.IsUsed),
|
||||
IsUsedText: cron_task_repo.IsUsedText[v.IsUsed],
|
||||
CreatedAt: v.CreatedAt.Format(time_parse.CSTLayout),
|
||||
CreatedAt: v.CreatedAt.Format(timeutil.CSTLayout),
|
||||
CreatedUser: v.CreatedUser,
|
||||
UpdatedAt: v.UpdatedAt.Format(time_parse.CSTLayout),
|
||||
UpdatedAt: v.UpdatedAt.Format(timeutil.CSTLayout),
|
||||
UpdatedUser: v.UpdatedUser,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package cron_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/cron_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
cron2 "github.com/xinliangnote/go-gin-api/internal/services/cron"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -81,7 +81,7 @@ func (h *handler) Modify() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
modifyData := new(cron_service.ModifyCronTaskData)
|
||||
modifyData := new(cron2.ModifyCronTaskData)
|
||||
modifyData.Name = req.Name
|
||||
modifyData.Spec = req.Spec
|
||||
modifyData.Command = req.Command
|
||||
|
||||
@@ -3,7 +3,7 @@ package cron_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
@@ -2,11 +2,11 @@ package cron_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/cron_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/cron/cron_server"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/internal/services/cron"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/hash"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -50,17 +50,17 @@ type Handler interface {
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
hashids hash.Hash
|
||||
cronService cron_service.Service
|
||||
cronService cron.Service
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo, cron cron_server.Server) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo, cronServer cron_server.Server) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
|
||||
cronService: cron_service.New(db, cache, cron),
|
||||
cronService: cron.New(db, cache, cronServer),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -60,7 +60,7 @@ func (h *handler) Create() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
updateData := new(menu_service.UpdateMenuData)
|
||||
updateData := new(menu2.UpdateMenuData)
|
||||
updateData.Name = req.Name
|
||||
updateData.Icon = req.Icon
|
||||
updateData.Link = req.Link
|
||||
@@ -88,7 +88,7 @@ func (h *handler) Create() core.HandlerFunc {
|
||||
level = 1
|
||||
}
|
||||
|
||||
createData := new(menu_service.CreateMenuData)
|
||||
createData := new(menu2.CreateMenuData)
|
||||
createData.Pid = pid
|
||||
createData.Name = req.Name
|
||||
createData.Icon = req.Icon
|
||||
|
||||
@@ -3,9 +3,9 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ func (h *handler) CreateAction() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
searchOneData := new(menu_service.SearchOneData)
|
||||
searchOneData := new(menu2.SearchOneData)
|
||||
searchOneData.Id = id
|
||||
menuInfo, err := h.menuService.Detail(c, searchOneData)
|
||||
if err != nil {
|
||||
@@ -68,7 +68,7 @@ func (h *handler) CreateAction() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
createActionData := new(menu_service.CreateMenuActionData)
|
||||
createActionData := new(menu2.CreateMenuActionData)
|
||||
createActionData.MenuId = menuInfo.Id
|
||||
createActionData.Method = req.Method
|
||||
createActionData.API = req.API
|
||||
|
||||
@@ -3,7 +3,7 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,9 +3,9 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ func (h *handler) Detail() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
searchOneData := new(menu_service.SearchOneData)
|
||||
searchOneData := new(menu2.SearchOneData)
|
||||
searchOneData.Id = id
|
||||
|
||||
info, err := h.menuService.Detail(c, searchOneData)
|
||||
|
||||
@@ -3,9 +3,9 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -38,7 +38,7 @@ type listResponse struct {
|
||||
func (h *handler) List() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
res := new(listResponse)
|
||||
resListData, err := h.menuService.List(c, new(menu_service.SearchData))
|
||||
resListData, err := h.menuService.List(c, new(menu2.SearchData))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
|
||||
@@ -3,9 +3,9 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
@@ -62,7 +62,7 @@ func (h *handler) ListAction() core.HandlerFunc {
|
||||
|
||||
id := int32(ids[0])
|
||||
|
||||
searchOneData := new(menu_service.SearchOneData)
|
||||
searchOneData := new(menu2.SearchOneData)
|
||||
searchOneData.Id = id
|
||||
|
||||
menuInfo, err := h.menuService.Detail(c, searchOneData)
|
||||
@@ -77,7 +77,7 @@ func (h *handler) ListAction() core.HandlerFunc {
|
||||
|
||||
res.MenuName = menuInfo.Name
|
||||
|
||||
searchListData := new(menu_service.SearchListActionData)
|
||||
searchListData := new(menu2.SearchListActionData)
|
||||
searchListData.MenuId = menuInfo.Id
|
||||
|
||||
resListData, err := h.menuService.ListAction(c, searchListData)
|
||||
|
||||
@@ -3,7 +3,7 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package menu_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -2,10 +2,10 @@ package menu_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/menu_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
menu2 "github.com/xinliangnote/go-gin-api/internal/services/menu"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/hash"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -64,17 +64,17 @@ type Handler interface {
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
hashids hash.Hash
|
||||
menuService menu_service.Service
|
||||
menuService menu2.Service
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
|
||||
menuService: menu_service.New(db, cache),
|
||||
menuService: menu2.New(db, cache),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package tool_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
@@ -49,7 +49,7 @@ func (h *handler) ClearCache() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
b := h.cache.Del(req.RedisKey, cache.WithTrace(c.Trace()))
|
||||
b := h.cache.Del(req.RedisKey, redis.WithTrace(c.Trace()))
|
||||
if b != true {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
|
||||
@@ -3,7 +3,7 @@ package tool_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package tool_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package tool_handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
@@ -50,7 +50,7 @@ func (h *handler) SearchCache() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
val, err := h.cache.Get(req.RedisKey, cache.WithTrace(c.Trace()))
|
||||
val, err := h.cache.Get(req.RedisKey, redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/validation"
|
||||
"github.com/xinliangnote/go-gin-api/internal/websocket/socket_conn/system_message"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
)
|
||||
|
||||
type sendMessageRequest struct {
|
||||
@@ -62,7 +62,7 @@ func (h *handler) SendMessage() core.HandlerFunc {
|
||||
messageData := new(messageBody)
|
||||
messageData.Username = ctx.UserName()
|
||||
messageData.Message = req.Message
|
||||
messageData.Time = time_parse.CSTLayoutString()
|
||||
messageData.Time = timeutil.CSTLayoutString()
|
||||
|
||||
messageJsonData, err := json.Marshal(messageData)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package tool_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/hash"
|
||||
@@ -59,11 +59,11 @@ type Handler interface {
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
db db.Repo
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
hashids hash.Hash
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Handler {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
db: db,
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
## repository
|
||||
|
||||
#### 数据访问层。
|
||||
|
||||
- `./db_repo` 访问 DB 数据
|
||||
- `./cache_repo` 访问 Cache 数据
|
||||
|
||||
#### SQL 建议:
|
||||
- 建议每张表需包含字段:主键(id)、标记删除(is_deteled)、创建时间(created_at)、更新时间(updated_at)
|
||||
|
||||
```mysql
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`is_deleted` tinyint(1) NOT NULL DEFAULT '-1' COMMENT '是否删除 1:是 -1:否',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
```
|
||||
|
||||
#### 命名规范:
|
||||
|
||||
- 包名应以 `_repo` 结尾;
|
||||
- `./db_repo` 目录下的包名以 `数据表名`+ `_repo` 命名;
|
||||
|
||||
@@ -1,275 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: hello.proto
|
||||
|
||||
package hello
|
||||
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
math "math"
|
||||
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// HelloRequest 请求结构
|
||||
type HelloRequest struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *HelloRequest) Reset() { *m = HelloRequest{} }
|
||||
func (m *HelloRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*HelloRequest) ProtoMessage() {}
|
||||
func (*HelloRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_61ef911816e0a8ce, []int{0}
|
||||
}
|
||||
|
||||
func (m *HelloRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_HelloRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *HelloRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_HelloRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *HelloRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_HelloRequest.Merge(m, src)
|
||||
}
|
||||
func (m *HelloRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_HelloRequest.Size(m)
|
||||
}
|
||||
func (m *HelloRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_HelloRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_HelloRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *HelloRequest) GetName() string {
|
||||
if m != nil {
|
||||
return m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// HelloResponse 响应结构
|
||||
type HelloResponse struct {
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *HelloResponse) Reset() { *m = HelloResponse{} }
|
||||
func (m *HelloResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*HelloResponse) ProtoMessage() {}
|
||||
func (*HelloResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_61ef911816e0a8ce, []int{1}
|
||||
}
|
||||
|
||||
func (m *HelloResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_HelloResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *HelloResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_HelloResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *HelloResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_HelloResponse.Merge(m, src)
|
||||
}
|
||||
func (m *HelloResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_HelloResponse.Size(m)
|
||||
}
|
||||
func (m *HelloResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_HelloResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_HelloResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *HelloResponse) GetMessage() string {
|
||||
if m != nil {
|
||||
return m.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*HelloRequest)(nil), "hello.HelloRequest")
|
||||
proto.RegisterType((*HelloResponse)(nil), "hello.HelloResponse")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("hello.proto", fileDescriptor_61ef911816e0a8ce) }
|
||||
|
||||
var fileDescriptor_61ef911816e0a8ce = []byte{
|
||||
// 154 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x48, 0xcd, 0xc9,
|
||||
0xc9, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x73, 0x94, 0x94, 0xb8, 0x78, 0x3c,
|
||||
0x40, 0x8c, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x21, 0x21, 0x2e, 0x96, 0xbc, 0xc4, 0xdc,
|
||||
0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x30, 0x5b, 0x49, 0x93, 0x8b, 0x17, 0xaa, 0xa6,
|
||||
0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x82, 0x8b, 0x3d, 0x37, 0xb5, 0xb8, 0x38, 0x31, 0x1d,
|
||||
0xa6, 0x0e, 0xc6, 0x35, 0x6a, 0x60, 0xe4, 0x62, 0x05, 0xab, 0x15, 0x32, 0xe7, 0xe2, 0x08, 0x4e,
|
||||
0xac, 0x84, 0xb0, 0x85, 0xf5, 0x20, 0x36, 0x23, 0xdb, 0x24, 0x25, 0x82, 0x2a, 0x08, 0x31, 0x5a,
|
||||
0x89, 0x41, 0xc8, 0x8e, 0x8b, 0xd7, 0x27, 0xbf, 0xa4, 0xd8, 0x3f, 0x2d, 0x28, 0xb5, 0x20, 0x27,
|
||||
0x33, 0xb5, 0x98, 0x24, 0xdd, 0x06, 0x8c, 0x49, 0x6c, 0x60, 0xff, 0x19, 0x03, 0x02, 0x00, 0x00,
|
||||
0xff, 0xff, 0x87, 0x17, 0x0f, 0x68, 0xee, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// HelloClient is the client API for Hello service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type HelloClient interface {
|
||||
// 定义 SayHello 方法
|
||||
SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
|
||||
// 定义 LotsOfReplies 方法
|
||||
LotsOfReplies(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (Hello_LotsOfRepliesClient, error)
|
||||
}
|
||||
|
||||
type helloClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewHelloClient(cc *grpc.ClientConn) HelloClient {
|
||||
return &helloClient{cc}
|
||||
}
|
||||
|
||||
func (c *helloClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) {
|
||||
out := new(HelloResponse)
|
||||
err := c.cc.Invoke(ctx, "/hello.Hello/SayHello", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *helloClient) LotsOfReplies(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (Hello_LotsOfRepliesClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_Hello_serviceDesc.Streams[0], "/hello.Hello/LotsOfReplies", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &helloLotsOfRepliesClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Hello_LotsOfRepliesClient interface {
|
||||
Recv() (*HelloResponse, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type helloLotsOfRepliesClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *helloLotsOfRepliesClient) Recv() (*HelloResponse, error) {
|
||||
m := new(HelloResponse)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// HelloServer is the server API for Hello service.
|
||||
type HelloServer interface {
|
||||
// 定义 SayHello 方法
|
||||
SayHello(context.Context, *HelloRequest) (*HelloResponse, error)
|
||||
// 定义 LotsOfReplies 方法
|
||||
LotsOfReplies(*HelloRequest, Hello_LotsOfRepliesServer) error
|
||||
}
|
||||
|
||||
// UnimplementedHelloServer can be embedded to have forward compatible implementations.
|
||||
type UnimplementedHelloServer struct {
|
||||
}
|
||||
|
||||
func (*UnimplementedHelloServer) SayHello(ctx context.Context, req *HelloRequest) (*HelloResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented")
|
||||
}
|
||||
func (*UnimplementedHelloServer) LotsOfReplies(req *HelloRequest, srv Hello_LotsOfRepliesServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method LotsOfReplies not implemented")
|
||||
}
|
||||
|
||||
func RegisterHelloServer(s *grpc.Server, srv HelloServer) {
|
||||
s.RegisterService(&_Hello_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Hello_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(HelloRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(HelloServer).SayHello(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/hello.Hello/SayHello",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(HelloServer).SayHello(ctx, req.(*HelloRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Hello_LotsOfReplies_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(HelloRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(HelloServer).LotsOfReplies(m, &helloLotsOfRepliesServer{stream})
|
||||
}
|
||||
|
||||
type Hello_LotsOfRepliesServer interface {
|
||||
Send(*HelloResponse) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type helloLotsOfRepliesServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *helloLotsOfRepliesServer) Send(m *HelloResponse) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
var _Hello_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "hello.Hello",
|
||||
HandlerType: (*HelloServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "SayHello",
|
||||
Handler: _Hello_SayHello_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "LotsOfReplies",
|
||||
Handler: _Hello_LotsOfReplies_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "hello.proto",
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
syntax = "proto3"; // 指定 proto 版本
|
||||
|
||||
package hello; // 指定包名
|
||||
|
||||
// 定义 Hello 服务
|
||||
service Hello {
|
||||
|
||||
// 定义 SayHello 方法
|
||||
rpc SayHello(HelloRequest) returns (HelloResponse) {}
|
||||
|
||||
// 定义 LotsOfReplies 方法
|
||||
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse){}
|
||||
}
|
||||
|
||||
// HelloRequest 请求结构
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// HelloResponse 响应结构
|
||||
message HelloResponse {
|
||||
string message = 1;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package cache
|
||||
package redis
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/trace"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
@@ -37,6 +38,7 @@ type Repo interface {
|
||||
Exists(keys ...string) bool
|
||||
Incr(key string, options ...Option) int64
|
||||
Close() error
|
||||
Version() string
|
||||
}
|
||||
|
||||
type cacheRepo struct {
|
||||
@@ -80,7 +82,7 @@ func (c *cacheRepo) Set(key, value string, ttl time.Duration, options ...Option)
|
||||
opt := newOption()
|
||||
defer func() {
|
||||
if opt.Trace != nil {
|
||||
opt.Redis.Timestamp = time_parse.CSTLayoutString()
|
||||
opt.Redis.Timestamp = timeutil.CSTLayoutString()
|
||||
opt.Redis.Handle = "set"
|
||||
opt.Redis.Key = key
|
||||
opt.Redis.Value = value
|
||||
@@ -107,7 +109,7 @@ func (c *cacheRepo) Get(key string, options ...Option) (string, error) {
|
||||
opt := newOption()
|
||||
defer func() {
|
||||
if opt.Trace != nil {
|
||||
opt.Redis.Timestamp = time_parse.CSTLayoutString()
|
||||
opt.Redis.Timestamp = timeutil.CSTLayoutString()
|
||||
opt.Redis.Handle = "get"
|
||||
opt.Redis.Key = key
|
||||
opt.Redis.CostSeconds = time.Since(ts).Seconds()
|
||||
@@ -162,7 +164,7 @@ func (c *cacheRepo) Del(key string, options ...Option) bool {
|
||||
opt := newOption()
|
||||
defer func() {
|
||||
if opt.Trace != nil {
|
||||
opt.Redis.Timestamp = time_parse.CSTLayoutString()
|
||||
opt.Redis.Timestamp = timeutil.CSTLayoutString()
|
||||
opt.Redis.Handle = "del"
|
||||
opt.Redis.Key = key
|
||||
opt.Redis.CostSeconds = time.Since(ts).Seconds()
|
||||
@@ -187,7 +189,7 @@ func (c *cacheRepo) Incr(key string, options ...Option) int64 {
|
||||
opt := newOption()
|
||||
defer func() {
|
||||
if opt.Trace != nil {
|
||||
opt.Redis.Timestamp = time_parse.CSTLayoutString()
|
||||
opt.Redis.Timestamp = timeutil.CSTLayoutString()
|
||||
opt.Redis.Handle = "incr"
|
||||
opt.Redis.Key = key
|
||||
opt.Redis.CostSeconds = time.Since(ts).Seconds()
|
||||
@@ -216,3 +218,12 @@ func WithTrace(t Trace) Option {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Version redis server version
|
||||
func (c *cacheRepo) Version() string {
|
||||
server := c.client.Info("server").Val()
|
||||
spl1 := strings.Split(server, "# Server")
|
||||
spl2 := strings.Split(spl1[1], "redis_version:")
|
||||
spl3 := strings.Split(spl2[1], "redis_git_sha1:")
|
||||
return spl3[0]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
## service
|
||||
|
||||
业务逻辑层。
|
||||
|
||||
处于 `controller` 层和 `repository` 层之间,依赖接口开发。
|
||||
|
||||
命令规范:
|
||||
|
||||
- 包名以 `_service` 结尾。
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package code
|
||||
|
||||
import "github.com/xinliangnote/go-gin-api/configs"
|
||||
import (
|
||||
_ "embed"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
)
|
||||
|
||||
//go:embed code.go
|
||||
var ByteCodeFile []byte
|
||||
|
||||
// Failure 错误时返回结构
|
||||
type Failure struct {
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/db_repo/cron_task_repo"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
|
||||
@@ -43,7 +43,7 @@ func (tc *taskCount) Wait() {
|
||||
type server struct {
|
||||
logger *zap.Logger
|
||||
db db.Repo
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
cron *cron.Cron
|
||||
taskCount *taskCount
|
||||
}
|
||||
@@ -67,7 +67,7 @@ type Server interface {
|
||||
AddJob(task *cron_task_repo.CronTask) cron.FuncJob
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) (Server, error) {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) (Server, error) {
|
||||
if logger == nil {
|
||||
return nil, errors.New("logger required")
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/graph/generated"
|
||||
"github.com/xinliangnote/go-gin-api/internal/graph/resolvers"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
@@ -30,10 +30,10 @@ type Gql interface {
|
||||
type gql struct {
|
||||
logger *zap.Logger
|
||||
db db.Repo
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache cache.Repo) Gql {
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) Gql {
|
||||
return &gql{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
|
||||
@@ -3,8 +3,8 @@ package resolvers
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/graph/generated"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
@@ -21,11 +21,11 @@ type queryResolver struct{ *Resolver }
|
||||
|
||||
type Resolver struct {
|
||||
logger *zap.Logger
|
||||
cache cache.Repo
|
||||
cache redis.Repo
|
||||
//userService user_service.UserService
|
||||
}
|
||||
|
||||
func NewRootResolvers(logger *zap.Logger, db db.Repo, cache cache.Repo) generated.Config {
|
||||
func NewRootResolvers(logger *zap.Logger, db db.Repo, cache redis.Repo) generated.Config {
|
||||
c := generated.Config{
|
||||
Resolvers: &Resolver{
|
||||
logger: logger,
|
||||
|
||||
@@ -2,14 +2,16 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/assets"
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
_ "github.com/xinliangnote/go-gin-api/docs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/browser"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/color"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/env"
|
||||
@@ -28,6 +30,7 @@ import (
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
// see https://patorjk.com/software/taag/#p=testall&f=Graffiti&t=go-gin-api
|
||||
const _UI = `
|
||||
██████╗ ██████╗ ██████╗ ██╗███╗ ██╗ █████╗ ██████╗ ██╗
|
||||
██╔════╝ ██╔═══██╗ ██╔════╝ ██║████╗ ██║ ██╔══██╗██╔══██╗██║
|
||||
@@ -37,8 +40,6 @@ const _UI = `
|
||||
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝
|
||||
`
|
||||
|
||||
const _MaxBurstSize = 100000
|
||||
|
||||
type Option func(*option)
|
||||
|
||||
type option struct {
|
||||
@@ -84,7 +85,6 @@ func WithDisablePrometheus() Option {
|
||||
func WithPanicNotify(notify OnPanicNotify) Option {
|
||||
return func(opt *option) {
|
||||
opt.panicNotify = notify
|
||||
fmt.Println(color.Green("* [register panic notify]"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,14 +106,12 @@ func WithEnableOpenBrowser(uri string) Option {
|
||||
func WithEnableCors() Option {
|
||||
return func(opt *option) {
|
||||
opt.enableCors = true
|
||||
fmt.Println(color.Green("* [register cors]"))
|
||||
}
|
||||
}
|
||||
|
||||
func WithEnableRate() Option {
|
||||
return func(opt *option) {
|
||||
opt.enableRate = true
|
||||
fmt.Println(color.Green("* [register rate]"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,19 +244,16 @@ func New(logger *zap.Logger, options ...Option) (Mux, error) {
|
||||
}
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
//gin.DisableBindValidation()
|
||||
mux := &mux{
|
||||
engine: gin.New(),
|
||||
}
|
||||
|
||||
fmt.Println(color.Blue(_UI))
|
||||
fmt.Println(color.Green(fmt.Sprintf("* [register port %s]", configs.ProjectPort)))
|
||||
fmt.Println(color.Green(fmt.Sprintf("* [register env %s]", env.Active().Value())))
|
||||
|
||||
mux.engine.StaticFS("bootstrap", http.Dir("./assets/bootstrap"))
|
||||
mux.engine.LoadHTMLGlob("./assets/templates/**/*")
|
||||
mux.engine.StaticFS("assets", http.FS(assets.Bootstrap))
|
||||
mux.engine.SetHTMLTemplate(template.Must(template.New("").ParseFS(assets.Templates, "templates/**/*")))
|
||||
|
||||
// withoutLogPaths 这些请求,默认不记录日志
|
||||
// withoutTracePaths 这些请求,默认不记录日志
|
||||
withoutTracePaths := map[string]bool{
|
||||
"/metrics": true,
|
||||
|
||||
@@ -287,20 +282,17 @@ func New(logger *zap.Logger, options ...Option) (Mux, error) {
|
||||
if !opt.disablePProf {
|
||||
if !env.Active().IsPro() {
|
||||
pprof.Register(mux.engine) // register pprof to gin
|
||||
fmt.Println(color.Green("* [register pprof]"))
|
||||
}
|
||||
}
|
||||
|
||||
if !opt.disableSwagger {
|
||||
if !env.Active().IsPro() {
|
||||
mux.engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // register swagger
|
||||
fmt.Println(color.Green("* [register swagger]"))
|
||||
}
|
||||
}
|
||||
|
||||
if !opt.disablePrometheus {
|
||||
mux.engine.GET("/metrics", gin.WrapH(promhttp.Handler())) // register prometheus
|
||||
fmt.Println(color.Green("* [register prometheus]"))
|
||||
}
|
||||
|
||||
if opt.enableCors {
|
||||
@@ -322,7 +314,6 @@ func New(logger *zap.Logger, options ...Option) (Mux, error) {
|
||||
|
||||
if opt.enableOpenBrowser != "" {
|
||||
_ = browser.Open(opt.enableOpenBrowser)
|
||||
fmt.Println(color.Green("* [register open browser '" + opt.enableOpenBrowser + "']"))
|
||||
}
|
||||
|
||||
// recover两次,防止处理时发生panic,尤其是在OnPanicNotify中。
|
||||
@@ -497,7 +488,7 @@ func New(logger *zap.Logger, options ...Option) (Mux, error) {
|
||||
})
|
||||
|
||||
if opt.enableRate {
|
||||
limiter := rate.NewLimiter(rate.Every(time.Second*1), _MaxBurstSize)
|
||||
limiter := rate.NewLimiter(rate.Every(time.Second*1), configs.MaxRequestsPerSecond)
|
||||
mux.engine.Use(func(ctx *gin.Context) {
|
||||
context := newContext(ctx)
|
||||
defer releaseContext(context)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/timeutil"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/trace"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -69,7 +69,7 @@ func after(db *gorm.DB) {
|
||||
sql := db.Dialector.Explain(db.Statement.SQL.String(), db.Statement.Vars...)
|
||||
|
||||
sqlInfo := new(trace.SQL)
|
||||
sqlInfo.Timestamp = time_parse.CSTLayoutString()
|
||||
sqlInfo.Timestamp = timeutil.CSTLayoutString()
|
||||
sqlInfo.SQL = sql
|
||||
sqlInfo.Stack = utils.FileWithLineNum()
|
||||
sqlInfo.Rows = db.Statement.RowsAffected
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ ClientConn = (*clientConn)(nil)
|
||||
|
||||
type ClientConn interface {
|
||||
i()
|
||||
Conn() *grpc.ClientConn
|
||||
}
|
||||
|
||||
type clientConn struct {
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
func New() (ClientConn, error) {
|
||||
|
||||
// TODO 需从配置文件中获取
|
||||
//target := "127.0.0.1:9988"
|
||||
//secret := "abcdef"
|
||||
//
|
||||
//clientInterceptor := NewClientInterceptor(func(message []byte) (authorization string, err error) {
|
||||
// return GenerateSign(secret, message)
|
||||
//})
|
||||
//
|
||||
//conn, err := grpclient.New(target,
|
||||
// grpclient.WithKeepAlive(keepAlive),
|
||||
// grpclient.WithDialTimeout(time.Second*5),
|
||||
// grpclient.WithUnaryInterceptor(clientInterceptor.UnaryInterceptor),
|
||||
//)
|
||||
//
|
||||
//return &clientConn{
|
||||
// conn: conn,
|
||||
//}, err
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *clientConn) i() {}
|
||||
|
||||
func (c *clientConn) Conn() *grpc.ClientConn {
|
||||
return c.conn
|
||||
}
|
||||
|
||||
func ContextWithValueAndTimeout(value interface{}, duration time.Duration) context.Context {
|
||||
ctx, _ := context.WithTimeout(context.Background(), duration)
|
||||
return context.WithValue(ctx, ClientWithContextKey, value)
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/notify"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/p"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/time_parse"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/trace"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const (
|
||||
TraceID = "trace-id"
|
||||
)
|
||||
|
||||
type clientWithContextKeyType struct{ name string }
|
||||
|
||||
var ClientWithContextKey = clientWithContextKeyType{"_client_with_context"}
|
||||
|
||||
// ClientInterceptor the client's interceptor
|
||||
type ClientInterceptor struct {
|
||||
sign Sign
|
||||
}
|
||||
|
||||
// NewClientInterceptor create a client interceptor
|
||||
func NewClientInterceptor(sign Sign) *ClientInterceptor {
|
||||
return &ClientInterceptor{
|
||||
sign: sign,
|
||||
}
|
||||
}
|
||||
|
||||
// UnaryInterceptor a interceptor for client unary operations
|
||||
func (c *ClientInterceptor) UnaryInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
var (
|
||||
invokerErr error
|
||||
ts = time.Now()
|
||||
coreContext = ctx.Value(ClientWithContextKey).(core.Context)
|
||||
)
|
||||
|
||||
defer func() { // double recover for safety
|
||||
if err := recover(); err != nil {
|
||||
stackInfo := string(debug.Stack())
|
||||
coreContext.Logger().Error("UnaryInterceptor got double panic", zap.String("panic", fmt.Sprintf("%+v", err)), zap.String("stack", stackInfo))
|
||||
coreContext.AbortWithError(errno.NewError(
|
||||
http.StatusInternalServerError,
|
||||
code.ServerError,
|
||||
code.Text(code.ServerError)),
|
||||
)
|
||||
notify.OnPanicNotify(coreContext, err, stackInfo)
|
||||
}
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
stackInfo := string(debug.Stack())
|
||||
coreContext.Logger().Error("UnaryInterceptor got panic", zap.String("panic", fmt.Sprintf("%+v", err)), zap.String("stack", stackInfo))
|
||||
coreContext.AbortWithError(errno.NewError(
|
||||
http.StatusInternalServerError,
|
||||
code.ServerError,
|
||||
code.Text(code.ServerError)),
|
||||
)
|
||||
notify.OnPanicNotify(coreContext, err, stackInfo)
|
||||
}
|
||||
|
||||
if coreContext.Trace() != nil {
|
||||
var mapReq, mapReply map[string]interface{}
|
||||
mapReq, err := ProtoMessage2Map(req.(proto.Message))
|
||||
if err != nil {
|
||||
p.Println("req ProtoMessage2Map err", err, p.WithTrace(coreContext.Trace()))
|
||||
}
|
||||
|
||||
mapReply, err = ProtoMessage2Map(reply.(proto.Message))
|
||||
if err != nil {
|
||||
p.Println("reply ProtoMessage2Map err", err, p.WithTrace(coreContext.Trace()))
|
||||
}
|
||||
|
||||
meta, _ := metadata.FromOutgoingContext(ctx)
|
||||
|
||||
gRPCTrace := new(trace.Grpc)
|
||||
gRPCTrace.Timestamp = time_parse.CSTLayoutString()
|
||||
gRPCTrace.Addr = cc.Target()
|
||||
gRPCTrace.Method = method
|
||||
gRPCTrace.Meta = meta
|
||||
gRPCTrace.Request = mapReq
|
||||
gRPCTrace.Response = mapReply
|
||||
gRPCTrace.CostSeconds = time.Since(ts).Seconds()
|
||||
|
||||
if invokerErr != nil {
|
||||
statusErr, ok := status.FromError(invokerErr)
|
||||
if ok {
|
||||
gRPCTrace.Code = statusErr.Code().String()
|
||||
gRPCTrace.Message = statusErr.Message()
|
||||
}
|
||||
}
|
||||
|
||||
coreContext.Trace().AppendGRPC(gRPCTrace)
|
||||
}
|
||||
}()
|
||||
|
||||
if c.sign != nil {
|
||||
var (
|
||||
raw string
|
||||
signature string
|
||||
err error
|
||||
)
|
||||
|
||||
if req != nil {
|
||||
if raw, err = ProtoMessage2JSON(req.(proto.Message)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if signature, err = c.sign([]byte(raw)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
meta, _ := metadata.FromOutgoingContext(ctx)
|
||||
if meta == nil {
|
||||
meta = make(metadata.MD)
|
||||
}
|
||||
|
||||
meta.Set(ProxyAuthorization, signature)
|
||||
ctx = metadata.NewOutgoingContext(ctx, meta)
|
||||
}
|
||||
|
||||
if coreContext.Trace() != nil {
|
||||
meta, _ := metadata.FromOutgoingContext(ctx)
|
||||
if meta == nil {
|
||||
meta = make(metadata.MD)
|
||||
}
|
||||
|
||||
meta.Set(TraceID, coreContext.Trace().ID())
|
||||
ctx = metadata.NewOutgoingContext(ctx, meta)
|
||||
}
|
||||
|
||||
invokerErr = invoker(ctx, method, req, reply, cc, opts...)
|
||||
return invokerErr
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/keepalive"
|
||||
)
|
||||
|
||||
var (
|
||||
keepAlive = &keepalive.ClientParameters{
|
||||
Time: 10 * time.Second,
|
||||
Timeout: time.Second,
|
||||
PermitWithoutStream: true,
|
||||
}
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
// 演示 sign 使用,实际情况中以 gRPC server 约定的签名算法为准
|
||||
|
||||
const (
|
||||
// ProxyAuthorization used by signature, both gateway and grpc
|
||||
ProxyAuthorization = "proxy-authorization"
|
||||
)
|
||||
|
||||
type Sign func(message []byte) (auth string, err error)
|
||||
|
||||
func GenerateSign(secret string, message []byte) (auth string, err error) {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
buffer.Write(message)
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(secret))
|
||||
hash.Write(buffer.Bytes())
|
||||
digest := base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
||||
return digest, nil
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var jsonMarshal = &jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EmitDefaults: true,
|
||||
}
|
||||
|
||||
// ProtoMessage2JSON marshal protobuf message to json string
|
||||
func ProtoMessage2JSON(message proto.Message) (string, error) {
|
||||
if message == nil {
|
||||
return "", errors.New("message required")
|
||||
}
|
||||
|
||||
raw, err := jsonMarshal.MarshalToString(message)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "marshal protobuf message to json err")
|
||||
}
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
// ProtoMessage2Map marshal protobuf message to map[string]interface{}
|
||||
func ProtoMessage2Map(message proto.Message) (map[string]interface{}, error) {
|
||||
if message == nil {
|
||||
return nil, errors.New("message required")
|
||||
}
|
||||
|
||||
raw := bytes.NewBuffer(nil)
|
||||
if err := jsonMarshal.Marshal(raw, message); err != nil {
|
||||
return nil, errors.Wrap(err, "marshal protobuf message to map err")
|
||||
}
|
||||
|
||||
var mp map[string]interface{}
|
||||
if err := json.Unmarshal(raw.Bytes(), &mp); err != nil {
|
||||
return nil, errors.Wrap(err, "marshal protobuf message to map err")
|
||||
}
|
||||
|
||||
return mp, nil
|
||||
}
|
||||
@@ -8,19 +8,24 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// OnPanicNotify 发生 panic 时进行通知
|
||||
func OnPanicNotify(ctx core.Context, err interface{}, stackInfo string) {
|
||||
// Email 发生 panic 时进行邮件通知
|
||||
func Email(ctx core.Context, err interface{}, stackInfo string) {
|
||||
cfg := configs.Get().Mail
|
||||
if cfg.Host == "" || cfg.Port == 0 || cfg.User == "" || cfg.Pass == "" || cfg.To == "" {
|
||||
ctx.Logger().Error("Mail config error")
|
||||
return
|
||||
}
|
||||
|
||||
tractID := ""
|
||||
if ctx.Trace() != nil {
|
||||
tractID = ctx.Trace().ID()
|
||||
}
|
||||
|
||||
subject, body, htmlErr := NewPanicHTMLEmail(
|
||||
ctx.Method(),
|
||||
ctx.Host(),
|
||||
ctx.URI(),
|
||||
ctx.Trace().ID(),
|
||||
tractID,
|
||||
err,
|
||||
stackInfo,
|
||||
)
|
||||
|
||||
@@ -84,7 +84,7 @@ const PanicMail = `
|
||||
Stack:
|
||||
</td>
|
||||
<td style="width: 90%;">
|
||||
{{.Stack}}}
|
||||
{{.Stack}}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `admin` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `admin_menu` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `authorized` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `authorized_api` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `cron_task` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `menu` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package mysql_table
|
||||
package tablesqls
|
||||
|
||||
//CREATE TABLE `menu_action` (
|
||||
//`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
@@ -0,0 +1,117 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
db db.Repo
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Login() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("admin_login", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Add() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("admin_add", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) List() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("admin_list", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Menu() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("menu_view", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) AdminMenu() core.HandlerFunc {
|
||||
type adminMenuRequest struct {
|
||||
Id string `uri:"id"` // 主键ID
|
||||
}
|
||||
|
||||
type adminMenuResponse struct {
|
||||
HashID string `json:"hash_id"` // hashID
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
req := new(adminMenuRequest)
|
||||
if err := ctx.ShouldBindURI(req); err != nil {
|
||||
ctx.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.ParamBindError,
|
||||
code.Text(code.ParamBindError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
obj := new(adminMenuResponse)
|
||||
obj.HashID = req.Id
|
||||
|
||||
ctx.HTML("admin_menu", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) MenuAction() core.HandlerFunc {
|
||||
type menuActionRequest struct {
|
||||
Id string `uri:"id"` // 主键ID
|
||||
}
|
||||
|
||||
type menuActionResponse struct {
|
||||
HashID string `json:"hash_id"` // hashID
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
req := new(menuActionRequest)
|
||||
if err := ctx.ShouldBindURI(req); err != nil {
|
||||
ctx.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.ParamBindError,
|
||||
code.Text(code.ParamBindError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
obj := new(menuActionResponse)
|
||||
obj.HashID = req.Id
|
||||
|
||||
ctx.HTML("menu_action", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) ModifyInfo() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("admin_modify_info", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) ModifyPassword() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("admin_modify_password", nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package authorized
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
db db.Repo
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Add() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("authorized_add", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Demo() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("authorized_demo", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) List() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("authorized_list", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Api() core.HandlerFunc {
|
||||
type apiRequest struct {
|
||||
Id string `uri:"id"` // 主键ID
|
||||
}
|
||||
|
||||
type apiResponse struct {
|
||||
HashID string `json:"hash_id"` // hashID
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
req := new(apiRequest)
|
||||
if err := ctx.ShouldBindURI(req); err != nil {
|
||||
ctx.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.ParamBindError,
|
||||
code.Text(code.ParamBindError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
obj := new(apiResponse)
|
||||
obj.HashID = req.Id
|
||||
|
||||
ctx.HTML("authorized_api", obj)
|
||||
}
|
||||
}
|
||||
+36
-18
@@ -1,37 +1,55 @@
|
||||
package config_handler
|
||||
package config
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"log"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
"github.com/dave/dst"
|
||||
"github.com/dave/dst/decorator"
|
||||
"github.com/spf13/cast"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type codes struct {
|
||||
Code int `json:"code"` // 错误码
|
||||
Message string `json:"message"` // 错误码信息
|
||||
const minBusinessCode = 20000
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
type codeViewResponse struct {
|
||||
SystemCodes []codes
|
||||
BusinessCodes []codes
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
codeFile = "./internal/pkg/code/code.go"
|
||||
minBusinessCode = 20000
|
||||
)
|
||||
func (h *handler) Email() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("config_email", configs.Get())
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) CodeView() core.HandlerFunc {
|
||||
fs := token.NewFileSet()
|
||||
parsedFile, err := decorator.ParseFile(fs, codeFile, nil, 0)
|
||||
func (h *handler) Code() core.HandlerFunc {
|
||||
type codes struct {
|
||||
Code int `json:"code"` // 错误码
|
||||
Message string `json:"message"` // 错误码信息
|
||||
}
|
||||
|
||||
type codeViewResponse struct {
|
||||
SystemCodes []codes
|
||||
BusinessCodes []codes
|
||||
}
|
||||
|
||||
parsedFile, err := decorator.Parse(code.ByteCodeFile)
|
||||
if err != nil {
|
||||
log.Fatalf("parsing package: %s: %s\n", codeFile, err)
|
||||
log.Fatalf("parsing code.go: %s: %s\n", "ByteCodeFile", err)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -71,11 +89,11 @@ func (h *handler) CodeView() core.HandlerFunc {
|
||||
return true
|
||||
})
|
||||
|
||||
return func(c core.Context) {
|
||||
return func(ctx core.Context) {
|
||||
obj := new(codeViewResponse)
|
||||
obj.BusinessCodes = businessCodes
|
||||
obj.SystemCodes = systemCodes
|
||||
|
||||
c.HTML("config_code", obj)
|
||||
ctx.HTML("config_code", obj)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package cron
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
db db.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Add() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("cron_task_add", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Edit() core.HandlerFunc {
|
||||
type editRequest struct {
|
||||
Id string `uri:"id"` // 主键ID
|
||||
}
|
||||
|
||||
type editResponse struct {
|
||||
HashID string `json:"hash_id"` // hashID
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
req := new(editRequest)
|
||||
if err := ctx.ShouldBindURI(req); err != nil {
|
||||
ctx.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.ParamBindError,
|
||||
code.Text(code.ParamBindError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
obj := new(editResponse)
|
||||
obj.HashID = req.Id
|
||||
ctx.HTML("cron_task_edit", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) List() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("cron_task_list", nil)
|
||||
}
|
||||
}
|
||||
+67
-32
@@ -1,4 +1,4 @@
|
||||
package dashboard_handler
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,15 +9,32 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/env"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
db db.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
B = 1
|
||||
KB = 1024 * B
|
||||
@@ -25,36 +42,52 @@ const (
|
||||
GB = 1024 * MB
|
||||
)
|
||||
|
||||
type viewResponse struct {
|
||||
MemTotal string
|
||||
MemUsed string
|
||||
MemUsedPercent float64
|
||||
|
||||
DiskTotal string
|
||||
DiskUsed string
|
||||
DiskUsedPercent float64
|
||||
|
||||
HostOS string
|
||||
HostName string
|
||||
|
||||
CpuName string
|
||||
CpuCores int32
|
||||
CpuUsedPercent float64
|
||||
|
||||
GoPath string
|
||||
GoVersion string
|
||||
Goroutine int
|
||||
ProjectPath string
|
||||
Env string
|
||||
Host string
|
||||
GoOS string
|
||||
GoArch string
|
||||
|
||||
ProjectVersion string
|
||||
}
|
||||
|
||||
func (h *handler) View() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
type mysqlVersion struct {
|
||||
Ver string
|
||||
}
|
||||
|
||||
mysqlVer := new(mysqlVersion)
|
||||
if h.db != nil {
|
||||
h.db.GetDbR().Raw("SELECT version() as ver").Scan(mysqlVer)
|
||||
}
|
||||
|
||||
redisVer := ""
|
||||
if h.cache != nil {
|
||||
redisVer = h.cache.Version()
|
||||
}
|
||||
|
||||
type viewResponse struct {
|
||||
MemTotal string
|
||||
MemUsed string
|
||||
MemUsedPercent float64
|
||||
|
||||
DiskTotal string
|
||||
DiskUsed string
|
||||
DiskUsedPercent float64
|
||||
|
||||
HostOS string
|
||||
HostName string
|
||||
|
||||
CpuName string
|
||||
CpuCores int32
|
||||
CpuUsedPercent float64
|
||||
|
||||
GoPath string
|
||||
GoVersion string
|
||||
Goroutine int
|
||||
ProjectPath string
|
||||
Env string
|
||||
Host string
|
||||
GoOS string
|
||||
GoArch string
|
||||
|
||||
ProjectVersion string
|
||||
MySQLVersion string
|
||||
RedisVersion string
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
memInfo, _ := mem.VirtualMemory()
|
||||
diskInfo, _ := disk.Usage("/")
|
||||
hostInfo, _ := host.Info()
|
||||
@@ -87,12 +120,14 @@ func (h *handler) View() core.HandlerFunc {
|
||||
obj.Goroutine = runtime.NumGoroutine()
|
||||
dir, _ := os.Getwd()
|
||||
obj.ProjectPath = strings.Replace(dir, "\\", "/", -1)
|
||||
obj.Host = c.Host()
|
||||
obj.Host = ctx.Host()
|
||||
obj.Env = env.Active().Value()
|
||||
obj.GoOS = runtime.GOOS
|
||||
obj.GoArch = runtime.GOARCH
|
||||
obj.ProjectVersion = configs.ProjectVersion
|
||||
obj.MySQLVersion = mysqlVer.Ver
|
||||
obj.RedisVersion = redisVer
|
||||
|
||||
c.HTML("dashboard", obj)
|
||||
ctx.HTML("dashboard", obj)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package generator_handler
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
db db.Repo
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
db db.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Index() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("index", nil)
|
||||
}
|
||||
}
|
||||
+17
-22
@@ -1,4 +1,4 @@
|
||||
package install_handler
|
||||
package install
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -7,10 +7,9 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/web/controller/install_handler/mysql_table"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/env"
|
||||
"github.com/xinliangnote/go-gin-api/internal/proposal/tablesqls"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
|
||||
"github.com/go-redis/redis/v7"
|
||||
@@ -37,31 +36,31 @@ func (h *handler) Execute() core.HandlerFunc {
|
||||
|
||||
installTableList := map[string]map[string]string{
|
||||
"authorized": {
|
||||
"table_sql": mysql_table.CreateAuthorizedTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAuthorizedTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAuthorizedTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAuthorizedTableDataSql(),
|
||||
},
|
||||
"authorized_api": {
|
||||
"table_sql": mysql_table.CreateAuthorizedAPITableSql(),
|
||||
"table_data_sql": mysql_table.CreateAuthorizedAPITableDataSql(),
|
||||
"table_sql": tablesqls.CreateAuthorizedAPITableSql(),
|
||||
"table_data_sql": tablesqls.CreateAuthorizedAPITableDataSql(),
|
||||
},
|
||||
"admin": {
|
||||
"table_sql": mysql_table.CreateAdminTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAdminTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAdminTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAdminTableDataSql(),
|
||||
},
|
||||
"admin_menu": {
|
||||
"table_sql": mysql_table.CreateAdminMenuTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAdminMenuTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAdminMenuTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAdminMenuTableDataSql(),
|
||||
},
|
||||
"menu": {
|
||||
"table_sql": mysql_table.CreateMenuTableSql(),
|
||||
"table_data_sql": mysql_table.CreateMenuTableDataSql(),
|
||||
"table_sql": tablesqls.CreateMenuTableSql(),
|
||||
"table_data_sql": tablesqls.CreateMenuTableDataSql(),
|
||||
},
|
||||
"menu_action": {
|
||||
"table_sql": mysql_table.CreateMenuActionTableSql(),
|
||||
"table_data_sql": mysql_table.CreateMenuActionTableDataSql(),
|
||||
"table_sql": tablesqls.CreateMenuActionTableSql(),
|
||||
"table_data_sql": tablesqls.CreateMenuActionTableDataSql(),
|
||||
},
|
||||
"cron_task": {
|
||||
"table_sql": mysql_table.CreateCronTaskTableSql(),
|
||||
"table_sql": tablesqls.CreateCronTaskTableSql(),
|
||||
"table_data_sql": "",
|
||||
},
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func (h *handler) Execute() core.HandlerFunc {
|
||||
// region 验证 version
|
||||
versionStr := runtime.Version()
|
||||
version := cast.ToFloat32(versionStr[2:6])
|
||||
if version < 1.15 {
|
||||
if version < configs.MinGoVersion {
|
||||
ctx.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.GoVersionError,
|
||||
@@ -149,10 +148,6 @@ func (h *handler) Execute() core.HandlerFunc {
|
||||
// endregion
|
||||
|
||||
// region 写入配置文件
|
||||
viper.SetConfigName(env.Active().Value() + "_configs")
|
||||
viper.SetConfigType("toml")
|
||||
viper.AddConfigPath("./configs")
|
||||
|
||||
viper.Set("language.local", req.Language)
|
||||
|
||||
viper.Set("redis.addr", req.RedisAddr)
|
||||
@@ -0,0 +1,42 @@
|
||||
package install
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/file"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) View() core.HandlerFunc {
|
||||
type viewResponse struct {
|
||||
Config configs.Config
|
||||
MinGoVersion float64
|
||||
GoVersion string
|
||||
}
|
||||
|
||||
return func(ctx core.Context) {
|
||||
if _, ok := file.IsExists(configs.ProjectInstallMark); ok {
|
||||
ctx.Redirect(http.StatusTemporaryRedirect, "/")
|
||||
}
|
||||
|
||||
obj := new(viewResponse)
|
||||
obj.Config = configs.Get()
|
||||
obj.MinGoVersion = configs.MinGoVersion
|
||||
obj.GoVersion = runtime.Version()
|
||||
ctx.HTML("install_view", obj)
|
||||
}
|
||||
}
|
||||
+53
-16
@@ -1,32 +1,69 @@
|
||||
package tool_handler
|
||||
package tool
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/file"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type logsViewResponse struct {
|
||||
Logs []logData `json:"logs"`
|
||||
type handler struct {
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
type logData struct {
|
||||
Level string `json:"level"`
|
||||
Time string `json:"time"`
|
||||
Path string `json:"path"`
|
||||
HTTPCode int `json:"http_code"`
|
||||
Method string `json:"method"`
|
||||
Msg string `json:"msg"`
|
||||
TraceID string `json:"trace_id"`
|
||||
Content string `json:"content"`
|
||||
CostSeconds float64 `json:"cost_seconds"`
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) LogsView() core.HandlerFunc {
|
||||
func (h *handler) Cache() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("tool_cache", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Data() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("tool_data", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) HashIds() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("tool_hashids", configs.Get())
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Websocket() core.HandlerFunc {
|
||||
return func(ctx core.Context) {
|
||||
ctx.HTML("tool_websocket", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *handler) Log() core.HandlerFunc {
|
||||
type logData struct {
|
||||
Level string `json:"level"`
|
||||
Time string `json:"time"`
|
||||
Path string `json:"path"`
|
||||
HTTPCode int `json:"http_code"`
|
||||
Method string `json:"method"`
|
||||
Msg string `json:"msg"`
|
||||
TraceID string `json:"trace_id"`
|
||||
Content string `json:"content"`
|
||||
CostSeconds float64 `json:"cost_seconds"`
|
||||
}
|
||||
|
||||
type logsViewResponse struct {
|
||||
Logs []logData `json:"logs"`
|
||||
}
|
||||
|
||||
type logParseData struct {
|
||||
Level string `json:"level"`
|
||||
@@ -43,7 +80,7 @@ func (h *handler) LogsView() core.HandlerFunc {
|
||||
TraceID string `json:"trace_id"`
|
||||
}
|
||||
|
||||
return func(c core.Context) {
|
||||
return func(ctx core.Context) {
|
||||
readLineFromEnd, err := file.NewReadLineFromEnd(configs.ProjectAccessLogFile)
|
||||
if err != nil {
|
||||
h.logger.Error("NewReadLineFromEnd err", zap.Error(err))
|
||||
@@ -78,6 +115,6 @@ func (h *handler) LogsView() core.HandlerFunc {
|
||||
obj.Logs[i] = data
|
||||
}
|
||||
}
|
||||
c.HTML("tool_logs", obj)
|
||||
ctx.HTML("tool_logs", obj)
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,11 +1,11 @@
|
||||
package upgrade_handler
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/internal/web/controller/install_handler/mysql_table"
|
||||
"github.com/xinliangnote/go-gin-api/internal/proposal/tablesqls"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
)
|
||||
@@ -19,31 +19,31 @@ func (h *handler) UpgradeExecute() core.HandlerFunc {
|
||||
|
||||
upgradeTableList := map[string]map[string]string{
|
||||
"authorized": {
|
||||
"table_sql": mysql_table.CreateAuthorizedTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAuthorizedTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAuthorizedTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAuthorizedTableDataSql(),
|
||||
},
|
||||
"authorized_api": {
|
||||
"table_sql": mysql_table.CreateAuthorizedAPITableSql(),
|
||||
"table_data_sql": mysql_table.CreateAuthorizedAPITableDataSql(),
|
||||
"table_sql": tablesqls.CreateAuthorizedAPITableSql(),
|
||||
"table_data_sql": tablesqls.CreateAuthorizedAPITableDataSql(),
|
||||
},
|
||||
"admin": {
|
||||
"table_sql": mysql_table.CreateAdminTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAdminTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAdminTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAdminTableDataSql(),
|
||||
},
|
||||
"admin_menu": {
|
||||
"table_sql": mysql_table.CreateAdminMenuTableSql(),
|
||||
"table_data_sql": mysql_table.CreateAdminMenuTableDataSql(),
|
||||
"table_sql": tablesqls.CreateAdminMenuTableSql(),
|
||||
"table_data_sql": tablesqls.CreateAdminMenuTableDataSql(),
|
||||
},
|
||||
"menu": {
|
||||
"table_sql": mysql_table.CreateMenuTableSql(),
|
||||
"table_data_sql": mysql_table.CreateMenuTableDataSql(),
|
||||
"table_sql": tablesqls.CreateMenuTableSql(),
|
||||
"table_data_sql": tablesqls.CreateMenuTableDataSql(),
|
||||
},
|
||||
"menu_action": {
|
||||
"table_sql": mysql_table.CreateMenuActionTableSql(),
|
||||
"table_data_sql": mysql_table.CreateMenuActionTableDataSql(),
|
||||
"table_sql": tablesqls.CreateMenuActionTableSql(),
|
||||
"table_data_sql": tablesqls.CreateMenuActionTableDataSql(),
|
||||
},
|
||||
"cron_task": {
|
||||
"table_sql": mysql_table.CreateCronTaskTableSql(),
|
||||
"table_sql": tablesqls.CreateCronTaskTableSql(),
|
||||
"table_data_sql": "",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/db"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
db db.Repo
|
||||
logger *zap.Logger
|
||||
cache redis.Repo
|
||||
}
|
||||
|
||||
func New(logger *zap.Logger, db db.Repo, cache redis.Repo) *handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
cache: cache,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package upgrade_handler
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -17,7 +17,7 @@ type upgradeViewData struct {
|
||||
IsHave int32 `json:"is_have"` // 是否已存在 1=存在 -1=不存在
|
||||
}
|
||||
|
||||
var tableList = []string{"authorized", "authorized_api", "admin", "menu", "menu_action", "admin_menu"}
|
||||
var tableList = []string{"authorized", "authorized_api", "admin", "menu", "menu_action", "admin_menu", "cron_task"}
|
||||
|
||||
func (h *handler) UpgradeView() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
@@ -1,47 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/token"
|
||||
)
|
||||
|
||||
func (m *middleware) Jwt(ctx core.Context) (userId int64, userName string, err errno.Error) {
|
||||
auth := ctx.GetHeader("Authorization")
|
||||
if auth == "" {
|
||||
err = errno.NewError(
|
||||
http.StatusUnauthorized,
|
||||
code.AuthorizationError,
|
||||
code.Text(code.AuthorizationError)).WithErr(errors.New("Header 中缺少 Authorization 参数"))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
cfg := configs.Get().JWT
|
||||
claims, errParse := token.New(cfg.Secret).JwtParse(auth)
|
||||
if errParse != nil {
|
||||
err = errno.NewError(
|
||||
http.StatusUnauthorized,
|
||||
code.AuthorizationError,
|
||||
code.Text(code.AuthorizationError)).WithErr(errParse)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
userId = claims.UserID
|
||||
if userId <= 0 {
|
||||
err = errno.NewError(
|
||||
http.StatusUnauthorized,
|
||||
code.AuthorizationError,
|
||||
code.Text(code.AuthorizationError)).WithErr(errors.New("claims.UserID <= 0 "))
|
||||
|
||||
return
|
||||
}
|
||||
userName = claims.UserName
|
||||
return
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/service/admin_service"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
admin2 "github.com/xinliangnote/go-gin-api/internal/services/admin"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/urltable"
|
||||
@@ -44,7 +44,7 @@ func (m *middleware) RBAC() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
actionData, err := m.cache.Get(configs.RedisKeyPrefixLoginUser+token+":action", cache.WithTrace(c.Trace()))
|
||||
actionData, err := m.cache.Get(configs.RedisKeyPrefixLoginUser+token+":action", redis.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusUnauthorized,
|
||||
@@ -54,7 +54,7 @@ func (m *middleware) RBAC() core.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
var actions []admin_service.MyActionData
|
||||
var actions []admin2.MyActionData
|
||||
err = json.Unmarshal([]byte(actionData), &actions)
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/token"
|
||||
)
|
||||
|
||||
const reSubmitMark = "1"
|
||||
|
||||
func (m *middleware) Resubmit() core.HandlerFunc {
|
||||
return func(c core.Context) {
|
||||
cfg := configs.Get().URLToken
|
||||
|
||||
tokenString, err := token.New(cfg.Secret).UrlSign(c.Path(), c.Method(), c.RequestInputParams())
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.UrlSignError,
|
||||
code.Text(code.UrlSignError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
redisKey := configs.RedisKeyPrefixRequestID + tokenString
|
||||
if !m.cache.Exists(redisKey) {
|
||||
err = m.cache.Set(redisKey, reSubmitMark, time.Minute*cfg.ExpireDuration)
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.CacheSetError,
|
||||
code.Text(code.CacheSetError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
redisValue, err := m.cache.Get(redisKey, cache.WithTrace(c.Trace()))
|
||||
if err != nil {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.CacheGetError,
|
||||
code.Text(code.CacheGetError)).WithErr(err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if redisValue == reSubmitMark {
|
||||
c.AbortWithError(errno.NewError(
|
||||
http.StatusBadRequest,
|
||||
code.ResubmitError,
|
||||
code.Text(code.ResubmitError)).WithErr(errors.New("resubmit")),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xinliangnote/go-gin-api/configs"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/cache"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/api/repository/redis"
|
||||
"github.com/xinliangnote/go-gin-api/internal/code"
|
||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errno"
|
||||
"github.com/xinliangnote/go-gin-api/pkg/errors"
|
||||
@@ -32,7 +32,7 @@ func (m *middleware) Token(ctx core.Context) (userId int64, userName string, err
|
||||
return
|
||||
}
|
||||
|
||||
cacheData, cacheErr := m.cache.Get(configs.RedisKeyPrefixLoginUser+token, cache.WithTrace(ctx.Trace()))
|
||||
cacheData, cacheErr := m.cache.Get(configs.RedisKeyPrefixLoginUser+token, redis.WithTrace(ctx.Trace()))
|
||||
if cacheErr != nil {
|
||||
err = errno.NewError(
|
||||
http.StatusUnauthorized,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user