Skip to content
Myr

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

22 files+135 added−91 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:render/render.go+1 added
18 unmodified lines
19 _ Render = Data{}20 _ Render = HTML{}21 _ HTMLRender = HTMLDebug{}22 _ HTMLRender = HTMLProduction{}23 _ Render = YAML{}24)2526func writeContentType(w http.ResponseWriter, value []string) {27 header := w.Header()
4 unmodified lines
added: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.45package render67import (8 "net/http"910 "gopkg.in/yaml.v2"11)1213type YAML struct {14 Data interface{}15}1617var yamlContentType = []string{"application/x-yaml; charset=utf-8"}1819func (r YAML) Render(w http.ResponseWriter) error {20 writeContentType(w, yamlContentType)2122 bytes, err := yaml.Marshal(r.Data)23 if err != nil {24 return err25 }2627 w.Write(bytes)28 return nil29}
modified:benchmarks_test.go+2 added-1 removed
1 unmodified line
23import (4 "html/template"5 "net/http"6 "os"7 "testing"8)910func BenchmarkOneRoute(B *testing.B) {
25 unmodified lines
36 runRequest(B, router, "GET", "/ping")37}3839func 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 lines
modified:context_test.go+13 added-4 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)
155 unmodified lines
432 assert.Contains(t, w.Body.String(), "func New() *Engine {")433 assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/plain; charset=utf-8")434}435436// TestContextRenderYAML tests that the response is serialized as YAML437// and Content-Type is set to application/x-yaml438func TestContextRenderYAML(t *testing.T) {439 c, w, _ := CreateTestContext()440 c.YAML(201, H{"foo": "bar"})441442 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}446447func TestContextHeaders(t *testing.T) {448 c, _, _ := CreateTestContext()449 c.Header("Content-Type", "text/plain")450 c.Header("X-Custom", "value")
104 unmodified lines
555func TestContextAbortWithStatus(t *testing.T) {556 c, w, _ := CreateTestContext()557 c.index = 4558 c.AbortWithStatus(401)548 c.Writer.WriteHeaderNow()559560 assert.Equal(t, c.index, abortIndex)561 assert.Equal(t, c.Writer.Status(), 401)562 assert.Equal(t, w.Code, 401)
42 unmodified lines
605606func TestContextAbortWithError(t *testing.T) {607 c, w, _ := CreateTestContext()608 c.AbortWithError(401, errors.New("bad input")).SetMeta("some input")599 c.Writer.WriteHeaderNow()609610 assert.Equal(t, w.Code, 401)611 assert.Equal(t, c.index, abortIndex)612 assert.True(t, c.IsAborted())
94 unmodified lines
modified:context.go+9 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
37 unmodified lines
114// 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).116func (c *Context) AbortWithStatus(code int) {117 c.Status(code)118 c.Writer.WriteHeaderNow()119 c.Abort()120}121122// AbortWithError calls `AbortWithStatus()` and `Error()` internally. This method stops the chain, writes the status code and
48 unmodified lines
171 }172 return173}174174// 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}246246// 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 {
174 unmodified lines
426func (c *Context) XML(code int, obj interface{}) {427 c.Render(code, render.XML{Data: obj})428}429430// YAML serializes the given struct as YAML into the response body.431func (c *Context) YAML(code int, obj interface{}) {432 c.Render(code, render.YAML{Data: obj})433}434435// String writes the given string into the response body.436func (c *Context) String(code int, format string, values ...interface{}) {437 c.Status(code)438 render.WriteString(c.Writer, format, values)
130 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+12 added-12 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()
1 unmodified line
216 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}243244func assertRoutePresent(t *testing.T, gotRoutes RoutesInfo, wantRoute RouteInfo) {
5 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+5 added-4 removed
8 unmodified lines
9 "fmt"10 "math/rand"11 "net/http"12 "net/http/httptest"13 "os"14 "testing"1516 "github.com/stretchr/testify/assert"17)
280 unmodified lines
298 }299}300301func TestGithubAPI(t *testing.T) {301 DefaultWriter = newMockWriter()302 DefaultWriter = os.Stdout303 router := Default()304 githubConfigRouter(router)305306 for _, route := range githubAPI {
34 unmodified lines
341 }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 lines
357 runRequest(b, router, "GET", "/legacy/issues/search/:owner/:repository/:state/:keyword")358}359360func BenchmarkParallelGithub(b *testing.B) {360 DefaultWriter = newMockWriter()361 DefaultWriter = os.Stdout362 router := New()363 githubConfigRouter(router)364365 req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)
7 unmodified lines
373 })374}375376func BenchmarkParallelGithubDefault(b *testing.B) {376 DefaultWriter = newMockWriter()377 DefaultWriter = os.Stdout378 router := Default()379 githubConfigRouter(router)380381 req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)
9 unmodified lines
modified:logger_test.go+1 added-1 removed
114 unmodified lines
115 assert.Equal(t, w.Body.String(), "{\"error\":\"no authorized\"}\n")116117 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}121122func TestSkippingPaths(t *testing.T) {123 buffer := new(bytes.Buffer)
11 unmodified lines
modified:logger.go+5 added-8 removed
26 unmodified lines
2728func 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}3741// 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}4347// 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 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)](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:recovery_test.go+1 added-1 removed
37 unmodified lines
38 })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 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