Granty1
4 years ago
5 changed files with 84 additions and 23 deletions
-
13server/config.yaml
-
23server/config/config.go
-
17server/core/log.go
-
2server/initialize/router.go
-
52server/middleware/operation.go
@ -0,0 +1,52 @@ |
|||
package middleware |
|||
|
|||
import ( |
|||
"bytes" |
|||
"fmt" |
|||
"gin-vue-admin/global" |
|||
"github.com/gin-gonic/gin" |
|||
"io/ioutil" |
|||
"net/http" |
|||
"time" |
|||
) |
|||
|
|||
var body []byte |
|||
|
|||
func RecordRequestBody() gin.HandlerFunc { |
|||
return func(c *gin.Context) { |
|||
if c.Request.Method != http.MethodGet { |
|||
var err error |
|||
body, err = ioutil.ReadAll(c.Request.Body) |
|||
if err != nil { |
|||
global.GVA_LOG.Error(err) |
|||
} |
|||
|
|||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) |
|||
} else { |
|||
body = nil |
|||
} |
|||
} |
|||
} |
|||
|
|||
func OperationRecord() gin.HandlerFunc { |
|||
return gin.LoggerWithConfig(gin.LoggerConfig{ |
|||
Formatter: func(param gin.LogFormatterParams) string { |
|||
|
|||
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" \"%s\" %s\"\n", |
|||
param.ClientIP, |
|||
param.TimeStamp.Format(time.RFC1123), |
|||
param.Method, |
|||
param.Path, |
|||
param.Request.Proto, |
|||
param.StatusCode, |
|||
param.Latency, |
|||
param.Request.UserAgent(), |
|||
string(body), |
|||
param.ErrorMessage, |
|||
) |
|||
}, |
|||
// 暂时没考虑好
|
|||
Output: nil, |
|||
SkipPaths: global.GVA_CONFIG.Operation.SkipPaths, |
|||
}) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue