lint code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Javier Provecho Fernandez · committed by Javier Provecho Fernandez · parent 89f1adf · Browse files · 17 files·+72 added−73 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
17 files+72 added−73 removed
- other:+72 added−73 removed
Provenance
- Commit
9e930b9- Tree
b923967- Author
Javier Provecho Fernandez <javiertitan@gmail.com>- Committer
Javier Provecho Fernandez <javiertitan@gmail.com>- Parent
89f1adf
17 files changed+72 added−73 removed
modified:binding/protobuf.go+2 added-2 removed
11 unmodified lines12 )13 14 type protobufBinding struct{}15 16-func (_ protobufBinding) Name() string {16+func (protobufBinding) Name() string {17 return "protobuf"18 }19 20-func (_ protobufBinding) Bind(req *http.Request, obj interface{}) error {20+func (protobufBinding) Bind(req *http.Request, obj interface{}) error {21 22 buf, err := ioutil.ReadAll(req.Body)23 if err != nil {24 return err11 unmodified linesmodified:binding/validate_test.go+26 added-26 removed
14 unmodified lines15 type testInterface interface {16 String() string17 }18 19-type substruct_noValidation struct {20- I_String string21- I_Int int19+type substructNoValidation struct {20+ IString string21+ IInt int22 }23 24-type mapNoValidationSub map[string]substruct_noValidation24+type mapNoValidationSub map[string]substructNoValidation25 26-type struct_noValidation_values struct {27- substruct_noValidation26+type structNoValidationValues struct {27+ substructNoValidation28 29 Boolean bool30 31 Uinteger uint13 unmodified lines45 String string46 47 Date time.Time48 49- Struct substruct_noValidation49+ Struct substructNoValidation50 InlinedStruct struct {51 String []string52 Integer int53 }54 55 IntSlice []int56 IntPointerSlice []*int57- StructPointerSlice []*substruct_noValidation58- StructSlice []substruct_noValidation57+ StructPointerSlice []*substructNoValidation58+ StructSlice []substructNoValidation59 InterfaceSlice []testInterface60 61 UniversalInterface interface{}62 CustomInterface testInterface1 unmodified line64 FloatMap map[string]float3265 StructMap mapNoValidationSub66 }67 68-func createNoValidation_values() struct_noValidation_values {68+func createNoValidationValues() structNoValidationValues {69 integer := 170- s := struct_noValidation_values{70+ s := structNoValidationValues{71 Boolean: true,72 Uinteger: 1 << 29,73 Integer: -10000,74 Integer8: 120,8 unmodified lines83 Float64: 123.456789,84 String: "text",85 Date: time.Time{},86 CustomInterface: &bytes.Buffer{},87- Struct: substruct_noValidation{},87+ Struct: substructNoValidation{},88 IntSlice: []int{-3, -2, 1, 0, 1, 2, 3},89 IntPointerSlice: []*int{&integer},90- StructSlice: []substruct_noValidation{},90+ StructSlice: []substructNoValidation{},91 UniversalInterface: 1.2,92 FloatMap: map[string]float32{93 "foo": 1.23,94 "bar": 232.323,95 },96 StructMap: mapNoValidationSub{97- "foo": substruct_noValidation{},98- "bar": substruct_noValidation{},97+ "foo": substructNoValidation{},98+ "bar": substructNoValidation{},99 },100 // StructPointerSlice []noValidationSub101 // InterfaceSlice []testInterface102 }103 s.InlinedStruct.Integer = 1000104 s.InlinedStruct.String = []string{"first", "second"}105- s.I_String = "substring"106- s.I_Int = 987654105+ s.IString = "substring"106+ s.IInt = 987654107 return s108 }109 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 115 assert.Nil(t, validate(test))116 assert.Nil(t, validate(&test))117 assert.Nil(t, validate(empty))1 unmodified line119 120 assert.Equal(t, origin, test)121 }122 123-type struct_noValidation_pointer struct {124- substruct_noValidation123+type structNoValidationPointer struct {124+ substructNoValidation125 126 Boolean bool127 128 Uinteger *uint13 unmodified lines142 String *string143 144 Date *time.Time145 146- Struct *substruct_noValidation146+ Struct *substructNoValidation147 148 IntSlice *[]int149 IntPointerSlice *[]*int150- StructPointerSlice *[]*substruct_noValidation151- StructSlice *[]substruct_noValidation150+ StructPointerSlice *[]*substructNoValidation151+ StructSlice *[]substructNoValidation152 InterfaceSlice *[]testInterface153 154 FloatMap *map[string]float32155 StructMap *mapNoValidationSub1 unmodified line157 158 func TestValidateNoValidationPointers(t *testing.T) {159 //origin := createNoValidation_values()160 //test := createNoValidation_values()161- empty := struct_noValidation_pointer{}161+ empty := structNoValidationPointer{}162 163 //assert.Nil(t, validate(test))164 //assert.Nil(t, validate(&test))165 assert.Nil(t, validate(empty))27 unmodified linesmodified:examples/realtime-advanced/stats.go+3 added-3 removed
14 unmodified lines15 var savedStats map[string]uint6416 17 func statsWorker() {18 c := time.Tick(1 * time.Second)19- var lastMallocs uint64 = 020- var lastFrees uint64 = 021- for _ = range c {19+ var lastMallocs uint6420+ var lastFrees uint6421+ for range c {22 var stats runtime.MemStats23 runtime.ReadMemStats(&stats)24 25 mutexStats.Lock()31 unmodified linesmodified:ginS/gins.go+7 added-7 removed
32 unmodified lines33 func SetHTMLTemplate(templ *template.Template) {34 engine().SetHTMLTemplate(templ)35 }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 func NoRoute(handlers ...HandlerFunc) {39 engine().NoRoute(handlers...)40 }41 42-// Sets the handlers called when... TODO42+// NoMethod sets the handlers called when... TODO43 func NoMethod(handlers ...HandlerFunc) {44 engine().NoMethod(handlers...)45 }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 // For example, all the routes that use a common middlware for authorization could be grouped.49 func Group(relativePath string, handlers ...HandlerFunc) *RouterGroup {50 return engine().Group(relativePath, handlers...)51 }58 unmodified lines110 func StaticFS(relativePath string, fs http.FileSystem) IRoutes {111 return engine().StaticFS(relativePath, fs)112 }113 114-// Attachs a global middleware to the router. ie. the middlewares attached though Use() will be114+// Use attachs a global middleware to the router. ie. the middlewares attached though Use() will be115 // included in the handlers chain for every single request. Even 404, 405, static files...116 // For example, this is the right place for a logger or error management middleware.117 func Use(middlewares ...HandlerFunc) IRoutes {118 return engine().Use(middlewares...)119 }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 // It is a shortcut for http.ListenAndServe(addr, router)123 // Note: this method will block the calling goroutine undefinitelly unless an error happens.124 func Run(addr ...string) (err error) {125 return engine().Run(addr...)126 }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 // It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)130 // Note: this method will block the calling goroutine undefinitelly unless an error happens.131 func RunTLS(addr string, certFile string, keyFile string) (err error) {132 return engine().RunTLS(addr, certFile, keyFile)133 }134 135-// The router is attached to a http.Server and starts listening and serving HTTP requests135+// RunUnix : The router is attached to a http.Server and starts listening and serving HTTP requests136 // through the specified unix socket (ie. a file)137 // Note: this method will block the calling goroutine undefinitelly unless an error happens.138 func RunUnix(file string) (err error) {139 return engine().RunUnix(file)1 unmodified linemodified:render/html.go+1 added-2 removed
59 unmodified lines60 func (r HTML) Render(w http.ResponseWriter) error {61 writeContentType(w, htmlContentType)62 if len(r.Name) == 0 {63 return r.Template.Execute(w, r.Data)64- } else {65- return r.Template.ExecuteTemplate(w, r.Name, r.Data)64 }65+ return r.Template.ExecuteTemplate(w, r.Name, r.Data)66 }modified:context_test.go+2 added-2 removed
260 unmodified lines261 Foo string `form:"foo"`262 Bar string `form:"bar"`263 BarAsInt int `form:"bar"`264 Array []string `form:"array"`265- Id string `form:"id"`265+ ID string `form:"id"`266 }267 assert.NoError(t, c.Bind(&obj))268 assert.Equal(t, obj.Foo, "bar")269 assert.Equal(t, obj.Bar, "10")270 assert.Equal(t, obj.BarAsInt, 10)271 assert.Equal(t, obj.Array, []string{"first", "second"})272- assert.Equal(t, obj.Id, "")272+ assert.Equal(t, obj.ID, "")273 274 value, ok := c.GetQuery("foo")275 assert.False(t, ok)276 assert.Empty(t, value)430 unmodified linesmodified:context.go+3 added-3 removed
67 unmodified lines68 69 // Copy returns a copy of the current context that can be safely used outside the request's scope.70 // This have to be used then the context has to be passed to a goroutine.71 func (c *Context) Copy() *Context {72- var cp Context = *c72+ var cp = *c73 cp.writermem.ResponseWriter = nil74 cp.Writer = &cp.writermem75 cp.index = abortIndex76 cp.handlers = nil94 unmodified lines171 }172 return173 }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 func (c *Context) MustGet(key string) interface{} {177 if value, exists := c.Get(key); exists {178 return value179 }63 unmodified lines243 value, _ := c.GetPostForm(key)244 return value245 }246 247-// PostForm returns the specified key from a POST urlencoded form or multipart form247+// DefaultPostForm returns the specified key from a POST urlencoded form or multipart form248 // when it exists, otherwise it returns the specified defaultValue string.249 // See: PostForm() and GetPostForm() for further information.250 func (c *Context) DefaultPostForm(key, defaultValue string) string {251 if value, ok := c.GetPostForm(key); ok {317 unmodified linesmodified:errors.go+2 added-2 removed
64 unmodified lines65 }66 return json67 }68 69-// Implements the json.Marshaller interface69+// MarshalJSON implements the json.Marshaller interface70 func (msg *Error) MarshalJSON() ([]byte, error) {71 return json.Marshal(msg.JSON())72 }73 14 unmodified lines88 }89 if typ == ErrorTypeAny {90 return a91 }92- var result errorMsgs = nil92+ var result errorMsgs93 for _, msg := range a {94 if msg.IsType(typ) {95 result = append(result, msg)96 }63 unmodified linesmodified:gin_test.go+7 added-7 removed
199 unmodified lines200 }201 202 func TestListOfRoutes(t *testing.T) {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 group := router.Group("/users")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 }212 router.Static("/static", ".")213 214 list := router.Routes()35 unmodified lines250 }251 t.Errorf("route not found: %v", wantRoute)252 }253 254-func handler_test1(c *Context) {}255-func handler_test2(c *Context) {}254+func handlerTest1(c *Context) {}255+func handlerTest2(c *Context) {}modified:gin.go+4 added-4 removed
12 unmodified lines13 14 "github.com/gin-gonic/gin/render"15 )16 17-// Framework's version17+// Version is Framework's version18 const Version = "v1.0rc2"19 20 var default404Body = []byte("404 page not found")21 var default405Body = []byte("405 method not allowed")124 unmodified lines146 }147 engine.HTMLRender = render.HTMLProduction{Template: templ}148 }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 func (engine *Engine) NoRoute(handlers ...HandlerFunc) {152 engine.noRoute = handlers153 engine.rebuild404Handlers()154 }155 156-// Sets the handlers called when... TODO156+// NoMethod sets the handlers called when... TODO157 func (engine *Engine) NoMethod(handlers ...HandlerFunc) {158 engine.noMethod = handlers159 engine.rebuild405Handlers()160 }161 162-// Attachs a global middleware to the router. ie. the middleware attached though Use() will be162+// Use attachs a global middleware to the router. ie. the middleware attached though Use() will be163 // included in the handlers chain for every single request. Even 404, 405, static files...164 // For example, this is the right place for a logger or error management middleware.165 func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {166 engine.RouterGroup.Use(middleware...)204 unmodified linesmodified:githubapi_test.go+1 added-1 removed
339 unmodified lines340 }341 if start >= 0 {342 value := fmt.Sprint(rand.Intn(100000))343 params = append(params, Param{344- Key: path[start:len(path)],344+ Key: path[start:],345 Value: value,346 })347 output.WriteString(value)348 }41 unmodified linesmodified:logger.go+2 added-2 removed
33 unmodified lines34 }35 }36 }37 38-// Instances a Logger middleware that will write the logs to gin.DefaultWriter38+// Logger instances a Logger middleware that will write the logs to gin.DefaultWriter39 // By default gin.DefaultWriter = os.Stdout40 func Logger() HandlerFunc {41 return LoggerWithWriter(DefaultWriter)42 }43 44-// Instance a Logger middleware with the specified writter buffer.44+// LoggerWithWriter instance a Logger middleware with the specified writter buffer.45 // Example: os.Stdout, a file opened in write mode, a socket...46 func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {47 var skip map[string]struct{}48 75 unmodified linesmodified:mode.go+4 added-5 removed
3 unmodified lines4 5 package gin6 7 import (8- "io"8 "os"9 10 "github.com/gin-gonic/gin/binding"11 )17 unmodified lines29 // output io.Writer.30 // To support coloring in Windows use:31 // import "github.com/mattn/go-colorable"32 // gin.DefaultWriter = colorable.NewColorableStdout()34-var DefaultWriter io.Writer = os.Stdout35-var DefaultErrorWriter io.Writer = os.Stderr33+var DefaultWriter = os.Stdout34+var DefaultErrorWriter = os.Stderr35 37-var ginMode int = debugCode38-var modeName string = DebugMode36+var ginMode = debugCode37+var modeName = DebugMode38 39 func init() {40 mode := os.Getenv(ENV_GIN_MODE)41 if len(mode) == 0 {27 unmodified linesmodified:README.md+1 added-1 removed
1 unmodified line2 #Gin Web Framework3 <img align="right" src="https://raw.githubusercontent.com/gin-gonic/gin/master/logo.jpg">4 [](https://travis-ci.org/gin-gonic/gin)5 [](https://coveralls.io/r/gin-gonic/gin?branch=master)6-[]6+[](https://goreportcard.com/report/github.com/gin-gonic/gin)7 [](https://godoc.org/github.com/gin-gonic/gin)8 [](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)9 10 Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin.700 unmodified linesmodified:tree_test.go+1 added-1 removed
19 unmodified lines20 printChildren(child, prefix)21 }22 }23 24-// Used as a workaround since we can't compare functions or their adresses24+// Used as a workaround since we can't compare functions or their addressses25 var fakeHandlerValue string26 27 func fakeHandler(val string) HandlersChain {28 return HandlersChain{func(c *Context) {605 unmodified linesmodified:tree.go+3 added-1 removed
18 unmodified lines19 // The slice is ordered, the first URL parameter is also the first slice value.20 // It is therefore safe to read values by the index.21 type Params []Param22 23-// ByName returns the value of the first Param which key matches the given name.23+// Get returns the value of the first Param which key matches the given name.24 // If no matching Param is found, an empty string is returned.25 func (ps Params) Get(name string) (string, bool) {26 for _, entry := range ps {27 if entry.Key == name {2 unmodified lines30 }31 return "", false32 }33 34+// ByName returns the value of the first Param which key matches the given name.35+// If no matching Param is found, an empty string is returned.36 func (ps Params) ByName(name string) (va string) {37 va, _ = ps.Get(name)38 return39 }566 unmodified linesmodified:utils.go+3 added-4 removed
45 unmodified lines46 }47 48 type H map[string]interface{}49 50-// Allows type H to be used with xml.Marshal50+// MarshalXML allows type H to be used with xml.Marshal51 func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {52 start.Name = xml.Name{53 Space: "",54 Local: "map",87 unmodified lines142 case 0:143 if port := os.Getenv("PORT"); len(port) > 0 {144 debugPrint("Environment variable PORT=\"%s\"", port)145 return ":" + port146- } else {147- debugPrint("Environment variable PORT is undefined. Using port :8080 by default")148- return ":8080"146 }147+ debugPrint("Environment variable PORT is undefined. Using port :8080 by default")148+ return ":8080"149 case 1:150 return addr[0]151 default:152 panic("too much parameters")2 unmodified lines