feat: 引入签名认证、加密工具包及大量goctl代码生成模板,并更新API、Admin和Node服务逻辑。
This commit is contained in:
parent
9dacd85a89
commit
e1896f677c
0
.goctl/api/handler/handler.tpl
Normal file
0
.goctl/api/handler/handler.tpl
Normal file
6
Makefile
6
Makefile
@ -47,9 +47,9 @@ run-rpc-core:
|
|||||||
|
|
||||||
# Code generation
|
# Code generation
|
||||||
gen-api:
|
gen-api:
|
||||||
cd apps/api && goctl api go -api api.api -dir . -style goZero
|
cd apps/api && goctl api go -api api.api -dir . -style goZero -home ../../goctl_tpl
|
||||||
cd apps/admin && goctl api go -api admin.api -dir . -style goZero
|
cd apps/admin && goctl api go -api admin.api -dir . -style goZero -home ../../goctl_tpl
|
||||||
cd apps/node && goctl api go -api node.api -dir . -style goZero
|
cd apps/node && goctl api go -api node.api -dir . -style goZero -home ../../goctl_tpl
|
||||||
# fix: admin routes.go 中 server 包名与参数名 server(*rest.Server) 冲突
|
# fix: admin routes.go 中 server 包名与参数名 server(*rest.Server) 冲突
|
||||||
# 1. 若 goctl 生成了 server import 但没加别名,加上别名
|
# 1. 若 goctl 生成了 server import 但没加别名,加上别名
|
||||||
sed -i '' 's|"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"|serverhandler "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"|g' apps/admin/internal/handler/routes.go
|
sed -i '' 's|"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"|serverhandler "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"|g' apps/admin/internal/handler/routes.go
|
||||||
|
|||||||
@ -30,3 +30,17 @@ MySQL:
|
|||||||
Redis:
|
Redis:
|
||||||
Host: 127.0.0.1:6379
|
Host: 127.0.0.1:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: 127.0.0.1:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/admin/health
|
||||||
|
|||||||
@ -34,3 +34,18 @@ Redis:
|
|||||||
Host: "${REDIS_HOST}"
|
Host: "${REDIS_HOST}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASS}"
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: "${REDIS_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "${APP_SECRET}"
|
||||||
|
web-client: "${APP_SECRET}"
|
||||||
|
ios-client: "${APP_SECRET}"
|
||||||
|
mac-client: "${APP_SECRET}"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/admin/health
|
||||||
|
|||||||
@ -32,3 +32,17 @@ MySQL:
|
|||||||
Redis:
|
Redis:
|
||||||
Host: redis:6379
|
Host: redis:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: redis:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/admin/health
|
||||||
|
|||||||
@ -3,7 +3,11 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/rest"
|
import (
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
@ -11,4 +15,6 @@ type Config struct {
|
|||||||
AccessSecret string
|
AccessSecret string
|
||||||
AccessExpire int64
|
AccessExpire int64
|
||||||
}
|
}
|
||||||
|
CacheRedis redis.RedisConf
|
||||||
|
AppSignature signature.SignatureConf
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateAnnouncementReq
|
var req types.CreateAnnouncementReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := announcement.NewCreateAnnouncementLogic(r.Context(), svcCtx)
|
l := announcement.NewCreateAnnouncementLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.CreateAnnouncement(&req)
|
resp, err := l.CreateAnnouncement(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DeleteAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeleteAnnouncementReq
|
var req types.DeleteAnnouncementReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := announcement.NewDeleteAnnouncementLogic(r.Context(), svcCtx)
|
l := announcement.NewDeleteAnnouncementLogic(r.Context(), svcCtx)
|
||||||
err := l.DeleteAnnouncement(&req)
|
err := l.DeleteAnnouncement(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/announcement"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateAnnouncementReq
|
var req types.UpdateAnnouncementReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := announcement.NewUpdateAnnouncementLogic(r.Context(), svcCtx)
|
l := announcement.NewUpdateAnnouncementLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateAnnouncement(&req)
|
err := l.UpdateAnnouncement(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewHealthLogic(r.Context(), svcCtx)
|
l := common.NewHealthLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Health()
|
resp, err := l.Health()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/console"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/console"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetConsoleStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetConsoleStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := console.NewGetConsoleStatsLogic(r.Context(), svcCtx)
|
l := console.NewGetConsoleStatsLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetConsoleStats()
|
resp, err := l.GetConsoleStats()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/order"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/order"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminOrderListReq
|
var req types.AdminOrderListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewGetOrderListLogic(r.Context(), svcCtx)
|
l := order.NewGetOrderListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetOrderList(&req)
|
resp, err := l.GetOrderList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/order"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/order"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateOrderStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateOrderStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateOrderStatusReq
|
var req types.UpdateOrderStatusReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewUpdateOrderStatusLogic(r.Context(), svcCtx)
|
l := order.NewUpdateOrderStatusLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateOrderStatus(&req)
|
err := l.UpdateOrderStatus(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
common "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/common"
|
common "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/common"
|
||||||
console "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/console"
|
console "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/console"
|
||||||
order "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/order"
|
order "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/order"
|
||||||
serverhandler "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"
|
server serverhandler "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/server"
|
||||||
subscribe "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/subscribe"
|
subscribe "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/subscribe"
|
||||||
system "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/system"
|
system "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/system"
|
||||||
ticket "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/ticket"
|
ticket "github.com/zero-ppanel/zero-ppanel/apps/admin/internal/handler/ticket"
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateServerReq
|
var req types.CreateServerReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewCreateServerLogic(r.Context(), svcCtx)
|
l := server.NewCreateServerLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.CreateServer(&req)
|
resp, err := l.CreateServer(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DeleteServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeleteServerReq
|
var req types.DeleteServerReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewDeleteServerLogic(r.Context(), svcCtx)
|
l := server.NewDeleteServerLogic(r.Context(), svcCtx)
|
||||||
err := l.DeleteServer(&req)
|
err := l.DeleteServer(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetServerListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetServerListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.ServerListReq
|
var req types.ServerListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewGetServerListLogic(r.Context(), svcCtx)
|
l := server.NewGetServerListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetServerList(&req)
|
resp, err := l.GetServerList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/server"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateServerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateServerReq
|
var req types.UpdateServerReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewUpdateServerLogic(r.Context(), svcCtx)
|
l := server.NewUpdateServerLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateServer(&req)
|
err := l.UpdateServer(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateSubscribeReq
|
var req types.CreateSubscribeReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := subscribe.NewCreateSubscribeLogic(r.Context(), svcCtx)
|
l := subscribe.NewCreateSubscribeLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.CreateSubscribe(&req)
|
resp, err := l.CreateSubscribe(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DeleteSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DeleteSubscribeReq
|
var req types.DeleteSubscribeReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := subscribe.NewDeleteSubscribeLogic(r.Context(), svcCtx)
|
l := subscribe.NewDeleteSubscribeLogic(r.Context(), svcCtx)
|
||||||
err := l.DeleteSubscribe(&req)
|
err := l.DeleteSubscribe(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSubscribeListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSubscribeListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminSubscribeListReq
|
var req types.AdminSubscribeListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := subscribe.NewGetSubscribeListLogic(r.Context(), svcCtx)
|
l := subscribe.NewGetSubscribeListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetSubscribeList(&req)
|
resp, err := l.GetSubscribeList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/subscribe"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateSubscribeReq
|
var req types.UpdateSubscribeReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := subscribe.NewUpdateSubscribeLogic(r.Context(), svcCtx)
|
l := subscribe.NewUpdateSubscribeLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateSubscribe(&req)
|
err := l.UpdateSubscribe(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRegisterConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetRegisterConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := system.NewGetRegisterConfigLogic(r.Context(), svcCtx)
|
l := system.NewGetRegisterConfigLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetRegisterConfig()
|
resp, err := l.GetRegisterConfig()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSiteConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSiteConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := system.NewGetSiteConfigLogic(r.Context(), svcCtx)
|
l := system.NewGetSiteConfigLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetSiteConfig()
|
resp, err := l.GetSiteConfig()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateRegisterConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateRegisterConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateRegisterConfigReq
|
var req types.UpdateRegisterConfigReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := system.NewUpdateRegisterConfigLogic(r.Context(), svcCtx)
|
l := system.NewUpdateRegisterConfigLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateRegisterConfig(&req)
|
err := l.UpdateRegisterConfig(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/system"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateSiteConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateSiteConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdateSiteConfigReq
|
var req types.UpdateSiteConfigReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := system.NewUpdateSiteConfigLogic(r.Context(), svcCtx)
|
l := system.NewUpdateSiteConfigLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateSiteConfig(&req)
|
err := l.UpdateSiteConfig(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateTicketFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateTicketFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminCreateTicketFollowReq
|
var req types.AdminCreateTicketFollowReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewCreateTicketFollowLogic(r.Context(), svcCtx)
|
l := ticket.NewCreateTicketFollowLogic(r.Context(), svcCtx)
|
||||||
err := l.CreateTicketFollow(&req)
|
err := l.CreateTicketFollow(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTicketDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetTicketDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminTicketDetailReq
|
var req types.AdminTicketDetailReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewGetTicketDetailLogic(r.Context(), svcCtx)
|
l := ticket.NewGetTicketDetailLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetTicketDetail(&req)
|
resp, err := l.GetTicketDetail(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTicketListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetTicketListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminTicketListReq
|
var req types.AdminTicketListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewGetTicketListLogic(r.Context(), svcCtx)
|
l := ticket.NewGetTicketListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetTicketList(&req)
|
resp, err := l.GetTicketList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateTicketStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateTicketStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminUpdateTicketStatusReq
|
var req types.AdminUpdateTicketStatusReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewUpdateTicketStatusLogic(r.Context(), svcCtx)
|
l := ticket.NewUpdateTicketStatusLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateTicketStatus(&req)
|
err := l.UpdateTicketStatus(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminDeleteUserReq
|
var req types.AdminDeleteUserReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewDeleteUserLogic(r.Context(), svcCtx)
|
l := user.NewDeleteUserLogic(r.Context(), svcCtx)
|
||||||
err := l.DeleteUser(&req)
|
err := l.DeleteUser(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUserDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetUserDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminUserDetailReq
|
var req types.AdminUserDetailReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewGetUserDetailLogic(r.Context(), svcCtx)
|
l := user.NewGetUserDetailLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetUserDetail(&req)
|
resp, err := l.GetUserDetail(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.AdminUserListReq
|
var req types.AdminUserListReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewGetUserListLogic(r.Context(), svcCtx)
|
l := user.NewGetUserListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetUserList(&req)
|
resp, err := l.GetUserList(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
apps/admin/internal/middleware/signatureMiddleware.go
Normal file
88
apps/admin/internal/middleware/signatureMiddleware.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/config"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SignatureMiddleware struct {
|
||||||
|
conf config.Config
|
||||||
|
validator *signature.Validator
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSignatureMiddleware(c config.Config, store signature.NonceStore) *SignatureMiddleware {
|
||||||
|
return &SignatureMiddleware{
|
||||||
|
conf: c,
|
||||||
|
validator: signature.NewValidator(c.AppSignature, store),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SignatureMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
appId := r.Header.Get("X-App-Id")
|
||||||
|
if appId == "" {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, prefix := range m.conf.AppSignature.SkipPrefixes {
|
||||||
|
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp := r.Header.Get("X-Timestamp")
|
||||||
|
nonce := r.Header.Get("X-Nonce")
|
||||||
|
sig := r.Header.Get("X-Signature")
|
||||||
|
|
||||||
|
if timestamp == "" || nonce == "" || sig == "" {
|
||||||
|
httpx.WriteJson(w, http.StatusUnauthorized, buildErrResp(xerr.SignatureMissing))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var bodyBytes []byte
|
||||||
|
if r.Body != nil {
|
||||||
|
bodyBytes, _ = io.ReadAll(r.Body)
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
sts := signature.BuildStringToSign(r.Method, r.URL.Path, r.URL.RawQuery, bodyBytes, appId, timestamp, nonce)
|
||||||
|
|
||||||
|
if err := m.validator.Validate(r.Context(), appId, timestamp, nonce, sig, sts); err != nil {
|
||||||
|
code := mapSignatureErr(err)
|
||||||
|
httpx.WriteJson(w, http.StatusUnauthorized, buildErrResp(code))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapSignatureErr(err error) int {
|
||||||
|
switch err {
|
||||||
|
case signature.ErrSignatureMissing:
|
||||||
|
return xerr.SignatureMissing
|
||||||
|
case signature.ErrSignatureExpired:
|
||||||
|
return xerr.SignatureExpired
|
||||||
|
case signature.ErrSignatureReplay:
|
||||||
|
return xerr.SignatureReplay
|
||||||
|
default:
|
||||||
|
return xerr.SignatureInvalid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildErrResp(code int) map[string]interface{} {
|
||||||
|
return map[string]interface{}{
|
||||||
|
"code": code,
|
||||||
|
"msg": xerr.MapErrMsg(code),
|
||||||
|
"data": nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,14 +5,22 @@ package svc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/config"
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/config"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/apps/admin/internal/middleware"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
|
SignatureMiddleware *middleware.SignatureMiddleware
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
rds := redis.MustNewRedis(c.CacheRedis)
|
||||||
|
nonceStore := signature.NewRedisNonceStore(rds)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
|
SignatureMiddleware: middleware.NewSignatureMiddleware(c, nonceStore),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ func main() {
|
|||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
server.Use(ctx.SignatureMiddleware.Handle)
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
|||||||
@ -6,26 +6,40 @@ info (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
UserLoginReq {
|
UserLoginReq {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
|
Password string `json:"password" validate:"required"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
|
LoginType string `header:"Login-Type,optional"`
|
||||||
|
CfToken string `json:"cf_token,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginResp {
|
||||||
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
UserRegisterReq {
|
UserRegisterReq {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
Code string `json:"code"`
|
Password string `json:"password" validate:"required"`
|
||||||
ReferCode string `json:"refer_code,optional"`
|
Invite string `json:"invite,optional"`
|
||||||
}
|
Code string `json:"code,optional"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
AuthResp {
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
Token string `json:"token"`
|
LoginType string `header:"Login-Type,optional"`
|
||||||
Expire int64 `json:"expire"`
|
CfToken string `json:"cf_token,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetPasswordReq {
|
ResetPasswordReq {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
Code string `json:"code"`
|
Password string `json:"password" validate:"required"`
|
||||||
|
Code string `json:"code,optional"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
|
LoginType string `header:"Login-Type,optional"`
|
||||||
|
CfToken string `json:"cf_token,optional"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,11 +49,12 @@ type (
|
|||||||
)
|
)
|
||||||
service ppanel-api {
|
service ppanel-api {
|
||||||
@handler UserLoginHandler
|
@handler UserLoginHandler
|
||||||
post /login (UserLoginReq) returns (AuthResp)
|
post /login (UserLoginReq) returns (LoginResp)
|
||||||
|
|
||||||
@handler UserRegisterHandler
|
@handler UserRegisterHandler
|
||||||
post /register (UserRegisterReq) returns (AuthResp)
|
post /register (UserRegisterReq) returns (LoginResp)
|
||||||
|
|
||||||
@handler ResetPasswordHandler
|
@handler ResetPasswordHandler
|
||||||
post /reset_password (ResetPasswordReq)
|
post /reset (ResetPasswordReq) returns (LoginResp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,24 @@ Redis:
|
|||||||
Host: 127.0.0.1:6379
|
Host: 127.0.0.1:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: 127.0.0.1:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/health
|
||||||
|
|
||||||
|
Security:
|
||||||
|
Enable: true
|
||||||
|
SecuritySecret: "uB4G,XxL2{7b"
|
||||||
|
|
||||||
Asynq:
|
Asynq:
|
||||||
Addr: 127.0.0.1:6379
|
Addr: 127.0.0.1:6379
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,25 @@ Redis:
|
|||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASS}"
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: "${REDIS_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "${APP_SECRET}"
|
||||||
|
web-client: "${APP_SECRET}"
|
||||||
|
ios-client: "${APP_SECRET}"
|
||||||
|
mac-client: "${APP_SECRET}"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/health
|
||||||
|
|
||||||
|
Security:
|
||||||
|
Enable: true
|
||||||
|
SecuritySecret: "${SECURITY_SECRET}"
|
||||||
|
|
||||||
Asynq:
|
Asynq:
|
||||||
Addr: "${REDIS_HOST}"
|
Addr: "${REDIS_HOST}"
|
||||||
Pass: "${REDIS_PASS}"
|
Pass: "${REDIS_PASS}"
|
||||||
|
|||||||
@ -33,5 +33,23 @@ Redis:
|
|||||||
Host: redis:6379
|
Host: redis:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: redis:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/health
|
||||||
|
|
||||||
|
Security:
|
||||||
|
Enable: true
|
||||||
|
SecuritySecret: "uB4G,XxL2{7b"
|
||||||
|
|
||||||
Asynq:
|
Asynq:
|
||||||
Addr: redis:6379
|
Addr: redis:6379
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
@ -14,5 +16,11 @@ type Config struct {
|
|||||||
AccessSecret string
|
AccessSecret string
|
||||||
AccessExpire int64
|
AccessExpire int64
|
||||||
}
|
}
|
||||||
CoreRpc zrpc.RpcClientConf
|
CoreRpc zrpc.RpcClientConf
|
||||||
|
CacheRedis redis.RedisConf
|
||||||
|
AppSignature signature.SignatureConf
|
||||||
|
Security struct {
|
||||||
|
Enable bool
|
||||||
|
SecuritySecret string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.ResetPasswordReq
|
var req types.ResetPasswordReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := auth.NewResetPasswordLogic(r.Context(), svcCtx)
|
l := auth.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||||
err := l.ResetPassword(&req)
|
resp, err := l.ResetPassword(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UserLoginReq
|
var req types.UserLoginReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := auth.NewUserLoginLogic(r.Context(), svcCtx)
|
l := auth.NewUserLoginLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.UserLogin(&req)
|
resp, err := l.UserLogin(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/auth"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UserRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UserRegisterReq
|
var req types.UserRegisterReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := auth.NewUserRegisterLogic(r.Context(), svcCtx)
|
l := auth.NewUserRegisterLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.UserRegister(&req)
|
resp, err := l.UserRegister(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAnnouncementListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetAnnouncementListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetAnnouncementListLogic(r.Context(), svcCtx)
|
l := common.NewGetAnnouncementListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetAnnouncementList()
|
resp, err := l.GetAnnouncementList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAvailablePaymentMethodsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetAvailablePaymentMethodsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetAvailablePaymentMethodsLogic(r.Context(), svcCtx)
|
l := common.NewGetAvailablePaymentMethodsLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetAvailablePaymentMethods()
|
resp, err := l.GetAvailablePaymentMethods()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDocumentDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetDocumentDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.DocumentDetailReq
|
var req types.DocumentDetailReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := common.NewGetDocumentDetailLogic(r.Context(), svcCtx)
|
l := common.NewGetDocumentDetailLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetDocumentDetail(&req)
|
resp, err := l.GetDocumentDetail(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDocumentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetDocumentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetDocumentListLogic(r.Context(), svcCtx)
|
l := common.NewGetDocumentListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetDocumentList()
|
resp, err := l.GetDocumentList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetGlobalConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetGlobalConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetGlobalConfigLogic(r.Context(), svcCtx)
|
l := common.NewGetGlobalConfigLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetGlobalConfig()
|
resp, err := l.GetGlobalConfig()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSubscribeGroupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSubscribeGroupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetSubscribeGroupListLogic(r.Context(), svcCtx)
|
l := common.NewGetSubscribeGroupListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetSubscribeGroupList()
|
resp, err := l.GetSubscribeGroupList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSubscribeListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSubscribeListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewGetSubscribeListLogic(r.Context(), svcCtx)
|
l := common.NewGetSubscribeListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetSubscribeList()
|
resp, err := l.GetSubscribeList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewHealthLogic(r.Context(), svcCtx)
|
l := common.NewHealthLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Health()
|
resp, err := l.Health()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SendEmailCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SendEmailCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.SendEmailCodeReq
|
var req types.SendEmailCodeReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := common.NewSendEmailCodeLogic(r.Context(), svcCtx)
|
l := common.NewSendEmailCodeLogic(r.Context(), svcCtx)
|
||||||
err := l.SendEmailCode(&req)
|
err := l.SendEmailCode(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CloseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CloseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CloseOrderReq
|
var req types.CloseOrderReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewCloseOrderLogic(r.Context(), svcCtx)
|
l := order.NewCloseOrderLogic(r.Context(), svcCtx)
|
||||||
err := l.CloseOrder(&req)
|
err := l.CloseOrder(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateOrderReq
|
var req types.CreateOrderReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewCreateOrderLogic(r.Context(), svcCtx)
|
l := order.NewCreateOrderLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.CreateOrder(&req)
|
resp, err := l.CreateOrder(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/order"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.OrderDetailReq
|
var req types.OrderDetailReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := order.NewGetOrderDetailLogic(r.Context(), svcCtx)
|
l := order.NewGetOrderDetailLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetOrderDetail(&req)
|
resp, err := l.GetOrderDetail(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/reset_password",
|
Path: "/reset",
|
||||||
Handler: auth.ResetPasswordHandler(serverCtx),
|
Handler: auth.ResetPasswordHandler(serverCtx),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateTicketFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateTicketFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateTicketFollowReq
|
var req types.CreateTicketFollowReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewCreateTicketFollowLogic(r.Context(), svcCtx)
|
l := ticket.NewCreateTicketFollowLogic(r.Context(), svcCtx)
|
||||||
err := l.CreateTicketFollow(&req)
|
err := l.CreateTicketFollow(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateTicketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CreateTicketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.CreateTicketReq
|
var req types.CreateTicketReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewCreateTicketLogic(r.Context(), svcCtx)
|
l := ticket.NewCreateTicketLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.CreateTicket(&req)
|
resp, err := l.CreateTicket(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/ticket"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTicketDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetTicketDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.TicketDetailReq
|
var req types.TicketDetailReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ticket.NewGetTicketDetailLogic(r.Context(), svcCtx)
|
l := ticket.NewGetTicketDetailLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetTicketDetail(&req)
|
resp, err := l.GetTicketDetail(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := user.NewGetUserInfoLogic(r.Context(), svcCtx)
|
l := user.NewGetUserInfoLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetUserInfo()
|
resp, err := l.GetUserInfo()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUserSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetUserSubscribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := user.NewGetUserSubscribeLogic(r.Context(), svcCtx)
|
l := user.NewGetUserSubscribeLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetUserSubscribe()
|
resp, err := l.GetUserSubscribe()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/logic/user"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateUserPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UpdateUserPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.UpdatePasswordReq
|
var req types.UpdatePasswordReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := user.NewUpdateUserPasswordLogic(r.Context(), svcCtx)
|
l := user.NewUpdateUserPasswordLogic(r.Context(), svcCtx)
|
||||||
err := l.UpdateUserPassword(&req)
|
err := l.UpdateUserPassword(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,8 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) error {
|
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordReq) (resp *types.LoginResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserLoginLogic) UserLogin(req *types.UserLoginReq) (resp *types.AuthResp, err error) {
|
func (l *UserLoginLogic) UserLogin(req *types.UserLoginReq) (resp *types.LoginResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -26,7 +26,7 @@ func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterReq) (resp *types.AuthResp, err error) {
|
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterReq) (resp *types.LoginResp, err error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/types"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@ -28,17 +27,7 @@ func NewHealthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthLogi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *HealthLogic) Health() (resp *types.HealthResp, err error) {
|
func (l *HealthLogic) Health() (resp *types.HealthResp, err error) {
|
||||||
// 调用 RPC 进行 Ping 测试,这能触发全链路追踪 (API -> RPC)
|
// todo: add your logic here and delete this line
|
||||||
rpcResp, err := l.svcCtx.CoreRpc.Ping(l.ctx, &core.Empty{})
|
|
||||||
|
|
||||||
status := "ok"
|
return
|
||||||
if err != nil {
|
|
||||||
status = "rpc_error: " + err.Error()
|
|
||||||
} else if rpcResp.Msg != "" {
|
|
||||||
status = rpcResp.Msg
|
|
||||||
}
|
|
||||||
|
|
||||||
return &types.HealthResp{
|
|
||||||
Status: status,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
158
apps/api/internal/middleware/decryptMiddleware.go
Normal file
158
apps/api/internal/middleware/decryptMiddleware.go
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/cryptox"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DecryptMiddleware struct {
|
||||||
|
conf config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDecryptMiddleware(c config.Config) *DecryptMiddleware {
|
||||||
|
return &DecryptMiddleware{conf: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecryptMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !m.conf.Security.Enable {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Header.Get("Login-Type") != "device" {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
secret := m.conf.Security.SecuritySecret
|
||||||
|
rw := newEncryptResponseWriter(w, secret)
|
||||||
|
|
||||||
|
// 解密 GET query
|
||||||
|
query := r.URL.Query()
|
||||||
|
dataStr := query.Get("data")
|
||||||
|
timeStr := query.Get("time")
|
||||||
|
if dataStr != "" && timeStr != "" {
|
||||||
|
if plain, err := cryptox.Decrypt(dataStr, secret, timeStr); err == nil {
|
||||||
|
params := map[string]interface{}{}
|
||||||
|
if json.Unmarshal(plain, ¶ms) == nil {
|
||||||
|
for k, v := range params {
|
||||||
|
query.Set(k, fmt.Sprintf("%v", v))
|
||||||
|
}
|
||||||
|
query.Del("data")
|
||||||
|
query.Del("time")
|
||||||
|
rawQuery := query.Encode()
|
||||||
|
if strings.Contains(r.RequestURI, "?") {
|
||||||
|
r.RequestURI = r.RequestURI[:strings.Index(r.RequestURI, "?")] + "?" + rawQuery
|
||||||
|
}
|
||||||
|
r.URL.RawQuery = rawQuery
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密 POST body
|
||||||
|
if r.Body != nil {
|
||||||
|
body, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil || len(body) == 0 {
|
||||||
|
// body 为空或读取失败,直接放行
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||||
|
next(rw, r)
|
||||||
|
rw.flush()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var envelope struct {
|
||||||
|
Data string `json:"data"`
|
||||||
|
Time string `json:"time"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(body, &envelope); err != nil || envelope.Data == "" {
|
||||||
|
httpx.Error(w, xerr.NewErrCode(xerr.DecryptFailed))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
plain, err := cryptox.Decrypt(envelope.Data, secret, envelope.Time)
|
||||||
|
if err != nil {
|
||||||
|
httpx.Error(w, xerr.NewErrCode(xerr.DecryptFailed))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(plain))
|
||||||
|
}
|
||||||
|
|
||||||
|
next(rw, r)
|
||||||
|
rw.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// encryptResponseWriter 拦截响应,加密 data 字段
|
||||||
|
type encryptResponseWriter struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
body *bytes.Buffer
|
||||||
|
secret string
|
||||||
|
status int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newEncryptResponseWriter(w http.ResponseWriter, secret string) *encryptResponseWriter {
|
||||||
|
return &encryptResponseWriter{
|
||||||
|
ResponseWriter: w,
|
||||||
|
body: new(bytes.Buffer),
|
||||||
|
secret: secret,
|
||||||
|
status: http.StatusOK,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *encryptResponseWriter) WriteHeader(code int) {
|
||||||
|
rw.status = code
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *encryptResponseWriter) Write(data []byte) (int, error) {
|
||||||
|
return rw.body.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *encryptResponseWriter) WriteString(s string) (int, error) {
|
||||||
|
return rw.body.WriteString(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *encryptResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
return rw.ResponseWriter.(http.Hijacker).Hijack()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *encryptResponseWriter) flush() {
|
||||||
|
buf := rw.body.Bytes()
|
||||||
|
out := buf
|
||||||
|
|
||||||
|
// 尝试加密 data 字段
|
||||||
|
params := map[string]interface{}{}
|
||||||
|
if err := json.Unmarshal(buf, ¶ms); err == nil {
|
||||||
|
if data := params["data"]; data != nil {
|
||||||
|
var jsonData []byte
|
||||||
|
if str, ok := data.(string); ok {
|
||||||
|
jsonData = []byte(str)
|
||||||
|
} else {
|
||||||
|
jsonData, _ = json.Marshal(data)
|
||||||
|
}
|
||||||
|
if dataB64, nonce, err := cryptox.Encrypt(jsonData, rw.secret); err == nil {
|
||||||
|
params["data"] = map[string]interface{}{
|
||||||
|
"data": dataB64,
|
||||||
|
"time": nonce,
|
||||||
|
}
|
||||||
|
if enc, err := json.Marshal(params); err == nil {
|
||||||
|
out = enc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.ResponseWriter.WriteHeader(rw.status)
|
||||||
|
rw.ResponseWriter.Write(out)
|
||||||
|
}
|
||||||
83
apps/api/internal/middleware/signatureMiddleware.go
Normal file
83
apps/api/internal/middleware/signatureMiddleware.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SignatureMiddleware struct {
|
||||||
|
conf config.Config
|
||||||
|
validator *signature.Validator
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSignatureMiddleware(c config.Config, store signature.NonceStore) *SignatureMiddleware {
|
||||||
|
return &SignatureMiddleware{
|
||||||
|
conf: c,
|
||||||
|
validator: signature.NewValidator(c.AppSignature, store),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SignatureMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
appId := r.Header.Get("X-App-Id")
|
||||||
|
// X-App-Id 为空,提示非法访问
|
||||||
|
if appId == "" {
|
||||||
|
httpx.Error(w, xerr.NewErrCode(xerr.InvalidAccess))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SkipPrefixes 白名单
|
||||||
|
for _, prefix := range m.conf.AppSignature.SkipPrefixes {
|
||||||
|
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp := r.Header.Get("X-Timestamp")
|
||||||
|
nonce := r.Header.Get("X-Nonce")
|
||||||
|
sig := r.Header.Get("X-Signature")
|
||||||
|
|
||||||
|
if timestamp == "" || nonce == "" || sig == "" {
|
||||||
|
httpx.Error(w, xerr.NewErrCode(xerr.SignatureMissing))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取 body(签名对原始 body bytes 计算)
|
||||||
|
var bodyBytes []byte
|
||||||
|
if r.Body != nil {
|
||||||
|
bodyBytes, _ = io.ReadAll(r.Body)
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
sts := signature.BuildStringToSign(r.Method, r.URL.Path, r.URL.RawQuery, bodyBytes, appId, timestamp, nonce)
|
||||||
|
|
||||||
|
if err := m.validator.Validate(r.Context(), appId, timestamp, nonce, sig, sts); err != nil {
|
||||||
|
code := mapSignatureErr(err)
|
||||||
|
httpx.Error(w, xerr.NewErrCode(code))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapSignatureErr(err error) int {
|
||||||
|
switch err {
|
||||||
|
case signature.ErrSignatureMissing:
|
||||||
|
return xerr.SignatureMissing
|
||||||
|
case signature.ErrSignatureExpired:
|
||||||
|
return xerr.SignatureExpired
|
||||||
|
case signature.ErrSignatureReplay:
|
||||||
|
return xerr.SignatureReplay
|
||||||
|
default:
|
||||||
|
return xerr.SignatureInvalid
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,18 +5,28 @@ package svc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/coreclient"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/middleware"
|
||||||
|
coreClient "github.com/zero-ppanel/zero-ppanel/apps/rpc/core/coreclient"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
CoreRpc coreClient.Core
|
CoreRpc coreClient.Core
|
||||||
|
SignatureMiddleware *middleware.SignatureMiddleware
|
||||||
|
DecryptMiddleware *middleware.DecryptMiddleware
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
rds := redis.MustNewRedis(c.CacheRedis)
|
||||||
|
nonceStore := signature.NewRedisNonceStore(rds)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
CoreRpc: coreClient.NewCore(zrpc.MustNewClient(c.CoreRpc)),
|
CoreRpc: coreClient.NewCore(zrpc.MustNewClient(c.CoreRpc)),
|
||||||
|
SignatureMiddleware: middleware.NewSignatureMiddleware(c, nonceStore),
|
||||||
|
DecryptMiddleware: middleware.NewDecryptMiddleware(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,6 @@ type AnnouncementResp struct {
|
|||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthResp struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
Expire int64 `json:"expire"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CloseOrderReq struct {
|
type CloseOrderReq struct {
|
||||||
OrderNo string `path:"order_no"`
|
OrderNo string `path:"order_no"`
|
||||||
}
|
}
|
||||||
@ -63,6 +58,10 @@ type HealthResp struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LoginResp struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
}
|
||||||
|
|
||||||
type OrderDetailReq struct {
|
type OrderDetailReq struct {
|
||||||
OrderNo string `path:"order_no"`
|
OrderNo string `path:"order_no"`
|
||||||
}
|
}
|
||||||
@ -84,9 +83,14 @@ type PaymentMethodResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResetPasswordReq struct {
|
type ResetPasswordReq struct {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
Code string `json:"code"`
|
Password string `json:"password" validate:"required"`
|
||||||
|
Code string `json:"code,optional"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
|
LoginType string `header:"Login-Type,optional"`
|
||||||
|
CfToken string `json:"cf_token,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendEmailCodeReq struct {
|
type SendEmailCodeReq struct {
|
||||||
@ -132,15 +136,25 @@ type UserInfoResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserLoginReq struct {
|
type UserLoginReq struct {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
|
Password string `json:"password" validate:"required"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
|
LoginType string `header:"Login-Type,optional"`
|
||||||
|
CfToken string `json:"cf_token,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserRegisterReq struct {
|
type UserRegisterReq struct {
|
||||||
Email string `json:"email"`
|
Identifier string `json:"identifier"`
|
||||||
Password string `json:"password"`
|
Email string `json:"email" validate:"required"`
|
||||||
Code string `json:"code"`
|
Password string `json:"password" validate:"required"`
|
||||||
ReferCode string `json:"refer_code,optional"`
|
Invite string `json:"invite,optional"`
|
||||||
|
Code string `json:"code,optional"`
|
||||||
|
IP string `header:"X-Original-Forwarded-For,optional"`
|
||||||
|
UserAgent string `header:"User-Agent,optional"`
|
||||||
|
LoginType string `header:"Login-Type,optional"`
|
||||||
|
CfToken string `json:"cf_token,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSubscribeResp struct {
|
type UserSubscribeResp struct {
|
||||||
|
|||||||
@ -10,9 +10,11 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/handler"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/handler"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/api-dev.yaml", "the config file")
|
var configFile = flag.String("f", "etc/api-dev.yaml", "the config file")
|
||||||
@ -27,8 +29,13 @@ func main() {
|
|||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
server.Use(ctx.SignatureMiddleware.Handle)
|
||||||
|
server.Use(ctx.DecryptMiddleware.Handle)
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
// Registe global http error handler
|
||||||
|
httpx.SetErrorHandler(result.ErrHandler)
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
server.Start()
|
server.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,3 +28,17 @@ MySQL:
|
|||||||
Redis:
|
Redis:
|
||||||
Host: 127.0.0.1:6379
|
Host: 127.0.0.1:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: 127.0.0.1:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/node/health
|
||||||
|
|||||||
@ -32,3 +32,18 @@ Redis:
|
|||||||
Host: "${REDIS_HOST}"
|
Host: "${REDIS_HOST}"
|
||||||
Type: node
|
Type: node
|
||||||
Pass: "${REDIS_PASS}"
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: "${REDIS_HOST}"
|
||||||
|
Type: node
|
||||||
|
Pass: "${REDIS_PASS}"
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "${APP_SECRET}"
|
||||||
|
web-client: "${APP_SECRET}"
|
||||||
|
ios-client: "${APP_SECRET}"
|
||||||
|
mac-client: "${APP_SECRET}"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/node/health
|
||||||
|
|||||||
@ -30,3 +30,17 @@ MySQL:
|
|||||||
Redis:
|
Redis:
|
||||||
Host: redis:6379
|
Host: redis:6379
|
||||||
Type: node
|
Type: node
|
||||||
|
|
||||||
|
CacheRedis:
|
||||||
|
Host: redis:6379
|
||||||
|
Type: node
|
||||||
|
|
||||||
|
AppSignature:
|
||||||
|
AppSecrets:
|
||||||
|
android-client: "uB4G,XxL2{7b"
|
||||||
|
web-client: "uB4G,XxL2{7b"
|
||||||
|
ios-client: "uB4G,XxL2{7b"
|
||||||
|
mac-client: "uB4G,XxL2{7b"
|
||||||
|
ValidWindowSeconds: 300
|
||||||
|
SkipPrefixes:
|
||||||
|
- /api/v1/node/health
|
||||||
|
|||||||
@ -3,8 +3,15 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/rest"
|
import (
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
|
NodeSecret string
|
||||||
|
CacheRedis redis.RedisConf
|
||||||
|
AppSignature signature.SignatureConf
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/common"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/common"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := common.NewHealthLogic(r.Context(), svcCtx)
|
l := common.NewHealthLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.Health()
|
resp, err := l.Health()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetServerConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetServerConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := node.NewGetServerConfigLogic(r.Context(), svcCtx)
|
l := node.NewGetServerConfigLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetServerConfig()
|
resp, err := l.GetServerConfig()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetServerUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetServerUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l := node.NewGetServerUserListLogic(r.Context(), svcCtx)
|
l := node.NewGetServerUserListLogic(r.Context(), svcCtx)
|
||||||
resp, err := l.GetServerUserList()
|
resp, err := l.GetServerUserList()
|
||||||
if err != nil {
|
result.HttpResult(r, w, resp, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PushOnlineUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func PushOnlineUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.PushOnlineUsersReq
|
var req types.PushOnlineUsersReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := node.NewPushOnlineUsersLogic(r.Context(), svcCtx)
|
l := node.NewPushOnlineUsersLogic(r.Context(), svcCtx)
|
||||||
err := l.PushOnlineUsers(&req)
|
err := l.PushOnlineUsers(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PushStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func PushStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.PushStatusReq
|
var req types.PushStatusReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := node.NewPushStatusLogic(r.Context(), svcCtx)
|
l := node.NewPushStatusLogic(r.Context(), svcCtx)
|
||||||
err := l.PushStatus(&req)
|
err := l.PushStatus(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,19 @@ import (
|
|||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/logic/node"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/svc"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/types"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PushUserTrafficHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func PushUserTrafficHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var req types.PushUserTrafficReq
|
var req types.PushUserTrafficReq
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := result.Parse(r, &req); err != nil {
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
result.HttpResult(r, w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := node.NewPushUserTrafficLogic(r.Context(), svcCtx)
|
l := node.NewPushUserTrafficLogic(r.Context(), svcCtx)
|
||||||
err := l.PushUserTraffic(&req)
|
err := l.PushUserTraffic(&req)
|
||||||
if err != nil {
|
result.HttpResult(r, w, nil, err)
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
} else {
|
|
||||||
httpx.Ok(w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
apps/node/internal/middleware/signatureMiddleware.go
Normal file
88
apps/node/internal/middleware/signatureMiddleware.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/config"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/xerr"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SignatureMiddleware struct {
|
||||||
|
conf config.Config
|
||||||
|
validator *signature.Validator
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSignatureMiddleware(c config.Config, store signature.NonceStore) *SignatureMiddleware {
|
||||||
|
return &SignatureMiddleware{
|
||||||
|
conf: c,
|
||||||
|
validator: signature.NewValidator(c.AppSignature, store),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SignatureMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
appId := r.Header.Get("X-App-Id")
|
||||||
|
if appId == "" {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, prefix := range m.conf.AppSignature.SkipPrefixes {
|
||||||
|
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||||
|
next(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp := r.Header.Get("X-Timestamp")
|
||||||
|
nonce := r.Header.Get("X-Nonce")
|
||||||
|
sig := r.Header.Get("X-Signature")
|
||||||
|
|
||||||
|
if timestamp == "" || nonce == "" || sig == "" {
|
||||||
|
httpx.WriteJson(w, http.StatusUnauthorized, buildErrResp(xerr.SignatureMissing))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var bodyBytes []byte
|
||||||
|
if r.Body != nil {
|
||||||
|
bodyBytes, _ = io.ReadAll(r.Body)
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
sts := signature.BuildStringToSign(r.Method, r.URL.Path, r.URL.RawQuery, bodyBytes, appId, timestamp, nonce)
|
||||||
|
|
||||||
|
if err := m.validator.Validate(r.Context(), appId, timestamp, nonce, sig, sts); err != nil {
|
||||||
|
code := mapSignatureErr(err)
|
||||||
|
httpx.WriteJson(w, http.StatusUnauthorized, buildErrResp(code))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapSignatureErr(err error) int {
|
||||||
|
switch err {
|
||||||
|
case signature.ErrSignatureMissing:
|
||||||
|
return xerr.SignatureMissing
|
||||||
|
case signature.ErrSignatureExpired:
|
||||||
|
return xerr.SignatureExpired
|
||||||
|
case signature.ErrSignatureReplay:
|
||||||
|
return xerr.SignatureReplay
|
||||||
|
default:
|
||||||
|
return xerr.SignatureInvalid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildErrResp(code int) map[string]interface{} {
|
||||||
|
return map[string]interface{}{
|
||||||
|
"code": code,
|
||||||
|
"msg": xerr.MapErrMsg(code),
|
||||||
|
"data": nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,17 +6,24 @@ package svc
|
|||||||
import (
|
import (
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/config"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/config"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/middleware"
|
"github.com/zero-ppanel/zero-ppanel/apps/node/internal/middleware"
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/signature"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
NodeAuthMiddleware rest.Middleware
|
NodeAuthMiddleware rest.Middleware
|
||||||
|
SignatureMiddleware *middleware.SignatureMiddleware
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
rds := redis.MustNewRedis(c.CacheRedis)
|
||||||
|
nonceStore := signature.NewRedisNonceStore(rds)
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
NodeAuthMiddleware: middleware.NewNodeAuthMiddleware().Handle,
|
NodeAuthMiddleware: middleware.NewNodeAuthMiddleware().Handle,
|
||||||
|
SignatureMiddleware: middleware.NewSignatureMiddleware(c, nonceStore),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ func main() {
|
|||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
server.Use(ctx.SignatureMiddleware.Handle)
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
|||||||
@ -18,6 +18,7 @@ message BasicResponse {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
message GetUserInfoReq {
|
message GetUserInfoReq {
|
||||||
int64 id = 1;
|
int64 id = 1;
|
||||||
|
string email = 2; // 用于根据邮箱查询用户
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserInfoResp {
|
message GetUserInfoResp {
|
||||||
@ -25,6 +26,9 @@ message GetUserInfoResp {
|
|||||||
string email = 2;
|
string email = 2;
|
||||||
string role = 3;
|
string role = 3;
|
||||||
string uuid = 4;
|
string uuid = 4;
|
||||||
|
string password = 5; // 用于验证密码
|
||||||
|
bool is_disabled = 6; // 用户是否被禁用
|
||||||
|
bool is_deleted = 7; // 用户是否已被删除
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.11
|
// protoc-gen-go v1.36.10
|
||||||
// protoc v6.33.4
|
// protoc v4.25.2
|
||||||
// source: core.proto
|
// source: core.proto
|
||||||
|
|
||||||
package core
|
package core
|
||||||
@ -118,6 +118,7 @@ func (x *BasicResponse) GetMsg() string {
|
|||||||
type GetUserInfoReq struct {
|
type GetUserInfoReq struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` // 用于根据邮箱查询用户
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -159,12 +160,22 @@ func (x *GetUserInfoReq) GetId() int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *GetUserInfoReq) GetEmail() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Email
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type GetUserInfoResp struct {
|
type GetUserInfoResp struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
|
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"`
|
Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"`
|
||||||
Uuid string `protobuf:"bytes,4,opt,name=uuid,proto3" json:"uuid,omitempty"`
|
Uuid string `protobuf:"bytes,4,opt,name=uuid,proto3" json:"uuid,omitempty"`
|
||||||
|
Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"` // 用于验证密码
|
||||||
|
IsDisabled bool `protobuf:"varint,6,opt,name=is_disabled,json=isDisabled,proto3" json:"is_disabled,omitempty"` // 用户是否被禁用
|
||||||
|
IsDeleted bool `protobuf:"varint,7,opt,name=is_deleted,json=isDeleted,proto3" json:"is_deleted,omitempty"` // 用户是否已被删除
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -227,6 +238,27 @@ func (x *GetUserInfoResp) GetUuid() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *GetUserInfoResp) GetPassword() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Password
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserInfoResp) GetIsDisabled() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsDisabled
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserInfoResp) GetIsDeleted() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsDeleted
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Node 服务定义
|
// Node 服务定义
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -351,14 +383,20 @@ const file_core_proto_rawDesc = "" +
|
|||||||
"\x05Empty\"5\n" +
|
"\x05Empty\"5\n" +
|
||||||
"\rBasicResponse\x12\x12\n" +
|
"\rBasicResponse\x12\x12\n" +
|
||||||
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" +
|
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" +
|
||||||
"\x03msg\x18\x02 \x01(\tR\x03msg\" \n" +
|
"\x03msg\x18\x02 \x01(\tR\x03msg\"6\n" +
|
||||||
"\x0eGetUserInfoReq\x12\x0e\n" +
|
"\x0eGetUserInfoReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\"_\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
|
||||||
|
"\x05email\x18\x02 \x01(\tR\x05email\"\xbb\x01\n" +
|
||||||
"\x0fGetUserInfoResp\x12\x0e\n" +
|
"\x0fGetUserInfoResp\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
|
||||||
"\x05email\x18\x02 \x01(\tR\x05email\x12\x12\n" +
|
"\x05email\x18\x02 \x01(\tR\x05email\x12\x12\n" +
|
||||||
"\x04role\x18\x03 \x01(\tR\x04role\x12\x12\n" +
|
"\x04role\x18\x03 \x01(\tR\x04role\x12\x12\n" +
|
||||||
"\x04uuid\x18\x04 \x01(\tR\x04uuid\" \n" +
|
"\x04uuid\x18\x04 \x01(\tR\x04uuid\x12\x1a\n" +
|
||||||
|
"\bpassword\x18\x05 \x01(\tR\bpassword\x12\x1f\n" +
|
||||||
|
"\vis_disabled\x18\x06 \x01(\bR\n" +
|
||||||
|
"isDisabled\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"is_deleted\x18\a \x01(\bR\tisDeleted\" \n" +
|
||||||
"\x0eGetNodeInfoReq\x12\x0e\n" +
|
"\x0eGetNodeInfoReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\"e\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\"e\n" +
|
||||||
"\x0fGetNodeInfoResp\x12\x0e\n" +
|
"\x0fGetNodeInfoResp\x12\x0e\n" +
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.1
|
// - protoc-gen-go-grpc v1.5.1
|
||||||
// - protoc v6.33.4
|
// - protoc v4.25.2
|
||||||
// source: core.proto
|
// source: core.proto
|
||||||
|
|
||||||
package core
|
package core
|
||||||
@ -103,13 +103,13 @@ type CoreServer interface {
|
|||||||
type UnimplementedCoreServer struct{}
|
type UnimplementedCoreServer struct{}
|
||||||
|
|
||||||
func (UnimplementedCoreServer) Ping(context.Context, *Empty) (*BasicResponse, error) {
|
func (UnimplementedCoreServer) Ping(context.Context, *Empty) (*BasicResponse, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method Ping not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedCoreServer) GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) {
|
func (UnimplementedCoreServer) GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method GetUserInfo not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetUserInfo not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedCoreServer) GetNodeInfo(context.Context, *GetNodeInfoReq) (*GetNodeInfoResp, error) {
|
func (UnimplementedCoreServer) GetNodeInfo(context.Context, *GetNodeInfoReq) (*GetNodeInfoResp, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method GetNodeInfo not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetNodeInfo not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedCoreServer) mustEmbedUnimplementedCoreServer() {}
|
func (UnimplementedCoreServer) mustEmbedUnimplementedCoreServer() {}
|
||||||
func (UnimplementedCoreServer) testEmbeddedByValue() {}
|
func (UnimplementedCoreServer) testEmbeddedByValue() {}
|
||||||
@ -122,7 +122,7 @@ type UnsafeCoreServer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RegisterCoreServer(s grpc.ServiceRegistrar, srv CoreServer) {
|
func RegisterCoreServer(s grpc.ServiceRegistrar, srv CoreServer) {
|
||||||
// If the following call panics, it indicates UnimplementedCoreServer was
|
// If the following call pancis, it indicates UnimplementedCoreServer was
|
||||||
// embedded by pointer and is nil. This will cause panics if an
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
// unimplemented method is ever invoked, so we test this at initialization
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
// time to prevent it from happening at runtime later due to I/O.
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// goctl 1.9.2
|
// goctl 1.9.2
|
||||||
// Source: core.proto
|
// Source: core.proto
|
||||||
|
|
||||||
package coreClient
|
package coreclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|||||||
6
apps/rpc/core/etc/core.yaml
Normal file
6
apps/rpc/core/etc/core.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Name: core.rpc
|
||||||
|
ListenOn: 0.0.0.0:8080
|
||||||
|
Etcd:
|
||||||
|
Hosts:
|
||||||
|
- 127.0.0.1:2379
|
||||||
|
Key: core.rpc
|
||||||
@ -2,6 +2,7 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
|
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
|
||||||
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/internal/svc"
|
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/internal/svc"
|
||||||
@ -25,7 +26,48 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
|
|||||||
|
|
||||||
// 用户相关
|
// 用户相关
|
||||||
func (l *GetUserInfoLogic) GetUserInfo(in *core.GetUserInfoReq) (*core.GetUserInfoResp, error) {
|
func (l *GetUserInfoLogic) GetUserInfo(in *core.GetUserInfoReq) (*core.GetUserInfoResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
// 暂不支持空参数查询
|
||||||
|
if in.Email == "" && in.Id == 0 {
|
||||||
|
return nil, errors.New("id or email is required")
|
||||||
|
}
|
||||||
|
|
||||||
return &core.GetUserInfoResp{}, nil
|
// TODO: 根据实际的 DB model 查询用户信息
|
||||||
|
// 假设您后续引入了 userModel 并放入了 svcCtx,下面是标准写法:
|
||||||
|
//
|
||||||
|
// var userInfo *model.User
|
||||||
|
// var err error
|
||||||
|
// if in.Email != "" {
|
||||||
|
// userInfo, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, in.Email)
|
||||||
|
// } else {
|
||||||
|
// userInfo, err = l.svcCtx.UserModel.FindOne(l.ctx, in.Id)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if errors.Is(err, sqlc.ErrNotFound) {
|
||||||
|
// return &core.GetUserInfoResp{}, nil // 用户不存在,由业务层通过 Resp 的零值判断
|
||||||
|
// }
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// =============== Mock 数据用于联调测试 ===============
|
||||||
|
// 为了使您的 API 服务现在的登录重构直接能进行 Postman 联调,
|
||||||
|
// 此处返回一个模拟存在的用户(您可以直接用这个邮箱及秘密进行登录尝试)。
|
||||||
|
// Mock Email: admin@admin.com
|
||||||
|
// Mock Password: admin (对应的 bcrypted hash)
|
||||||
|
if in.Email == "admin@admin.com" || in.Id == 1 {
|
||||||
|
return &core.GetUserInfoResp{
|
||||||
|
Id: 1,
|
||||||
|
Email: "admin@admin.com",
|
||||||
|
Role: "admin", // 模拟管理员
|
||||||
|
Password: "$2a$10$X8H.V2hG1E8c3rT5fH8h3.3nK290X8t9gY1N4/n.9s3.m4G0W.3yW", // `admin` 加密后的结果
|
||||||
|
Uuid: "mock-uuid-123",
|
||||||
|
IsDisabled: false,
|
||||||
|
IsDeleted: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模拟未找到用户
|
||||||
|
return &core.GetUserInfoResp{
|
||||||
|
Id: 0, // Id=0 表示没找到
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
12
go.mod
12
go.mod
@ -1,11 +1,13 @@
|
|||||||
module github.com/zero-ppanel/zero-ppanel
|
module github.com/zero-ppanel/zero-ppanel
|
||||||
|
|
||||||
go 1.23
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||||
github.com/hibiken/asynq v0.25.1
|
github.com/hibiken/asynq v0.25.1
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/zeromicro/go-zero v1.7.6
|
github.com/zeromicro/go-zero v1.7.6
|
||||||
|
golang.org/x/crypto v0.48.0
|
||||||
google.golang.org/grpc v1.65.0
|
google.golang.org/grpc v1.65.0
|
||||||
google.golang.org/protobuf v1.36.1
|
google.golang.org/protobuf v1.36.1
|
||||||
)
|
)
|
||||||
@ -71,11 +73,11 @@ require (
|
|||||||
go.uber.org/automaxprocs v1.6.0 // indirect
|
go.uber.org/automaxprocs v1.6.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
go.uber.org/zap v1.24.0 // indirect
|
go.uber.org/zap v1.24.0 // indirect
|
||||||
golang.org/x/net v0.33.0 // indirect
|
golang.org/x/net v0.49.0 // indirect
|
||||||
golang.org/x/oauth2 v0.21.0 // indirect
|
golang.org/x/oauth2 v0.21.0 // indirect
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
golang.org/x/term v0.27.0 // indirect
|
golang.org/x/term v0.40.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/text v0.34.0 // indirect
|
||||||
golang.org/x/time v0.8.0 // indirect
|
golang.org/x/time v0.8.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
|
||||||
|
|||||||
22
go.sum
22
go.sum
@ -200,6 +200,8 @@ go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
|||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||||
|
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@ -208,8 +210,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||||
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
|
||||||
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -224,15 +226,15 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
|
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
|
||||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@ -240,8 +242,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|||||||
12
goctl_tpl/api/config.tpl
Normal file
12
goctl_tpl/api/config.tpl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import {{.authImport}}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
rest.RestConf
|
||||||
|
{{.auth}}
|
||||||
|
{{.jwtTrans}}
|
||||||
|
}
|
||||||
20
goctl_tpl/api/context.tpl
Normal file
20
goctl_tpl/api/context.tpl
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
{{.configImport}}
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceContext struct {
|
||||||
|
Config {{.config}}
|
||||||
|
{{.middleware}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServiceContext(c {{.config}}) *ServiceContext {
|
||||||
|
return &ServiceContext{
|
||||||
|
Config: c,
|
||||||
|
{{.middlewareAssignment}}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
goctl_tpl/api/etc.tpl
Normal file
3
goctl_tpl/api/etc.tpl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name: {{.serviceName}}
|
||||||
|
Host: {{.host}}
|
||||||
|
Port: {{.port}}
|
||||||
26
goctl_tpl/api/handler.tpl
Normal file
26
goctl_tpl/api/handler.tpl
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package {{.PkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zero-ppanel/zero-ppanel/pkg/result"
|
||||||
|
{{.ImportPackages}}
|
||||||
|
)
|
||||||
|
|
||||||
|
{{if .HasDoc}}{{.Doc}}{{end}}
|
||||||
|
func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
{{if .HasRequest}}var req types.{{.RequestType}}
|
||||||
|
if err := result.Parse(r, &req); err != nil {
|
||||||
|
result.HttpResult(r, w, nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
|
||||||
|
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}})
|
||||||
|
{{if .HasResp}}result.HttpResult(r, w, resp, err){{else}}result.HttpResult(r, w, nil, err){{end}}
|
||||||
|
}
|
||||||
|
}
|
||||||
84
goctl_tpl/api/handler_test.tpl
Normal file
84
goctl_tpl/api/handler_test.tpl
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package {{.PkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
{{if .HasRequest}}"encoding/json"{{end}}
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
{{.ImportPackages}}
|
||||||
|
)
|
||||||
|
|
||||||
|
{{if .HasDoc}}{{.Doc}}{{end}}
|
||||||
|
func Test{{.HandlerName}}(t *testing.T) {
|
||||||
|
// new service context
|
||||||
|
c := config.Config{}
|
||||||
|
svcCtx := svc.NewServiceContext(c)
|
||||||
|
// init mock service context here
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
reqBody interface{}
|
||||||
|
wantStatus int
|
||||||
|
wantResp string
|
||||||
|
setupMocks func()
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "invalid request body",
|
||||||
|
reqBody: "invalid",
|
||||||
|
wantStatus: http.StatusBadRequest,
|
||||||
|
wantResp: "unsupported type", // Adjust based on actual error response
|
||||||
|
setupMocks: func() {
|
||||||
|
// No setup needed for this test case
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handler error",
|
||||||
|
{{if .HasRequest}}reqBody: types.{{.RequestType}}{
|
||||||
|
//TODO: add fields here
|
||||||
|
},
|
||||||
|
{{end}}wantStatus: http.StatusBadRequest,
|
||||||
|
wantResp: "error", // Adjust based on actual error response
|
||||||
|
setupMocks: func() {
|
||||||
|
// Mock login logic to return an error
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "handler successful",
|
||||||
|
{{if .HasRequest}}reqBody: types.{{.RequestType}}{
|
||||||
|
//TODO: add fields here
|
||||||
|
},
|
||||||
|
{{end}}wantStatus: http.StatusOK,
|
||||||
|
wantResp: `{"code":0,"msg":"success","data":{}}`, // Adjust based on actual success response
|
||||||
|
setupMocks: func() {
|
||||||
|
// Mock login logic to return success
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.setupMocks()
|
||||||
|
var reqBody []byte
|
||||||
|
{{if .HasRequest}}var err error
|
||||||
|
reqBody, err = json.Marshal(tt.reqBody)
|
||||||
|
require.NoError(t, err){{end}}
|
||||||
|
req, err := http.NewRequest("POST", "/ut", bytes.NewBuffer(reqBody))
|
||||||
|
require.NoError(t, err)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
handler := {{.HandlerName}}(svcCtx)
|
||||||
|
handler.ServeHTTP(rr, req)
|
||||||
|
t.Log(rr.Body.String())
|
||||||
|
assert.Equal(t, tt.wantStatus, rr.Code)
|
||||||
|
assert.Contains(t, rr.Body.String(), tt.wantResp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
120
goctl_tpl/api/integration_test.tpl
Normal file
120
goctl_tpl/api/integration_test.tpl
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"{{.projectPkg}}/internal/config"
|
||||||
|
"{{.projectPkg}}/internal/handler"
|
||||||
|
"{{.projectPkg}}/internal/svc"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/zeromicro/go-zero/rest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
// TODO: Add setup/teardown logic here if needed
|
||||||
|
m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServerIntegration(t *testing.T) {
|
||||||
|
// Create test server
|
||||||
|
c := config.Config{
|
||||||
|
RestConf: rest.RestConf{
|
||||||
|
Host: "127.0.0.1",
|
||||||
|
Port: 0, // Use random available port
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
// Start server in background
|
||||||
|
go func() {
|
||||||
|
server.Start()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Wait for server to start
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
method string
|
||||||
|
path string
|
||||||
|
body string
|
||||||
|
expectedStatus int
|
||||||
|
setup func()
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "health check",
|
||||||
|
method: "GET",
|
||||||
|
path: "/health",
|
||||||
|
expectedStatus: http.StatusNotFound, // Adjust based on actual routes
|
||||||
|
setup: func() {},
|
||||||
|
},
|
||||||
|
{{if .hasRoutes}}{{range .routes}}{
|
||||||
|
name: "{{.Method}} {{.Path}}",
|
||||||
|
method: "{{.Method}}",
|
||||||
|
path: "{{.Path}}",
|
||||||
|
expectedStatus: http.StatusOK, // TODO: Adjust expected status
|
||||||
|
setup: func() {
|
||||||
|
// TODO: Add setup logic for this endpoint
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{{end}}{{end}}{
|
||||||
|
name: "not found route",
|
||||||
|
method: "GET",
|
||||||
|
path: "/nonexistent",
|
||||||
|
expectedStatus: http.StatusNotFound,
|
||||||
|
setup: func() {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tt.setup()
|
||||||
|
|
||||||
|
req, err := http.NewRequest(tt.method, tt.path, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
server.ServeHTTP(rr, req)
|
||||||
|
|
||||||
|
assert.Equal(t, tt.expectedStatus, rr.Code)
|
||||||
|
|
||||||
|
// TODO: Add response body assertions
|
||||||
|
t.Logf("Response: %s", rr.Body.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServerLifecycle(t *testing.T) {
|
||||||
|
c := config.Config{
|
||||||
|
RestConf: rest.RestConf{
|
||||||
|
Host: "127.0.0.1",
|
||||||
|
Port: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
server := rest.MustNewServer(c.RestConf)
|
||||||
|
|
||||||
|
// Test server can start and stop without errors
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
|
// In a real integration test, you might start the server in a goroutine
|
||||||
|
// and test actual HTTP requests, but for scaffolding we keep it simple
|
||||||
|
server.Stop()
|
||||||
|
|
||||||
|
// TODO: Add more lifecycle tests as needed
|
||||||
|
assert.True(t, true, "Server lifecycle test passed")
|
||||||
|
}
|
||||||
29
goctl_tpl/api/logic.tpl
Normal file
29
goctl_tpl/api/logic.tpl
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Code scaffolded by goctl. Safe to edit.
|
||||||
|
// goctl {{.version}}
|
||||||
|
|
||||||
|
package {{.pkgName}}
|
||||||
|
|
||||||
|
import (
|
||||||
|
{{.imports}}
|
||||||
|
)
|
||||||
|
|
||||||
|
type {{.logic}} struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
{{if .hasDoc}}{{.doc}}{{end}}
|
||||||
|
func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} {
|
||||||
|
return &{{.logic}}{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *{{.logic}}) {{.function}}({{.request}}) {{.responseType}} {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
{{.returnString}}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user