jwt 认证

This commit is contained in:
eson
2023-06-06 20:08:32 +08:00
parent ab9df9bc42
commit 48be41f64b
11 changed files with 192 additions and 44 deletions

View File

@@ -31,7 +31,8 @@ type RequestUserLogin struct {
}
type DataUserLogin struct {
Token string `json:"token"`
Token string `json:"token"` // 充值密码token
JwtToken string `json:"jwt_token"` // jwt 的Token
}
type DataUserBasicInfo struct {
@@ -74,9 +75,18 @@ type Response struct {
Data interface{} `json:"data"`
}
type ResponseJwt struct {
Code int `json:"code"`
Message string `json:"msg"`
Data interface{} `json:"data"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
}
type Auth struct {
AccessSecret string `json:"AccessSecret"`
AccessExpire int `json:"AccessExpire"`
AccessSecret string `json:"accessSecret"`
AccessExpire int64 `json:"accessExpire"`
RefreshAfter int64 `json:"refreshAfter"`
}
// Set 设置Response的Code和Message值
@@ -124,3 +134,49 @@ func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string,
resp.Data = data[0]
}
}
// Set 设置Response的Code和Message值
func (resp *ResponseJwt) Set(Code int, Message string) {
resp.Code = Code
resp.Message = Message
}
// Set 设置整个Response
func (resp *ResponseJwt) SetWithData(Code int, Message string, Data interface{}) {
resp.Code = Code
resp.Message = Message
resp.Data = Data
}
// SetMessage 设置Response的Message
func (resp *ResponseJwt) SetMessage(msg string) {
resp.Message = msg
}
// SetWithData 设置Data
func (resp *ResponseJwt) SetData(Data interface{}) {
resp.Data = Data
}
// SetWithData 设置Response的Code和Message值 带Data入参数
func (resp *ResponseJwt) SetCode(Code int) {
resp.Code = Code
}
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
func (resp *ResponseJwt) SetStatus(sr *basic.StatusResponse, data ...interface{}) {
resp.Code = sr.Code
resp.Message = sr.Message
if len(data) == 1 {
resp.Data = data[0]
}
}
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
func (resp *ResponseJwt) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) {
resp.Code = sr.Code
resp.Message = msg
if len(data) == 1 {
resp.Data = data[0]
}
}