Skip to content
Myr

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

17 files+72 added−73 removed

modified:binding/protobuf.go+2 added-2 removed
11 unmodified lines
12)1314type protobufBinding struct{}1516func (_ protobufBinding) Name() string {16func (protobufBinding) Name() string {17 return "protobuf"18}1920func (_ protobufBinding) Bind(req *http.Request, obj interface{}) error {20func (protobufBinding) Bind(req *http.Request, obj interface{}) error {2122 buf, err := ioutil.ReadAll(req.Body)23 if err != nil {24 return err
11 unmodified lines
modified:binding/validate_test.go+26 added-26 removed
14 unmodified lines
15type testInterface interface {16 String() string17}1819type substruct_noValidation struct {20 I_String string21 I_Int int19type substructNoValidation struct {20 IString string21 IInt int22}2324type mapNoValidationSub map[string]substruct_noValidation24type mapNoValidationSub map[string]substructNoValidation2526type struct_noValidation_values struct {27 substruct_noValidation26type structNoValidationValues struct {27 substructNoValidation2829 Boolean bool3031 Uinteger uint
13 unmodified lines
45 String string4647 Date time.Time4849 Struct substruct_noValidation49 Struct substructNoValidation50 InlinedStruct struct {51 String []string52 Integer int53 }5455 IntSlice []int56 IntPointerSlice []*int57 StructPointerSlice []*substruct_noValidation58 StructSlice []substruct_noValidation57 StructPointerSlice []*substructNoValidation58 StructSlice []substructNoValidation59 InterfaceSlice []testInterface6061 UniversalInterface interface{}62 CustomInterface testInterface
1 unmodified line
64 FloatMap map[string]float3265 StructMap mapNoValidationSub66}6768func createNoValidation_values() struct_noValidation_values {68func 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 lines
83 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}109110func 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{}114115 assert.Nil(t, validate(test))116 assert.Nil(t, validate(&test))117 assert.Nil(t, validate(empty))
1 unmodified line
119120 assert.Equal(t, origin, test)121}122123type struct_noValidation_pointer struct {124 substruct_noValidation123type structNoValidationPointer struct {124 substructNoValidation125126 Boolean bool127128 Uinteger *uint
13 unmodified lines
142 String *string143144 Date *time.Time145146 Struct *substruct_noValidation146 Struct *substructNoValidation147148 IntSlice *[]int149 IntPointerSlice *[]*int150 StructPointerSlice *[]*substruct_noValidation151 StructSlice *[]substruct_noValidation150 StructPointerSlice *[]*substructNoValidation151 StructSlice *[]substructNoValidation152 InterfaceSlice *[]testInterface153154 FloatMap *map[string]float32155 StructMap *mapNoValidationSub
1 unmodified line
157158func TestValidateNoValidationPointers(t *testing.T) {159 //origin := createNoValidation_values()160 //test := createNoValidation_values()161 empty := struct_noValidation_pointer{}161 empty := structNoValidationPointer{}162163 //assert.Nil(t, validate(test))164 //assert.Nil(t, validate(&test))165 assert.Nil(t, validate(empty))
27 unmodified lines
modified:examples/realtime-advanced/stats.go+3 added-3 removed
14 unmodified lines
15var savedStats map[string]uint641617func 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)2425 mutexStats.Lock()
31 unmodified lines
modified:ginS/gins.go+7 added-7 removed
32 unmodified lines
33func SetHTMLTemplate(templ *template.Template) {34 engine().SetHTMLTemplate(templ)35}3637// Adds handlers for NoRoute. It return a 404 code by default.37// NoRoute adds handlers for NoRoute. It return a 404 code by default.38func NoRoute(handlers ...HandlerFunc) {39 engine().NoRoute(handlers...)40}4142// Sets the handlers called when... TODO42// NoMethod sets the handlers called when... TODO43func NoMethod(handlers ...HandlerFunc) {44 engine().NoMethod(handlers...)45}4647// 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.49func Group(relativePath string, handlers ...HandlerFunc) *RouterGroup {50 return engine().Group(relativePath, handlers...)51}
58 unmodified lines
110func StaticFS(relativePath string, fs http.FileSystem) IRoutes {111 return engine().StaticFS(relativePath, fs)112}113114// 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.117func Use(middlewares ...HandlerFunc) IRoutes {118 return engine().Use(middlewares...)119}120121// 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.124func Run(addr ...string) (err error) {125 return engine().Run(addr...)126}127128// 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.131func RunTLS(addr string, certFile string, keyFile string) (err error) {132 return engine().RunTLS(addr, certFile, keyFile)133}134135// 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.138func RunUnix(file string) (err error) {139 return engine().RunUnix(file)
1 unmodified line
modified:render/html.go+1 added-2 removed
59 unmodified lines
60func (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 lines
261 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, "")273274 value, ok := c.GetQuery("foo")275 assert.False(t, ok)276 assert.Empty(t, value)
430 unmodified lines
modified:context.go+3 added-3 removed
67 unmodified lines
6869// 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.71func (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 = nil
94 unmodified lines
171 }172 return173}174175// 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.176func (c *Context) MustGet(key string) interface{} {177 if value, exists := c.Get(key); exists {178 return value179 }
63 unmodified lines
243 value, _ := c.GetPostForm(key)244 return value245}246247// 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.250func (c *Context) DefaultPostForm(key, defaultValue string) string {251 if value, ok := c.GetPostForm(key); ok {
317 unmodified lines
modified:errors.go+2 added-2 removed
64 unmodified lines
65 }66 return json67}6869// Implements the json.Marshaller interface69// MarshalJSON implements the json.Marshaller interface70func (msg *Error) MarshalJSON() ([]byte, error) {71 return json.Marshal(msg.JSON())72}73
14 unmodified lines
88 }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 lines
modified:gin_test.go+7 added-7 removed
199 unmodified lines
200}201202func 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", ".")213214 list := router.Routes()
35 unmodified lines
250 }251 t.Errorf("route not found: %v", wantRoute)252}253254func handler_test1(c *Context) {}255func handler_test2(c *Context) {}254func handlerTest1(c *Context) {}255func handlerTest2(c *Context) {}
modified:gin.go+4 added-4 removed
12 unmodified lines
1314 "github.com/gin-gonic/gin/render"15)1617// Framework's version17// Version is Framework's version18const Version = "v1.0rc2"1920var default404Body = []byte("404 page not found")21var default405Body = []byte("405 method not allowed")
124 unmodified lines
146 }147 engine.HTMLRender = render.HTMLProduction{Template: templ}148}149150// Adds handlers for NoRoute. It return a 404 code by default.150// NoRoute adds handlers for NoRoute. It return a 404 code by default.151func (engine *Engine) NoRoute(handlers ...HandlerFunc) {152 engine.noRoute = handlers153 engine.rebuild404Handlers()154}155156// Sets the handlers called when... TODO156// NoMethod sets the handlers called when... TODO157func (engine *Engine) NoMethod(handlers ...HandlerFunc) {158 engine.noMethod = handlers159 engine.rebuild405Handlers()160}161162// 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.165func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {166 engine.RouterGroup.Use(middleware...)
204 unmodified lines
modified:githubapi_test.go+1 added-1 removed
339 unmodified lines
340 }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 lines
modified:logger.go+2 added-2 removed
33 unmodified lines
34 }35 }36}3738// 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.Stdout40func Logger() HandlerFunc {41 return LoggerWithWriter(DefaultWriter)42}4344// 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...46func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {47 var skip map[string]struct{}48
75 unmodified lines
modified:mode.go+4 added-5 removed
3 unmodified lines
45package gin67import (8 "io"8 "os"910 "github.com/gin-gonic/gin/binding"11)
17 unmodified lines
29// output io.Writer.30// To support coloring in Windows use:31// import "github.com/mattn/go-colorable"32// gin.DefaultWriter = colorable.NewColorableStdout()34var DefaultWriter io.Writer = os.Stdout35var DefaultErrorWriter io.Writer = os.Stderr33var DefaultWriter = os.Stdout34var DefaultErrorWriter = os.Stderr3537var ginMode int = debugCode38var modeName string = DebugMode36var ginMode = debugCode37var modeName = DebugMode3839func init() {40 mode := os.Getenv(ENV_GIN_MODE)41 if len(mode) == 0 {
27 unmodified lines
modified:README.md+1 added-1 removed
1 unmodified line
2#Gin Web Framework3<img align="right" src="https://raw.githubusercontent.com/gin-gonic/gin/master/logo.jpg">4[![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin)5[![Coverage Status](https://coveralls.io/repos/gin-gonic/gin/badge.svg?branch=master)](https://coveralls.io/r/gin-gonic/gin?branch=master)6[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/gin)]6[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/gin)](https://goreportcard.com/report/github.com/gin-gonic/gin)7[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin)8[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)910Gin 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 lines
modified:tree_test.go+1 added-1 removed
19 unmodified lines
20 printChildren(child, prefix)21 }22}2324// 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 addressses25var fakeHandlerValue string2627func fakeHandler(val string) HandlersChain {28 return HandlersChain{func(c *Context) {
605 unmodified lines
modified:tree.go+3 added-1 removed
18 unmodified lines
19// 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.21type Params []Param2223// 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.25func (ps Params) Get(name string) (string, bool) {26 for _, entry := range ps {27 if entry.Key == name {
2 unmodified lines
30 }31 return "", false32}3334// 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.36func (ps Params) ByName(name string) (va string) {37 va, _ = ps.Get(name)38 return39}
566 unmodified lines
modified:utils.go+3 added-4 removed
45 unmodified lines
46}4748type H map[string]interface{}4950// Allows type H to be used with xml.Marshal50// MarshalXML allows type H to be used with xml.Marshal51func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {52 start.Name = xml.Name{53 Space: "",54 Local: "map",
87 unmodified lines
142 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