Push branch develop into master
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 · parents 7d0b329, 3c3526f · Browse files · 22 files·+135 added−91 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+135 added−91 removed
- other:+135 added−91 removed
Provenance
- Commit
5caaac4- Tree
4859750- Author
Javier Provecho Fernandez <javiertitan@gmail.com>- Committer
Javier Provecho Fernandez <javiertitan@gmail.com>- Parent 1
7d0b329- Parent 2
3c3526f
22 files changed+135 added−91 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:render/render.go+1 added
18 unmodified lines19 _ Render = Data{}20 _ Render = HTML{}21 _ HTMLRender = HTMLDebug{}22 _ HTMLRender = HTMLProduction{}23+ _ Render = YAML{}24 )25 26 func writeContentType(w http.ResponseWriter, value []string) {27 header := w.Header()4 unmodified linesadded:render/yaml.go+29 added
1+// Copyright 2014 Manu Martinez-Almeida. All rights reserved.2+// Use of this source code is governed by a MIT style3+// license that can be found in the LICENSE file.4+5+package render6+7+import (8+ "net/http"9+10+ "gopkg.in/yaml.v2"11+)12+13+type YAML struct {14+ Data interface{}15+}16+17+var yamlContentType = []string{"application/x-yaml; charset=utf-8"}18+19+func (r YAML) Render(w http.ResponseWriter) error {20+ writeContentType(w, yamlContentType)21+22+ bytes, err := yaml.Marshal(r.Data)23+ if err != nil {24+ return err25+ }26+27+ w.Write(bytes)28+ return nil29+}modified:benchmarks_test.go+2 added-1 removed
1 unmodified line2 3 import (4 "html/template"5 "net/http"6+ "os"7 "testing"8 )9 10 func BenchmarkOneRoute(B *testing.B) {25 unmodified lines36 runRequest(B, router, "GET", "/ping")37 }38 39 func Benchmark5Params(B *testing.B) {39- DefaultWriter = newMockWriter()40+ DefaultWriter = os.Stdout41 router := New()42 router.Use(func(c *Context) {})43 router.GET("/param/:param1/:params2/:param3/:param4/:param5", func(c *Context) {})44 runRequest(B, router, "GET", "/param/path/to/parameter/john/12345")114 unmodified linesmodified:context_test.go+13 added-4 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)155 unmodified lines432 assert.Contains(t, w.Body.String(), "func New() *Engine {")433 assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")434 }435 436+// TestContextRenderYAML tests that the response is serialized as YAML437+// and Content-Type is set to application/x-yaml438+func TestContextRenderYAML(t *testing.T) {439+ c, w, _ := CreateTestContext()440+ c.YAML(201, H{"foo": "bar"})441+442+ assert.Equal(t, w.Code, 201)443+ assert.Equal(t, w.Body.String(), "foo: bar\n")444+ assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/x-yaml; charset=utf-8")445+}446+447 func TestContextHeaders(t *testing.T) {448 c, _, _ := CreateTestContext()449 c.Header("Content-Type", "text/plain")450 c.Header("X-Custom", "value")104 unmodified lines555 func TestContextAbortWithStatus(t *testing.T) {556 c, w, _ := CreateTestContext()557 c.index = 4558 c.AbortWithStatus(401)548- c.Writer.WriteHeaderNow()559 560 assert.Equal(t, c.index, abortIndex)561 assert.Equal(t, c.Writer.Status(), 401)562 assert.Equal(t, w.Code, 401)42 unmodified lines605 606 func TestContextAbortWithError(t *testing.T) {607 c, w, _ := CreateTestContext()608 c.AbortWithError(401, errors.New("bad input")).SetMeta("some input")599- c.Writer.WriteHeaderNow()609 610 assert.Equal(t, w.Code, 401)611 assert.Equal(t, c.index, abortIndex)612 assert.True(t, c.IsAborted())94 unmodified linesmodified:context.go+9 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 = nil37 unmodified lines114 // AbortWithStatus calls `Abort()` and writes the headers with the specified status code.115 // For example, a failed attempt to authentificate a request could use: context.AbortWithStatus(401).116 func (c *Context) AbortWithStatus(code int) {117 c.Status(code)118+ c.Writer.WriteHeaderNow()119 c.Abort()120 }121 122 // AbortWithError calls `AbortWithStatus()` and `Error()` internally. This method stops the chain, writes the status code and48 unmodified lines171 }172 return173 }174 174-// 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 246-// 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 {174 unmodified lines426 func (c *Context) XML(code int, obj interface{}) {427 c.Render(code, render.XML{Data: obj})428 }429 430+// YAML serializes the given struct as YAML into the response body.431+func (c *Context) YAML(code int, obj interface{}) {432+ c.Render(code, render.YAML{Data: obj})433+}434+435 // String writes the given string into the response body.436 func (c *Context) String(code int, format string, values ...interface{}) {437 c.Status(code)438 render.WriteString(c.Writer, format, values)130 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+12 added-12 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()1 unmodified line216 assert.Len(t, list, 7)217 assertRoutePresent(t, list, RouteInfo{218 Method: "GET",219 Path: "/favicon.ico",220- Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",220+ Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",221 })222 assertRoutePresent(t, list, RouteInfo{223 Method: "GET",224 Path: "/",225- Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",225+ Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",226 })227 assertRoutePresent(t, list, RouteInfo{228 Method: "GET",229 Path: "/users/",230- Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test2$",230+ Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$",231 })232 assertRoutePresent(t, list, RouteInfo{233 Method: "GET",234 Path: "/users/:id",235- Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test1$",235+ Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest1$",236 })237 assertRoutePresent(t, list, RouteInfo{238 Method: "POST",239 Path: "/users/:id",240- Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handler_test2$",240+ Handler: "^(.*/vendor/)?github.com/gin-gonic/gin.handlerTest2$",241 })242 }243 244 func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) {5 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+5 added-4 removed
8 unmodified lines9 "fmt"10 "math/rand"11 "net/http"12 "net/http/httptest"13+ "os"14 "testing"15 16 "github.com/stretchr/testify/assert"17 )280 unmodified lines298 }299 }300 301 func TestGithubAPI(t *testing.T) {301- DefaultWriter = newMockWriter()302+ DefaultWriter = os.Stdout303 router := Default()304 githubConfigRouter(router)305 306 for _, route := range githubAPI {34 unmodified lines341 }342 if start >= 0 {343 value := fmt.Sprint(rand.Intn(100000))344 params = append(params, Param{344- Key: path[start:len(path)],345+ Key: path[start:],346 Value: value,347 })348 output.WriteString(value)349 }7 unmodified lines357 runRequest(b, router, "GET", "/legacy/issues/search/:owner/:repository/:state/:keyword")358 }359 360 func BenchmarkParallelGithub(b *testing.B) {360- DefaultWriter = newMockWriter()361+ DefaultWriter = os.Stdout362 router := New()363 githubConfigRouter(router)364 365 req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)7 unmodified lines373 })374 }375 376 func BenchmarkParallelGithubDefault(b *testing.B) {376- DefaultWriter = newMockWriter()377+ DefaultWriter = os.Stdout378 router := Default()379 githubConfigRouter(router)380 381 req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)9 unmodified linesmodified:logger_test.go+1 added-1 removed
114 unmodified lines115 assert.Equal(t, w.Body.String(), "{\"error\":\"no authorized\"}\n")116 117 w = performRequest(router, "GET", "/print")118 assert.Equal(t, w.Code, 500)119- assert.Equal(t, w.Body.String(), "hola!")119+ assert.Equal(t, w.Body.String(), "hola!{\"error\":\"this is an error\"}\n")120 }121 122 func TestSkippingPaths(t *testing.T) {123 buffer := new(bytes.Buffer)11 unmodified linesmodified:logger.go+5 added-8 removed
26 unmodified lines27 28 func ErrorLoggerT(typ ErrorType) HandlerFunc {29 return func(c *Context) {30 c.Next()31- // avoid writting if we already wrote into the response body32- if !c.Writer.Written() {33- errors := c.Errors.ByType(typ)34- if len(errors) > 0 {35- c.JSON(-1, errors)31+ errors := c.Errors.ByType(typ)32+ if len(errors) > 0 {33+ c.JSON(-1, errors)36- }34 }35 }36 }37 41-// 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 47-// 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 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+[](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:recovery_test.go+1 added-1 removed
37 unmodified lines38 })39 // RUN40 w := performRequest(router, "GET", "/recovery")41 // TEST42- assert.Equal(t, w.Code, 500) // NOT SURE42+ assert.Equal(t, w.Code, 400)43 }modified: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