GeezerVison is showing github.com — lint code · NodejsMAS/gin@9e930b9
File treeExpand file treeCollapse file tree Open diff view settings examples/realtime-advanced
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | <img align="right" src="https://raw.githubusercontent.com/gin-gonic/gin/master/logo.jpg"> | 4 | 4 | [](https://travis-ci.org/gin-gonic/gin) | 5 | 5 | [](https://coveralls.io/r/gin-gonic/gin?branch=master) | 6 | | -[] | | 6 | +[](https://goreportcard.com/report/github.com/gin-gonic/gin) | 7 | 7 | [](https://godoc.org/github.com/gin-gonic/gin) | 8 | 8 | [](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | 9 | 9 |
| |
Collapse file Copy file name to clipboardExpand all lines: binding/protobuf.go +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,11 +13,11 @@ import ( | 13 | 13 |
| 14 | 14 | type protobufBinding struct{} | 15 | 15 |
| 16 | | -func (_ protobufBinding) Name() string { | | 16 | +func (protobufBinding) Name() string { | 17 | 17 | return "protobuf" | 18 | 18 | } | 19 | 19 |
| 20 | | -func (_ protobufBinding) Bind(req *http.Request, obj interface{}) error { | | 20 | +func (protobufBinding) Bind(req *http.Request, obj interface{}) error { | 21 | 21 |
| 22 | 22 | buf, err := ioutil.ReadAll(req.Body) | 23 | 23 | if err != nil { | |
Collapse file Copy file name to clipboardExpand all lines: binding/validate_test.go +26-26Lines changed: 26 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,15 +16,15 @@ type testInterface interface { | 16 | 16 | String() string | 17 | 17 | } | 18 | 18 |
| 19 | | -type substruct_noValidation struct { | 20 | | - I_String string | 21 | | - I_Int int | | 19 | +type substructNoValidation struct { | | 20 | + IString string | | 21 | + IInt int | 22 | 22 | } | 23 | 23 |
| 24 | | -type mapNoValidationSub map[string]substruct_noValidation | | 24 | +type mapNoValidationSub map[string]substructNoValidation | 25 | 25 |
| 26 | | -type struct_noValidation_values struct { | 27 | | - substruct_noValidation | | 26 | +type structNoValidationValues struct { | | 27 | + substructNoValidation | 28 | 28 |
| 29 | 29 | Boolean bool | 30 | 30 |
| @@ -46,16 +46,16 @@ type struct_noValidation_values struct { | 46 | 46 |
| 47 | 47 | Date time.Time | 48 | 48 |
| 49 | | - Struct substruct_noValidation | | 49 | + Struct substructNoValidation | 50 | 50 | InlinedStruct struct { | 51 | 51 | String []string | 52 | 52 | Integer int | 53 | 53 | } | 54 | 54 |
| 55 | 55 | IntSlice []int | 56 | 56 | IntPointerSlice []*int | 57 | | - StructPointerSlice []*substruct_noValidation | 58 | | - StructSlice []substruct_noValidation | | 57 | + StructPointerSlice []*substructNoValidation | | 58 | + StructSlice []substructNoValidation | 59 | 59 | InterfaceSlice []testInterface | 60 | 60 |
| 61 | 61 | UniversalInterface interface{} | @@ -65,9 +65,9 @@ type struct_noValidation_values struct { | 65 | 65 | StructMap mapNoValidationSub | 66 | 66 | } | 67 | 67 |
| 68 | | -func createNoValidation_values() struct_noValidation_values { | | 68 | +func createNoValidationValues() structNoValidationValues { | 69 | 69 | integer := 1 | 70 | | - s := struct_noValidation_values{ | | 70 | + s := structNoValidationValues{ | 71 | 71 | Boolean: true, | 72 | 72 | Uinteger: 1 << 29, | 73 | 73 | Integer: -10000, | @@ -84,33 +84,33 @@ func createNoValidation_values() struct_noValidation_values { | 84 | 84 | String: "text", | 85 | 85 | Date: time.Time{}, | 86 | 86 | CustomInterface: &bytes.Buffer{}, | 87 | | - Struct: substruct_noValidation{}, | | 87 | + Struct: substructNoValidation{}, | 88 | 88 | IntSlice: []int{-3, -2, 1, 0, 1, 2, 3}, | 89 | 89 | IntPointerSlice: []*int{&integer}, | 90 | | - StructSlice: []substruct_noValidation{}, | | 90 | + StructSlice: []substructNoValidation{}, | 91 | 91 | UniversalInterface: 1.2, | 92 | 92 | FloatMap: map[string]float32{ | 93 | 93 | "foo": 1.23, | 94 | 94 | "bar": 232.323, | 95 | 95 | }, | 96 | 96 | StructMap: mapNoValidationSub{ | 97 | | - "foo": substruct_noValidation{}, | 98 | | - "bar": substruct_noValidation{}, | | 97 | + "foo": substructNoValidation{}, | | 98 | + "bar": substructNoValidation{}, | 99 | 99 | }, | 100 | 100 | // StructPointerSlice []noValidationSub | 101 | 101 | // InterfaceSlice []testInterface | 102 | 102 | } | 103 | 103 | s.InlinedStruct.Integer = 1000 | 104 | 104 | s.InlinedStruct.String = []string{"first", "second"} | 105 | | - s.I_String = "substring" | 106 | | - s.I_Int = 987654 | | 105 | + s.IString = "substring" | | 106 | + s.IInt = 987654 | 107 | 107 | return s | 108 | 108 | } | 109 | 109 |
| 110 | 110 | func TestValidateNoValidationValues(t *testing.T) { | 111 | | - origin := createNoValidation_values() | 112 | | - test := createNoValidation_values() | 113 | | - empty := struct_noValidation_values{} | | 111 | + origin := createNoValidationValues() | | 112 | + test := createNoValidationValues() | | 113 | + empty := structNoValidationValues{} | 114 | 114 |
| 115 | 115 | assert.Nil(t, validate(test)) | 116 | 116 | assert.Nil(t, validate(&test)) | @@ -120,8 +120,8 @@ func TestValidateNoValidationValues(t *testing.T) { | 120 | 120 | assert.Equal(t, origin, test) | 121 | 121 | } | 122 | 122 |
| 123 | | -type struct_noValidation_pointer struct { | 124 | | - substruct_noValidation | | 123 | +type structNoValidationPointer struct { | | 124 | + substructNoValidation | 125 | 125 |
| 126 | 126 | Boolean bool | 127 | 127 |
| @@ -143,12 +143,12 @@ type struct_noValidation_pointer struct { | 143 | 143 |
| 144 | 144 | Date *time.Time | 145 | 145 |
| 146 | | - Struct *substruct_noValidation | | 146 | + Struct *substructNoValidation | 147 | 147 |
| 148 | 148 | IntSlice *[]int | 149 | 149 | IntPointerSlice *[]*int | 150 | | - StructPointerSlice *[]*substruct_noValidation | 151 | | - StructSlice *[]substruct_noValidation | | 150 | + StructPointerSlice *[]*substructNoValidation | | 151 | + StructSlice *[]substructNoValidation | 152 | 152 | InterfaceSlice *[]testInterface | 153 | 153 |
| 154 | 154 | FloatMap *map[string]float32 | @@ -158,7 +158,7 @@ type struct_noValidation_pointer struct { | 158 | 158 | func TestValidateNoValidationPointers(t *testing.T) { | 159 | 159 | //origin := createNoValidation_values() | 160 | 160 | //test := createNoValidation_values() | 161 | | - empty := struct_noValidation_pointer{} | | 161 | + empty := structNoValidationPointer{} | 162 | 162 |
| 163 | 163 | //assert.Nil(t, validate(test)) | 164 | 164 | //assert.Nil(t, validate(&test)) | |
Collapse file Copy file name to clipboardExpand all lines: context.go +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,7 +69,7 @@ func (c *Context) reset() { | 69 | 69 | // Copy returns a copy of the current context that can be safely used outside the request's scope. | 70 | 70 | // This have to be used then the context has to be passed to a goroutine. | 71 | 71 | func (c *Context) Copy() *Context { | 72 | | - var cp Context = *c | | 72 | + var cp = *c | 73 | 73 | cp.writermem.ResponseWriter = nil | 74 | 74 | cp.Writer = &cp.writermem | 75 | 75 | cp.index = abortIndex | @@ -172,7 +172,7 @@ func (c *Context) Get(key string) (value interface{}, exists bool) { | 172 | 172 | return | 173 | 173 | } | 174 | 174 |
| 175 | | -// Returns the value for the given key if it exists, otherwise it panics. | | 175 | +// MustGet returns the value for the given key if it exists, otherwise it panics. | 176 | 176 | func (c *Context) MustGet(key string) interface{} { | 177 | 177 | if value, exists := c.Get(key); exists { | 178 | 178 | return value | @@ -244,7 +244,7 @@ func (c *Context) PostForm(key string) string { | 244 | 244 | return value | 245 | 245 | } | 246 | 246 |
| 247 | | -// PostForm returns the specified key from a POST urlencoded form or multipart form | | 247 | +// DefaultPostForm returns the specified key from a POST urlencoded form or multipart form | 248 | 248 | // when it exists, otherwise it returns the specified defaultValue string. | 249 | 249 | // See: PostForm() and GetPostForm() for further information. | 250 | 250 | func (c *Context) DefaultPostForm(key, defaultValue string) string { | |
Collapse file Copy file name to clipboardExpand all lines: context_test.go +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -262,14 +262,14 @@ func TestContextPostFormMultipart(t *testing.T) { | 262 | 262 | Bar string `form:"bar"` | 263 | 263 | BarAsInt int `form:"bar"` | 264 | 264 | Array []string `form:"array"` | 265 | | - Id string `form:"id"` | | 265 | + ID string `form:"id"` | 266 | 266 | } | 267 | 267 | assert.NoError(t, c.Bind(&obj)) | 268 | 268 | assert.Equal(t, obj.Foo, "bar") | 269 | 269 | assert.Equal(t, obj.Bar, "10") | 270 | 270 | assert.Equal(t, obj.BarAsInt, 10) | 271 | 271 | assert.Equal(t, obj.Array, []string{"first", "second"}) | 272 | | - assert.Equal(t, obj.Id, "") | | 272 | + assert.Equal(t, obj.ID, "") | 273 | 273 |
| 274 | 274 | value, ok := c.GetQuery("foo") | 275 | 275 | assert.False(t, ok) | |
Collapse file Copy file name to clipboardExpand all lines: errors.go +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,7 +66,7 @@ func (msg *Error) JSON() interface{} { | 66 | 66 | return json | 67 | 67 | } | 68 | 68 |
| 69 | | -// Implements the json.Marshaller interface | | 69 | +// MarshalJSON implements the json.Marshaller interface | 70 | 70 | func (msg *Error) MarshalJSON() ([]byte, error) { | 71 | 71 | return json.Marshal(msg.JSON()) | 72 | 72 | } | @@ -89,7 +89,7 @@ func (a errorMsgs) ByType(typ ErrorType) errorMsgs { | 89 | 89 | if typ == ErrorTypeAny { | 90 | 90 | return a | 91 | 91 | } | 92 | | - var result errorMsgs = nil | | 92 | + var result errorMsgs | 93 | 93 | for _, msg := range a { | 94 | 94 | if msg.IsType(typ) { | 95 | 95 | result = append(result, msg) | |
Collapse file Copy file name to clipboardExpand all lines: examples/realtime-advanced/stats.go +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,9 +16,9 @@ var savedStats map[string]uint64 | 16 | 16 |
| 17 | 17 | func statsWorker() { | 18 | 18 | c := time.Tick(1 * time.Second) | 19 | | - var lastMallocs uint64 = 0 | 20 | | - var lastFrees uint64 = 0 | 21 | | - for _ = range c { | | 19 | + var lastMallocs uint64 | | 20 | + var lastFrees uint64 | | 21 | + for range c { | 22 | 22 | var stats runtime.MemStats | 23 | 23 | runtime.ReadMemStats(&stats) | 24 | 24 |
| |
Collapse file Copy file name to clipboardExpand all lines: gin.go +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ import ( | 14 | 14 | "github.com/gin-gonic/gin/render" | 15 | 15 | ) | 16 | 16 |
| 17 | | -// Framework's version | | 17 | +// Version is Framework's version | 18 | 18 | const Version = "v1.0rc2" | 19 | 19 |
| 20 | 20 | var default404Body = []byte("404 page not found") | @@ -147,19 +147,19 @@ func (engine *Engine) SetHTMLTemplate(templ *template.Template) { | 147 | 147 | engine.HTMLRender = render.HTMLProduction{Template: templ} | 148 | 148 | } | 149 | 149 |
| 150 | | -// Adds handlers for NoRoute. It return a 404 code by default. | | 150 | +// NoRoute adds handlers for NoRoute. It return a 404 code by default. | 151 | 151 | func (engine *Engine) NoRoute(handlers ...HandlerFunc) { | 152 | 152 | engine.noRoute = handlers | 153 | 153 | engine.rebuild404Handlers() | 154 | 154 | } | 155 | 155 |
| 156 | | -// Sets the handlers called when... TODO | | 156 | +// NoMethod sets the handlers called when... TODO | 157 | 157 | func (engine *Engine) NoMethod(handlers ...HandlerFunc) { | 158 | 158 | engine.noMethod = handlers | 159 | 159 | engine.rebuild405Handlers() | 160 | 160 | } | 161 | 161 |
| 162 | | -// Attachs a global middleware to the router. ie. the middleware attached though Use() will be | | 162 | +// Use attachs a global middleware to the router. ie. the middleware attached though Use() will be | 163 | 163 | // included in the handlers chain for every single request. Even 404, 405, static files... | 164 | 164 | // For example, this is the right place for a logger or error management middleware. | 165 | 165 | func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes { | |
Collapse file Copy file name to clipboardExpand all lines: ginS/gins.go +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,17 +34,17 @@ func SetHTMLTemplate(templ *template.Template) { | 34 | 34 | engine().SetHTMLTemplate(templ) | 35 | 35 | } | 36 | 36 |
| 37 | | -// Adds handlers for NoRoute. It return a 404 code by default. | | 37 | +// NoRoute adds handlers for NoRoute. It return a 404 code by default. | 38 | 38 | func NoRoute(handlers ...HandlerFunc) { | 39 | 39 | engine().NoRoute(handlers...) | 40 | 40 | } | 41 | 41 |
| 42 | | -// Sets the handlers called when... TODO | | 42 | +// NoMethod sets the handlers called when... TODO | 43 | 43 | func NoMethod(handlers ...HandlerFunc) { | 44 | 44 | engine().NoMethod(handlers...) | 45 | 45 | } | 46 | 46 |
| 47 | | -// Creates a new router group. You should add all the routes that have common middlwares or the same path prefix. | | 47 | +// Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix. | 48 | 48 | // For example, all the routes that use a common middlware for authorization could be grouped. | 49 | 49 | func Group(relativePath string, handlers ...HandlerFunc) *RouterGroup { | 50 | 50 | return engine().Group(relativePath, handlers...) | @@ -111,28 +111,28 @@ func StaticFS(relativePath string, fs http.FileSystem) IRoutes { | 111 | 111 | return engine().StaticFS(relativePath, fs) | 112 | 112 | } | 113 | 113 |
| 114 | | -// Attachs a global middleware to the router. ie. the middlewares attached though Use() will be | | 114 | +// Use attachs a global middleware to the router. ie. the middlewares attached though Use() will be | 115 | 115 | // included in the handlers chain for every single request. Even 404, 405, static files... | 116 | 116 | // For example, this is the right place for a logger or error management middleware. | 117 | 117 | func Use(middlewares ...HandlerFunc) IRoutes { | 118 | 118 | return engine().Use(middlewares...) | 119 | 119 | } | 120 | 120 |
| 121 | | -// The router is attached to a http.Server and starts listening and serving HTTP requests. | | 121 | +// Run : The router is attached to a http.Server and starts listening and serving HTTP requests. | 122 | 122 | // It is a shortcut for http.ListenAndServe(addr, router) | 123 | 123 | // Note: this method will block the calling goroutine undefinitelly unless an error happens. | 124 | 124 | func Run(addr ...string) (err error) { | 125 | 125 | return engine().Run(addr...) | 126 | 126 | } | 127 | 127 |
| 128 | | -// The router is attached to a http.Server and starts listening and serving HTTPS requests. | | 128 | +// RunTLS : The router is attached to a http.Server and starts listening and serving HTTPS requests. | 129 | 129 | // It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router) | 130 | 130 | // Note: this method will block the calling goroutine undefinitelly unless an error happens. | 131 | 131 | func RunTLS(addr string, certFile string, keyFile string) (err error) { | 132 | 132 | return engine().RunTLS(addr, certFile, keyFile) | 133 | 133 | } | 134 | 134 |
| 135 | | -// The router is attached to a http.Server and starts listening and serving HTTP requests | | 135 | +// RunUnix : The router is attached to a http.Server and starts listening and serving HTTP requests | 136 | 136 | // through the specified unix socket (ie. a file) | 137 | 137 | // Note: this method will block the calling goroutine undefinitelly unless an error happens. | 138 | 138 | func RunUnix(file string) (err error) { | |
Collapse file Copy file name to clipboardExpand all lines: gin_test.go +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -201,13 +201,13 @@ func compareFunc(t *testing.T, a, b interface{}) { | 201 | 201 |
| 202 | 202 | func TestListOfRoutes(t *testing.T) { | 203 | 203 | router := New() | 204 | | - router.GET("/favicon.ico", handler_test1) | 205 | | - router.GET("/", handler_test1) | | 204 | + router.GET("/favicon.ico", handlerTest1) | | 205 | + router.GET("/", handlerTest1) | 206 | 206 | group := router.Group("/users") | 207 | 207 | { | 208 | | - group.GET("/", handler_test2) | 209 | | - group.GET("/:id", handler_test1) | 210 | | - group.POST("/:id", handler_test2) | | 208 | + group.GET("/", handlerTest2) | | 209 | + group.GET("/:id", handlerTest1) | | 210 | + group.POST("/:id", handlerTest2) | 211 | 211 | } | 212 | 212 | router.Static("/static", ".") | 213 | 213 |
| @@ -251,5 +251,5 @@ func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) | 251 | 251 | t.Errorf("route not found: %v", wantRoute) | 252 | 252 | } | 253 | 253 |
| 254 | | -func handler_test1(c *Context) {} | 255 | | -func handler_test2(c *Context) {} | | 254 | +func handlerTest1(c *Context) {} | | 255 | +func handlerTest2(c *Context) {} |
|