mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 03:33:53 +08:00
This commit is contained in:
@@ -4,7 +4,7 @@ import "github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
// AuthSummary 授权摘要
|
||||
type AuthSummary struct {
|
||||
Request
|
||||
RpcMsg
|
||||
}
|
||||
|
||||
// ResponseAuthSummary 响应授权摘要
|
||||
|
||||
@@ -2,32 +2,74 @@ package msgin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/encrypt"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
AppId string `json:"appID" v:"0" example:"d0bb93048bc5c9164cdee845dcb7f820" description:"应用ID"`
|
||||
TraceID string `json:"traceID" v:"0" example:"d0bb93048bc5c9164cdee845dcb7f820" description:"链路ID"`
|
||||
Timestamp int64 `json:"timestamp" example:"1640966400" description:"服务器时间戳"`
|
||||
Sign string `json:"sign" example:"d0bb93048bc5c9164cdee845dcb7f820" description:"签名"`
|
||||
type RpcMsg struct {
|
||||
AppId string `json:"appID" v:"0" example:"10001" description:"应用ID"`
|
||||
TraceID string `json:"traceID" v:"0" example:"d0bb93048bc5c9164cdee845dcb7f820" description:"链路ID"`
|
||||
Timestamp int64 `json:"timestamp" example:"1640966400" description:"服务器时间戳"`
|
||||
Sign string `json:"sign" example:"d0bb93048bc5c9164cdee845dcb7f820" description:"签名"`
|
||||
}
|
||||
|
||||
func (i *Request) SetSign(traceID, appId, secretKey string) {
|
||||
func (i *RpcMsg) SetSign(appId, secretKey string) *RpcMsg {
|
||||
i.AppId = appId
|
||||
i.TraceID = traceID
|
||||
i.Timestamp = gtime.Timestamp()
|
||||
i.Sign = i.GetSign(secretKey)
|
||||
return i
|
||||
}
|
||||
|
||||
func (i *Request) GetSign(secretKey string) string {
|
||||
return encrypt.Md5ToString(fmt.Sprintf("%s%s%s%s", i.AppId, i.TraceID, i.Timestamp, secretKey))
|
||||
func (i *RpcMsg) GetSign(secretKey string) string {
|
||||
return encrypt.Md5ToString(fmt.Sprintf("%v%v%v%v", i.AppId, i.TraceID, i.Timestamp, secretKey))
|
||||
}
|
||||
|
||||
func (i *RpcMsg) GetTraceID() string {
|
||||
return i.TraceID
|
||||
}
|
||||
|
||||
func (i *RpcMsg) SetTraceID(traceID string) {
|
||||
i.TraceID = traceID
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code" example:"0" description:"状态码"`
|
||||
Message string `json:"message,omitempty" example:"操作成功" description:"提示消息"`
|
||||
//Data interface{} `json:"data,omitempty" description:"数据集"`
|
||||
RpcMsg
|
||||
Code int `json:"code" example:"2000" description:"状态码"`
|
||||
Message string `json:"message,omitempty" example:"操作成功" description:"提示消息"`
|
||||
}
|
||||
|
||||
// PkgResponse 打包响应消息
|
||||
func (m *Response) PkgResponse() {
|
||||
m.SetCode()
|
||||
// ...
|
||||
}
|
||||
|
||||
// SetCode 设置状态码
|
||||
func (m *Response) SetCode(code ...int) {
|
||||
if len(code) > 0 {
|
||||
m.Code = code[0]
|
||||
return
|
||||
}
|
||||
|
||||
// 默认值,转为成功的状态码
|
||||
if m.Code == 0 {
|
||||
m.Code = consts.TCPMsgCodeSuccess
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetError 获取响应中的错误
|
||||
func (m *Response) GetError() (err error) {
|
||||
if m.Code != consts.TCPMsgCodeSuccess {
|
||||
if m.Message == "" {
|
||||
m.Message = "操作失败"
|
||||
}
|
||||
err = gerror.New(m.Message)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ServerHeartbeat 心跳
|
||||
@@ -41,9 +83,9 @@ type ResponseServerHeartbeat struct {
|
||||
|
||||
// ServerLogin 服务登录
|
||||
type ServerLogin struct {
|
||||
Request
|
||||
Group string
|
||||
Name string
|
||||
RpcMsg
|
||||
Group string `json:"group" description:"分组"`
|
||||
Name string `json:"name" description:"名称"`
|
||||
}
|
||||
|
||||
// ResponseServerLogin 响应服务登录
|
||||
@@ -53,6 +95,7 @@ type ResponseServerLogin struct {
|
||||
|
||||
// ServerOffline 服务离线
|
||||
type ServerOffline struct {
|
||||
RpcMsg
|
||||
}
|
||||
|
||||
// ResponseServerOffline 响应服务离线
|
||||
|
||||
49
server/internal/model/input/msgin/cron.go
Normal file
49
server/internal/model/input/msgin/cron.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package msgin
|
||||
|
||||
import (
|
||||
"hotgo/internal/model/input/sysin"
|
||||
)
|
||||
|
||||
// CronDelete 删除任务
|
||||
type CronDelete struct {
|
||||
RpcMsg
|
||||
sysin.CronDeleteInp
|
||||
}
|
||||
|
||||
type ResponseCronDelete struct {
|
||||
Response
|
||||
sysin.CronDeleteModel
|
||||
}
|
||||
|
||||
// CronEdit 编辑任务
|
||||
type CronEdit struct {
|
||||
RpcMsg
|
||||
sysin.CronEditInp
|
||||
}
|
||||
|
||||
type ResponseCronEdit struct {
|
||||
Response
|
||||
sysin.CronEditModel
|
||||
}
|
||||
|
||||
// CronStatus 修改任务状态
|
||||
type CronStatus struct {
|
||||
RpcMsg
|
||||
sysin.CronStatusInp
|
||||
}
|
||||
|
||||
type ResponseCronStatus struct {
|
||||
Response
|
||||
sysin.CronStatusModel
|
||||
}
|
||||
|
||||
// CronOnlineExec 在线执行
|
||||
type CronOnlineExec struct {
|
||||
RpcMsg
|
||||
sysin.OnlineExecInp
|
||||
}
|
||||
|
||||
type ResponseCronOnlineExec struct {
|
||||
Response
|
||||
sysin.OnlineExecModel
|
||||
}
|
||||
Reference in New Issue
Block a user