From 6ac7f194c4e4867f30c94674af3015fceb1a97af Mon Sep 17 00:00:00 2001 From: thinkerou Date: Tue, 5 May 2020 13:55:57 +0800 Subject: [PATCH] chore: update some code style (#2356) --- context.go | 2 +- gin.go | 8 ++++---- githubapi_test.go | 8 ++++---- internal/json/jsoniter.go | 2 +- routes_test.go | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/context.go b/context.go index 01cff1ae..4ebcc294 100644 --- a/context.go +++ b/context.go @@ -865,7 +865,7 @@ func (c *Context) IndentedJSON(code int, obj interface{}) { // Default prepends "while(1)," to response body if the given struct is array values. // It also sets the Content-Type as "application/json". func (c *Context) SecureJSON(code int, obj interface{}) { - c.Render(code, render.SecureJSON{Prefix: c.engine.secureJsonPrefix, Data: obj}) + c.Render(code, render.SecureJSON{Prefix: c.engine.secureJSONPrefix, Data: obj}) } // JSONP serializes the given struct as JSON into the response body. diff --git a/gin.go b/gin.go index 888be36b..4e72f81d 100644 --- a/gin.go +++ b/gin.go @@ -104,7 +104,7 @@ type Engine struct { RemoveExtraSlash bool delims render.Delims - secureJsonPrefix string + secureJSONPrefix string HTMLRender render.HTMLRender FuncMap template.FuncMap allNoRoute HandlersChain @@ -145,7 +145,7 @@ func New() *Engine { MaxMultipartMemory: defaultMultipartMemory, trees: make(methodTrees, 0, 9), delims: render.Delims{Left: "{{", Right: "}}"}, - secureJsonPrefix: "while(1);", + secureJSONPrefix: "while(1);", } engine.RouterGroup.engine = engine engine.pool.New = func() interface{} { @@ -172,9 +172,9 @@ func (engine *Engine) Delims(left, right string) *Engine { return engine } -// SecureJsonPrefix sets the secureJsonPrefix used in Context.SecureJSON. +// SecureJsonPrefix sets the secureJSONPrefix used in Context.SecureJSON. func (engine *Engine) SecureJsonPrefix(prefix string) *Engine { - engine.secureJsonPrefix = prefix + engine.secureJSONPrefix = prefix return engine } diff --git a/githubapi_test.go b/githubapi_test.go index 925c5a14..3f440bce 100644 --- a/githubapi_test.go +++ b/githubapi_test.go @@ -291,13 +291,13 @@ func TestShouldBindUri(t *testing.T) { type Person struct { Name string `uri:"name" binding:"required"` - Id string `uri:"id" binding:"required"` + ID string `uri:"id" binding:"required"` } router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) { var person Person assert.NoError(t, c.ShouldBindUri(&person)) assert.True(t, "" != person.Name) - assert.True(t, "" != person.Id) + assert.True(t, "" != person.ID) c.String(http.StatusOK, "ShouldBindUri test OK") }) @@ -313,13 +313,13 @@ func TestBindUri(t *testing.T) { type Person struct { Name string `uri:"name" binding:"required"` - Id string `uri:"id" binding:"required"` + ID string `uri:"id" binding:"required"` } router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) { var person Person assert.NoError(t, c.BindUri(&person)) assert.True(t, "" != person.Name) - assert.True(t, "" != person.Id) + assert.True(t, "" != person.ID) c.String(http.StatusOK, "BindUri test OK") }) diff --git a/internal/json/jsoniter.go b/internal/json/jsoniter.go index fabd7b84..649a3cdb 100644 --- a/internal/json/jsoniter.go +++ b/internal/json/jsoniter.go @@ -6,7 +6,7 @@ package json -import "github.com/json-iterator/go" +import jsoniter "github.com/json-iterator/go" var ( json = jsoniter.ConfigCompatibleWithStandardLibrary diff --git a/routes_test.go b/routes_test.go index ee6ea823..360ade62 100644 --- a/routes_test.go +++ b/routes_test.go @@ -514,7 +514,7 @@ func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) { // Middleware must be called just only once by per request. middlewareCalledNum := 0 router.Use(func(c *Context) { - middlewareCalledNum += 1 + middlewareCalledNum++ }) router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))