Commit Graph

1322 Commits

Author SHA1 Message Date
bbiao f65018d7b1 Bugfix for the FullPath feature (#1919)
* worked with more complex situations
 * the original pr not work when and a short route with the same prefix
 to some already added routes
2019-06-28 23:54:52 +08:00
Dan Markham fc920dc561 Drop Support for go1.8 and go1.9 (#1933) 2019-06-28 23:43:07 +08:00
srt180 46acb91996 modify readme example code (#1961) 2019-06-28 09:34:14 +08:00
guonaihong 31342fc03f fix README.md code bug and Change map to gin.H (#1963)
``` go
func main() {
        r := gin.Default()

        // r.GET("/JSONP?callback=x", func(c *gin.Context) { // old
        r.GET("/JSONP", func(c *gin.Context) {    // new
                data := gin.H{
                        "foo": "bar",
                }

                //callback is x
                // Will output  :   x({\"foo\":\"bar\"})
                c.JSONP(http.StatusOK, data)
        })

        // Listen and serve on 0.0.0.0:8080
        r.Run(":8080")
}

// client
// curl http://127.0.0.1:8080/JSONP?callback=x

// old output
// 404 page not found

// new output
// x({"foo":"bar"})

```

Most of the sample code in the documentation map[string]interface{} is represented by gin.H.
gin.H is a very important place for me to like gin, can write a lot less code
2019-06-28 09:25:19 +08:00
guonaihong f98b339b77 support bind http header param #1956 (#1957)
* support bind http header param #1956

update #1956
```
package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

type testHeader struct {
	Rate   int    `header:"Rate"`
	Domain string `header:"Domain"`
}

func main() {
	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		h := testHeader{}

		if err := c.ShouldBindHeader(&h); err != nil {
			c.JSON(200, err)
		}

		fmt.Printf("%#v\n", h)
		c.JSON(200, gin.H{"Rate": h.Rate, "Domain": h.Domain})
	})

	r.Run()

// client
// curl -H "rate:300" -H "domain:music" 127.0.0.1:8080/
// output
// {"Domain":"music","Rate":300}
}
```

* add unit test

* Modify the code to get the http header

When the http header is obtained in the standard library,
the key value will be modified by the CanonicalMIMEHeaderKey function,
and finally the value of the http header will be obtained from the map.
As follows.
```go
func (h MIMEHeader) Get(key string) string {
        // ...
         v := h[CanonicalMIMEHeaderKey(key)]
        // ...
}
```

This pr also follows this modification

* Thanks to vkd for suggestions, modifying code

* Increase test coverage

env GOPATH=`pwd` go test github.com/gin-gonic/gin/binding -coverprofile=cover.prof
ok  	github.com/gin-gonic/gin/binding	0.015s	coverage: 100.0% of statements

* Rollback check code

* add use case to README.md
2019-06-27 12:47:45 +08:00
Dmitry Kutakov 09a3650c97 binding: add support of multipart multi files (#1878) (#1949)
* binding: add support of multipart multi files (#1878)

* update readme: add multipart file binding
2019-06-18 19:49:10 +08:00
田欧 75b9d2bed7
Attempt to fix PostForm cache bug (#1931) 2019-06-12 21:07:15 +08:00
田欧 73c4633943
use context instead of x/net/context (#1922) 2019-06-03 22:52:33 +08:00
田欧 bfecd88fc4
use sse v0.1.0 (#1923) 2019-06-03 22:42:25 +08:00
Bo-Yi Wu 08b52e5394 feat: improve get post data. (#1920)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-06-02 17:24:41 +08:00
Bo-Yi Wu 4b6df417e4 chore: improve GetQueryMap performance. (#1918)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-05-29 14:54:55 +08:00
ijaa 233a3e493d add context param query cache (#1450) 2019-05-29 11:25:02 +08:00
Samuel Abreu 6e320c97e8 Fix context.Params race condition on Copy() (#1841)
* Fix context.Params race condition on Copy()

Using context.Param(key) on a context.Copy inside a goroutine
may lead to incorrect value on a high load, where another request
overwrite a Param

* Using waitgroup to wait asynchronous test case
2019-05-27 14:04:30 +08:00
Roman Zaynetdinov 35e33d3638 Hold matched route full path in the Context (#1826)
* Return nodeValue from getValue method

* Hold route full path in the Context

* Add small example
2019-05-26 08:20:21 +08:00
ZYunH 78a8b5c9d5 Fix typo (#1913) 2019-05-23 11:37:34 +08:00
itcloudy 0cbf290302 use encode replace json marshal increase json encoder speed (#1546) 2019-05-22 07:48:50 +08:00
Kirill Motkov b1d607a899 Some code improvements (#1909)
* strings.ToLower comparison changed to strings.EqualFold.
* Rewrite switch statement with only one case as if.
2019-05-21 23:08:52 +08:00
guonaihong 8ee9d959a0 Now you can parse the inline lowercase start structure (#1893)
* Now you can parse the inline lowercase start structure

package main

import (
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
)

type appkey struct {
	Appkey string `json:"appkey" form:"appkey"`
}

type Query struct {
	Page int `json:"page" form:"page"`
	Size int `json:"size" form:"size"`
	appkey
}

func main() {

	router := gin.Default()
	router.POST("/login", func(c *gin.Context) {

		var q2 Query

		if c.ShouldBindQuery(&q2) == nil {
			c.JSON(200, &q2)
		}
	})
	router.Run(":8088")
}

http client:

old:
curl -X POST "127.0.0.1:8088/login?appkey=china&page=1&size=10"
{"page":1,"size":10,"appkey":""}

now:
curl -X POST "127.0.0.1:8088/login?appkey=china&page=1&size=10"
{"page":1,"size":10,"appkey":"china"}

* Modify judgment conditions
2019-05-13 10:17:31 +08:00
田欧 965d74cebb
add dev version (#1886)
* add dev version

* Update version.go

* Update version.go
2019-05-12 18:47:27 +08:00
Uwe Dauernheim 04eecb1283 Use DefaultWriter and DefaultErrorWriter for debug messages (#1891)
Aligns behaviour according to documentation.
2019-05-10 14:03:25 +08:00
田欧 5a7e3095b2 Update README.md about go version (#1885) 2019-05-08 11:10:34 +08:00
田欧 b75d67cd51
update vendor: ugorji/go (#1879)
* update vendor: ugorji/go

* fix
2019-05-07 19:43:05 +08:00
Dan Markham b6425689dc Clean the Request Path early (#1817)
This will reduce the number of times we have todo a redirect.
and allow multiple slashes in path to be routed!
fixes #1644
2019-05-07 19:32:35 +08:00
Dmitry Kutakov 66d2c30c54 binding: move tests of mapping to separate test file (#1842)
* move tests of mapping to separate test file

make 100% coverage of form_mapping.go from form_mapping_test.go file

* fix tests for go 1.6

go 1.6 doesn't support `t.Run(...)` subtests
2019-05-07 19:06:55 +08:00
Dan Markham 094f9a9105 v1.4.0 + #1631 (remove go1.6/go1,7 support) (#1851)
* remove go1.6 support

* remove build tag

* remove todo

* remove go1.6 support: https://github.com/gin-gonic/gin/pull/1383/commits

* update readme

* remove go1.7 support

* fix embedmd error

* test

* revert it

* revert it

* remove context_17

* add pusher test

* v1.4.0 rc1
2019-05-07 18:32:32 +08:00
DeathKing 202f8fc58a Fix a typo syscanll.SIGTERM -> syscall.SIGTERM (#1868) 2019-04-24 20:21:41 +08:00
John Bampton 11407e73ad Fix spelling. (#1861) 2019-04-22 23:11:57 +08:00
Abhishek Chanda f9de6049cb Remove contents of the Authorization header while dumping requests (#1836)
This PR replaces the contents of that header with a *. This prevents
credential leak in logs.
2019-04-18 10:45:37 +08:00
Eason Lin ffcbe77b1e chore(readme): rollback readme (#1846)
#1844 #1838 
Keep the documentation in readme until full available on the new website.
2019-04-06 21:48:33 +08:00
Dmitry Kutakov 2e915f4e50 refactor(form_mapping.go): mapping multipart request (#1829)
* refactor(form_mapping.go): mapping multipart request

* add checkers for a types to match with the setter interface

* form_mapping.go: rename method name on setter interface, add comments

* fix style of comments
2019-04-02 09:01:34 +08:00
Dan Markham ce20f107f5 Truncate Latency precision in long running request (#1830)
fixes #1823
2019-03-28 14:14:00 +08:00
田欧 1d462bbe37
chore: update ginS (#1822) 2019-03-21 15:12:06 +08:00
田欧 0c1f3c4e81 chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
Sai b40d4c175c IsTerm flag should not be affected by DisableConsoleColor method. (#1802)
* IsTerm flag should not be affected by DisableConsoleColor method.

* change public property to private
2019-03-18 11:12:30 +08:00
Boyi Wu c16bfa7949 update for supporting file binding (#1264)
update for supporting multipart form and file binding 

example:
```
type PhoptUploadForm struct {
	imgData    *multipart.FileHeader `form:"img_data" binding:"required"`
	ProjectID   string `form:"project_id" binding:"required"`
	Description string `form:"description binding:"required"`
}
```


ref: https://github.com/gin-gonic/gin/issues/1263
2019-03-18 10:16:34 +08:00
sekky0905 bcf36ade9f Remove sudo setting from travis.yml (#1816) 2019-03-16 16:09:10 +08:00
David Zhang 05b5c3ba74 Doc: fix gin example notice syntax (#1814) 2019-03-15 15:39:34 +08:00
Sai 242a2622c8 Fix Japanese text hiragana -> kanji (#1812) 2019-03-14 16:26:51 +08:00
Dmitry Kutakov 483f828bce add support arrays on mapping (#1797)
* add support arrays on mapping

* not allow default value on array mapping
2019-03-14 13:34:56 +08:00
田欧 cab0749b4f
chore: update readme (#1793)
* update readme

* add multi-language version doc link

* add multi-language version doc link

* update readme

* update

* update readme

* update readme

* update readme
2019-03-14 13:23:35 +08:00
田欧 e5261480fd
chore(readme.md): fix invalid link (#1807) 2019-03-12 14:01:12 +08:00
Sai 4a23c4f7b9 fix #1804 which is caused by calling middleware twice. (#1805)
Fix: https://github.com/gin-gonic/gin/issues/1804

`allNoRoute` contains middlewares such as `gin.Logger`, `gin.Recovery`, so on.  The correct code is to use `noRoute`.

cc: @MetalBreaker
2019-03-11 10:52:47 +08:00
田欧 70a0aba3e4
travisci: use go module when go11+ (#1800) 2019-03-08 23:18:52 +08:00
Sai f7079a861e Delete dupilicated test (#1801) 2019-03-08 19:44:39 +08:00
Adam Zielinski 3dc247893e make context.Keys available as LogFormatterParams (#1779)
* make context available as LogFormatterParams

* pass context Keys to LogFormatterParams

* update logger test to check for Key param
2019-03-07 09:47:31 +08:00
Riverside 057f63b1bb spell check (#1796)
* spell check

* variable path collides with imported package name

* spell check
2019-03-05 09:41:37 +08:00
田欧 a5dda62cdc
chore: use internal/json (#1791) 2019-03-05 06:46:18 +08:00
Dmitry Kutakov 805b2d4904 add support time.Duration on mapping (#1794) 2019-03-04 11:37:46 +08:00
Kumar McMillan f8f1459619 Fix URL to starter template in the docs (#1795) 2019-03-04 08:06:46 +08:00
田欧 df366c7840
chore: update go mod package (#1792) 2019-03-04 07:28:03 +08:00