Add go http client

This commit is contained in:
若海
2023-12-17 13:16:15 +08:00
parent ccf742aef8
commit 4d9808b584
19 changed files with 2792 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package midware
import (
"github.com/gin-gonic/gin"
)
func OutputHandle(c *gin.Context) {
c.Next()
// 输出错误信息
if err, exists := c.Get("Error"); exists {
c.AbortWithStatusJSON(exitCode(c, 400), newErrorMessage(err))
return
}
// 输出请求结果
msg := c.GetString("Message")
if res, exists := c.Get("Payload"); exists || msg != "" {
data := newPayload(res, msg, c.GetString("JwtToken"))
c.AbortWithStatusJSON(exitCode(c, 200), data)
return
}
// 输出HTML内容
if htm := c.GetString("HTML"); htm != "" {
c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, htm)
c.Abort()
return
}
// 捕获异常返回
c.AbortWithStatusJSON(500, newErrorMessage("内部错误"))
}