gin框架类似于javaAOP的实现

func LogPushAop(mqClass Class, service, operMethod, operType, operDesc string) gin.HandlerFunc {

return func(c *gin.Context) {

mid := gin_util.GetUid(c)

bodyBytes, _ := ioutil.ReadAll(c.Request.Body)

_ = c.Request.Body.Close()

mbDe := new(MbDetail)

agres, _ := user.GetAgentFromHeader(c)

if agres != nil {

mbDe.Os = agres.SysVersion

mbDe.AppVersion = agres.AppVersion

mbDe.Did = agres.Did

}

mbDe.ClientIp = c.ClientIP()

mbDe.ReQuest = json.RawMessage(bodyBytes)

c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))

c.Next()

mainDe, _ := json.Marshal(mbDe)

tmp := LogPushMessage{

Service:    service,

OperMethod: operMethod,

OperType:  operType,

MainId:    mid,

MainBody:  isAdmin(mid),

MainDetail: mainDe,

OperDes:    operDesc,

ObjectBody: operType,

}

result, ok := c.Get(LogOperationKey)

if ok {

temp := new(CallIn)

_ = copier.Copy(temp, result)

var operTemp []byte

if temp.OperIn != nil {

operTemp, _ = json.Marshal(temp.OperIn)

}

var obTemp []byte

if temp.ObjectIn != nil {

obTemp, _ = json.Marshal(temp.ObjectIn)

}

tmp.OperDetail = operTemp

tmp.ObjectDetail = obTemp

}

New(Class{

Topic:  mqClass.Topic,

Group:  mqClass.Group,

Broker: mqClass.Broker,

}).SendLogMqMessage(tmp)

}

}

你可能感兴趣的:(gin框架类似于javaAOP的实现)