|
@@ -5,8 +5,10 @@ import (
|
|
|
"eta/eta_mini_api/models"
|
|
|
"eta/eta_mini_api/services"
|
|
|
"eta/eta_mini_api/utils"
|
|
|
+ "fmt"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/beego/beego/v2/server/web"
|
|
|
)
|
|
@@ -65,7 +67,8 @@ func (c *BaseCommonController) JSON(data interface{}, hasIndent bool, coding boo
|
|
|
}
|
|
|
ip := c.Ctx.Input.IP()
|
|
|
requestBody, _ := url.QueryUnescape(string(c.Ctx.Input.RequestBody))
|
|
|
- utils.ApiLog.Info("请求地址:", c.Ctx.Input.URI(), "Authorization:", c.Ctx.Input.Header("Authorization"), "RequestBody:", requestBody, "ResponseBody", string(content), "IP:", ip)
|
|
|
+
|
|
|
+ c.logUri(content, requestBody, ip)
|
|
|
|
|
|
if coding {
|
|
|
content = []byte(utils.StringsToJSON(string(content)))
|
|
@@ -80,3 +83,44 @@ func (c *BaseCommonController) JSON(data interface{}, hasIndent bool, coding boo
|
|
|
|
|
|
return c.Ctx.Output.Body(content)
|
|
|
}
|
|
|
+
|
|
|
+func (c *BaseCommonController) logUri(respContent []byte, requestBody, ip string) {
|
|
|
+ authorization := ""
|
|
|
+ method := c.Ctx.Input.Method()
|
|
|
+ uri := c.Ctx.Input.URI()
|
|
|
+ if method != "HEAD" {
|
|
|
+ if method == "POST" || method == "GET" {
|
|
|
+ authorization = c.Ctx.Input.Header("authorization")
|
|
|
+ if authorization == "" {
|
|
|
+ authorization = c.Ctx.Input.Header("Authorization")
|
|
|
+ }
|
|
|
+ if authorization == "" {
|
|
|
+ newAuthorization := c.GetString("authorization")
|
|
|
+ if newAuthorization != `` {
|
|
|
+ authorization = "authorization=" + newAuthorization
|
|
|
+ } else {
|
|
|
+ newAuthorization = c.GetString("Authorization")
|
|
|
+ authorization = "authorization=" + newAuthorization
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if strings.Contains(authorization, ";") {
|
|
|
+ authorization = strings.Replace(authorization, ";", "$", 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if authorization == "" {
|
|
|
+ strArr := strings.Split(uri, "?")
|
|
|
+ for k, v := range strArr {
|
|
|
+ fmt.Println(k, v)
|
|
|
+ }
|
|
|
+ if len(strArr) > 1 {
|
|
|
+ authorization = strArr[1]
|
|
|
+ authorization = strings.Replace(authorization, "Authorization", "authorization", -1)
|
|
|
+ fmt.Println(authorization)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ utils.ApiLog.Info("uri:%s, authorization:%s, requestBody:%s, responseBody:%s, ip:%s", c.Ctx.Input.URI(), authorization, requestBody, respContent, ip)
|
|
|
+ return
|
|
|
+}
|