From 9a4ecc87d6f8272b8e2450f9c0ab12d3e814521f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E6=AC=A7?= Date: Sun, 12 Nov 2017 13:24:51 +0800 Subject: [PATCH] format some codes style (#1165) --- context.go | 13 +++++-------- gin.go | 4 ++-- json/json.go | 4 +--- json/jsoniter.go | 4 +--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/context.go b/context.go index 5b67dcc..1ed65fe 100644 --- a/context.go +++ b/context.go @@ -33,9 +33,7 @@ const ( MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm ) -const ( - abortIndex int8 = math.MaxInt8 / 2 -) +const abortIndex int8 = math.MaxInt8 / 2 // Context is the most important part of gin. It allows us to pass variables between middleware, // manage the flow, validate the JSON of a request and render a JSON response for example. @@ -105,8 +103,7 @@ func (c *Context) Handler() HandlerFunc { // See example in GitHub. func (c *Context) Next() { c.index++ - s := int8(len(c.handlers)) - for ; c.index < s; c.index++ { + for s := int8(len(c.handlers)); c.index < s; c.index++ { c.handlers[c.index](c) } } @@ -521,11 +518,11 @@ func (c *Context) ClientIP() string { clientIP = clientIP[0:index] } clientIP = strings.TrimSpace(clientIP) - if len(clientIP) > 0 { + if clientIP != "" { return clientIP } clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip")) - if len(clientIP) > 0 { + if clientIP != "" { return clientIP } } @@ -588,7 +585,7 @@ func (c *Context) Status(code int) { // It writes a header in the response. // If value == "", this method removes the header `c.Writer.Header().Del(key)` func (c *Context) Header(key, value string) { - if len(value) == 0 { + if value == "" { c.Writer.Header().Del(key) } else { c.Writer.Header().Set(key, value) diff --git a/gin.go b/gin.go index 4857f3a..b59712b 100644 --- a/gin.go +++ b/gin.go @@ -403,8 +403,8 @@ func redirectTrailingSlash(c *Context) { code = 307 } - if len(path) > 1 && path[len(path)-1] == '/' { - req.URL.Path = path[:len(path)-1] + if length := len(path); length > 1 && path[length-1] == '/' { + req.URL.Path = path[:length-1] } else { req.URL.Path = path + "/" } diff --git a/json/json.go b/json/json.go index d2d0f8b..aa76aa3 100644 --- a/json/json.go +++ b/json/json.go @@ -6,9 +6,7 @@ package json -import ( - "encoding/json" -) +import "encoding/json" var ( Marshal = json.Marshal diff --git a/json/jsoniter.go b/json/jsoniter.go index 65deee5..ffe1424 100644 --- a/json/jsoniter.go +++ b/json/jsoniter.go @@ -6,9 +6,7 @@ package json -import ( - "github.com/json-iterator/go" -) +import "github.com/json-iterator/go" var ( json = jsoniter.ConfigCompatibleWithStandardLibrary