|
@@ -1,11 +1,14 @@
|
|
package webutils
|
|
package webutils
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "encoding/base64"
|
|
|
|
+ "encoding/json"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
ut "github.com/go-playground/universal-translator"
|
|
ut "github.com/go-playground/universal-translator"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
|
|
+ "gogs.daxia.dev/huanan/pkg.daxia.dev/encrypt"
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -57,7 +60,35 @@ func FailedResponse(c *gin.Context, msg string) {
|
|
Data: nil,
|
|
Data: nil,
|
|
})
|
|
})
|
|
|
|
|
|
- panic(kkerror.NewRespError("failed"))
|
|
|
|
|
|
+ panic(NewRespError("failed"))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FailedResponseEncrypt(c *gin.Context, msg string, encKey []byte) {
|
|
|
|
+ if c == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if encKey != nil {
|
|
|
|
+ respData, _ := json.Marshal(Response{
|
|
|
|
+ Code: CodeFailed,
|
|
|
|
+ Msg: msg,
|
|
|
|
+ Data: nil,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ encData, _ := encrypt.AesEncrypt(respData, encKey)
|
|
|
|
+ encDataStr := base64.StdEncoding.EncodeToString(encData)
|
|
|
|
+
|
|
|
|
+ c.Data(200, "application/json", []byte(encDataStr))
|
|
|
|
+ panic(NewRespError("failed"))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(http.StatusOK, &Response{
|
|
|
|
+ Code: CodeFailed,
|
|
|
|
+ Msg: msg,
|
|
|
|
+ Data: nil,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ panic(NewRespError("failed"))
|
|
}
|
|
}
|
|
|
|
|
|
func FailedResponseErr(c *gin.Context, err error) {
|
|
func FailedResponseErr(c *gin.Context, err error) {
|
|
@@ -76,7 +107,7 @@ func FailedResponseWithCode(c *gin.Context, code int, msg string) {
|
|
Data: nil,
|
|
Data: nil,
|
|
})
|
|
})
|
|
|
|
|
|
- panic(kkerror.NewRespError("failed"))
|
|
|
|
|
|
+ panic(NewRespError("failed"))
|
|
}
|
|
}
|
|
|
|
|
|
func SuccessResponse(c *gin.Context, data interface{}) {
|
|
func SuccessResponse(c *gin.Context, data interface{}) {
|
|
@@ -86,5 +117,29 @@ func SuccessResponse(c *gin.Context, data interface{}) {
|
|
Data: data,
|
|
Data: data,
|
|
})
|
|
})
|
|
|
|
|
|
- panic(kkerror.NewRespError("success"))
|
|
|
|
|
|
+ panic(NewRespError("success"))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func SuccessResponseEncrypt(c *gin.Context, data interface{}, encKey []byte) {
|
|
|
|
+ if encKey != nil {
|
|
|
|
+ respData, _ := json.Marshal(Response{
|
|
|
|
+ Code: CodeSuccess,
|
|
|
|
+ Msg: "",
|
|
|
|
+ Data: data,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ encData, _ := encrypt.AesEncrypt(respData, encKey)
|
|
|
|
+ encDataStr := base64.StdEncoding.EncodeToString(encData)
|
|
|
|
+
|
|
|
|
+ c.Data(200, "application/json", []byte(encDataStr))
|
|
|
|
+ panic(NewRespError("failed"))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.JSON(http.StatusOK, &Response{
|
|
|
|
+ Code: CodeSuccess,
|
|
|
|
+ Msg: "",
|
|
|
|
+ Data: data,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ panic(NewRespError("success"))
|
|
}
|
|
}
|