|
@@ -33,9 +33,7 @@ const (
|
|
|
MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
|
|
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,
|
|
// 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.
|
|
// 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.
|
|
// See example in GitHub.
|
|
|
func (c *Context) Next() {
|
|
func (c *Context) Next() {
|
|
|
c.index++
|
|
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)
|
|
c.handlers[c.index](c)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -521,11 +518,11 @@ func (c *Context) ClientIP() string {
|
|
|
clientIP = clientIP[0:index]
|
|
clientIP = clientIP[0:index]
|
|
|
}
|
|
}
|
|
|
clientIP = strings.TrimSpace(clientIP)
|
|
clientIP = strings.TrimSpace(clientIP)
|
|
|
- if len(clientIP) > 0 {
|
|
|
|
|
|
|
+ if clientIP != "" {
|
|
|
return clientIP
|
|
return clientIP
|
|
|
}
|
|
}
|
|
|
clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
|
|
clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
|
|
|
- if len(clientIP) > 0 {
|
|
|
|
|
|
|
+ if clientIP != "" {
|
|
|
return clientIP
|
|
return clientIP
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -588,7 +585,7 @@ func (c *Context) Status(code int) {
|
|
|
// It writes a header in the response.
|
|
// It writes a header in the response.
|
|
|
// If value == "", this method removes the header `c.Writer.Header().Del(key)`
|
|
// If value == "", this method removes the header `c.Writer.Header().Del(key)`
|
|
|
func (c *Context) Header(key, value string) {
|
|
func (c *Context) Header(key, value string) {
|
|
|
- if len(value) == 0 {
|
|
|
|
|
|
|
+ if value == "" {
|
|
|
c.Writer.Header().Del(key)
|
|
c.Writer.Header().Del(key)
|
|
|
} else {
|
|
} else {
|
|
|
c.Writer.Header().Set(key, value)
|
|
c.Writer.Header().Set(key, value)
|