MCPcopy Create free account
hub / github.com/TalkingData/owl / OperationRecord

Function OperationRecord

api/operations.go:39–69  ·  view source on GitHub ↗

OperationRecord 操作记录中间件

()

Source from the content-addressed store, hash-verified

37
38// OperationRecord 操作记录中间件
39func OperationRecord() gin.HandlerFunc {
40 return func(c *gin.Context) {
41 if strings.ToLower(c.Request.Method) == "get" {
42 c.Next()
43 return
44 }
45 operation := &Operation{}
46 operation.Result = 1
47 operation.Time = time.Now()
48 operation.IP = strings.Split(c.Request.RemoteAddr, ":")[0]
49 rip := c.Request.Header.Get("X-Real-Ip")
50 if len(rip) > 0 {
51 operation.IP = rip
52 }
53 operation.Operator = c.GetString("username")
54 body, _ := ioutil.ReadAll(c.Request.Body)
55 c.Request.Body = ioutil.NopCloser(bytes.NewReader(body))
56 operation.Method = c.Request.Method
57 operation.API = c.Request.URL.String()
58 operation.Body = string(body)
59
60 c.Next()
61
62 if strings.Contains(c.Request.URL.String(), "/operations") != true {
63 if c.Writer.Status() <= 599 && c.Writer.Status() >= 400 {
64 operation.Result = 0
65 }
66 mydb.CreateOperation(operation)
67 }
68 }
69}
70
71func operationList(c *gin.Context) {
72 startTime := c.DefaultQuery("start_time", time.Now().Add(-time.Hour).Format("2006-01-02 15:04:05"))

Callers 1

InitServerFunction · 0.85

Calls 3

CreateOperationMethod · 0.80
GetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected