Init hostname only once

This commit is contained in:
Ankit Deshpande 2019-03-23 02:49:47 +05:30 committed by GitHub
parent 5d05462a6e
commit e6ee8f9745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -20,6 +20,10 @@ var timeFormat = "02/Jan/2006:15:04:05 -0700"
// Logger is the logrus logger handler
func Logger(log *logrus.Logger) gin.HandlerFunc {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknow"
}
return func(c *gin.Context) {
// other handler can change c.Path so:
path := c.Request.URL.Path
@ -31,10 +35,6 @@ func Logger(log *logrus.Logger) gin.HandlerFunc {
clientIP := c.ClientIP()
clientUserAgent := c.Request.UserAgent()
referer := c.Request.Referer()
hostname, err := os.Hostname()
if err != nil {
hostname = "unknow"
}
dataLength := c.Writer.Size()
if dataLength < 0 {
dataLength = 0