|
@@ -9,30 +9,18 @@ import (
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
"net/http"
|
|
"net/http"
|
|
"net/url"
|
|
"net/url"
|
|
-
|
|
|
|
- "github.com/rdlucklib/rdluck_tools/log"
|
|
|
|
|
|
+ "strings"
|
|
)
|
|
)
|
|
|
|
|
|
-var apiLog *log.Log
|
|
|
|
-
|
|
|
|
-func init() {
|
|
|
|
- /*if utils.RunMode == "release" {
|
|
|
|
- logDir := `/data/rdlucklog/eta_chart_lib`
|
|
|
|
- apiLog = log.Init("20060102.api", logDir)
|
|
|
|
- } else {
|
|
|
|
- apiLog = log.Init("20060102.api")
|
|
|
|
- }*/
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
type BaseAuthController struct {
|
|
type BaseAuthController struct {
|
|
web.Controller
|
|
web.Controller
|
|
}
|
|
}
|
|
|
|
|
|
-func (this *BaseAuthController) Prepare() {
|
|
|
|
|
|
+func (c *BaseAuthController) Prepare() {
|
|
fmt.Println("enter prepare")
|
|
fmt.Println("enter prepare")
|
|
- method := this.Ctx.Input.Method()
|
|
|
|
- uri := this.Ctx.Input.URI()
|
|
|
|
- ip := this.Ctx.Input.IP()
|
|
|
|
|
|
+ method := c.Ctx.Input.Method()
|
|
|
|
+ uri := c.Ctx.Input.URI()
|
|
|
|
+ ip := c.Ctx.Input.IP()
|
|
fmt.Println("Url:", uri+";ip:"+ip)
|
|
fmt.Println("Url:", uri+";ip:"+ip)
|
|
if method != "HEAD" {
|
|
if method != "HEAD" {
|
|
if method == "POST" || method == "GET" {
|
|
if method == "POST" || method == "GET" {
|
|
@@ -135,8 +123,8 @@ func (this *BaseAuthController) Prepare() {
|
|
//admin.RoleTypeCode = GetSysUserRoleTypeCode(admin.RoleTypeCode)
|
|
//admin.RoleTypeCode = GetSysUserRoleTypeCode(admin.RoleTypeCode)
|
|
//this.SysUser = admin
|
|
//this.SysUser = admin
|
|
} else {
|
|
} else {
|
|
- this.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
|
|
|
|
- this.StopRun()
|
|
|
|
|
|
+ c.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
|
|
|
|
+ c.StopRun()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -193,19 +181,69 @@ func (c *BaseAuthController) JSON(data interface{}, hasIndent bool, coding bool)
|
|
if requestBody == "" {
|
|
if requestBody == "" {
|
|
requestBody = c.Ctx.Input.URI()
|
|
requestBody = c.Ctx.Input.URI()
|
|
}
|
|
}
|
|
- authorization := c.Ctx.Input.Header("authorization")
|
|
|
|
- if authorization == "" {
|
|
|
|
- authorization = c.Ctx.Input.Header("Authorization")
|
|
|
|
- }
|
|
|
|
- utils.ApiLog.WithFields(logrus.Fields{
|
|
|
|
- "uri": c.Ctx.Input.URI(),
|
|
|
|
- "authorization": authorization,
|
|
|
|
- "requestBody": requestBody,
|
|
|
|
- "responseBody": data,
|
|
|
|
- "ip": ip,
|
|
|
|
- }).Info("request")
|
|
|
|
|
|
+ c.logUri(data, requestBody, ip)
|
|
if coding {
|
|
if coding {
|
|
content = []byte(utils.StringsToJSON(string(content)))
|
|
content = []byte(utils.StringsToJSON(string(content)))
|
|
}
|
|
}
|
|
return c.Ctx.Output.Body(content)
|
|
return c.Ctx.Output.Body(content)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (c *BaseAuthController) logUri(data interface{}, requestBody, ip string) {
|
|
|
|
+ authorization := ""
|
|
|
|
+ method := c.Ctx.Input.Method()
|
|
|
|
+ uri := c.Ctx.Input.URI()
|
|
|
|
+ fmt.Println("Url:", 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)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var reqData interface{}
|
|
|
|
+ err := json.Unmarshal([]byte(requestBody), &reqData)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.ApiLog.WithFields(logrus.Fields{
|
|
|
|
+ "uri": c.Ctx.Input.URI(),
|
|
|
|
+ "authorization": authorization,
|
|
|
|
+ "requestBody": requestBody,
|
|
|
|
+ "responseBody": data,
|
|
|
|
+ "ip": ip,
|
|
|
|
+ }).Info("请求详情")
|
|
|
|
+ } else {
|
|
|
|
+ utils.ApiLog.WithFields(logrus.Fields{
|
|
|
|
+ "uri": c.Ctx.Input.URI(),
|
|
|
|
+ "authorization": authorization,
|
|
|
|
+ "requestBody": reqData,
|
|
|
|
+ "responseBody": data,
|
|
|
|
+ "ip": ip,
|
|
|
|
+ }).Info("请求详情")
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|