Commit Graph

325 Commits

Author SHA1 Message Date
voidman
690aa2b1b9
feat(binding): support custom struct tag (#2720)
* feat(binding): support custom struct tag

Add function `binding.MapFormWithTag` (#2719)

* doc: add 'bind form-data with custom struct tag'

Add 'Bind form-data request with custom struct and custom tag' section (#2719)

* test(binding): add test for MapFromWithTag
2021-06-30 00:53:56 +08:00
Jeff
fb8a113f8d
ci: add github action workflows (#2596)
* ci: add github action workflows

* test: fixed the TestUnixSocket test on windows (#20)

* ci: add github action workflows (#18)

* Remove .travis.yml

* ci: replace GITTER_ROOM_ID and upload coverage every time you go test

* ci: update coverage using codecov/codecov-action@v1

* Merge branch 'master' into github-actions

* repo: replace travis ci to github actions

* ci: add go version 1.16

* fix: go install requires a specific version

* chore(ci): remove go 1.12 support

* chore(ci): remove os windows-latest

Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-06-23 13:10:49 +08:00
yugu
d7091e7dec
README.md update (#2715)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-05-19 10:57:23 +08:00
y-yagi
5452a1d3ef
Add note about nomsgpack tag to the readme (#2703)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-05-01 14:13:50 +08:00
y-yagi
1acb459c10
Fix example code of Bind Uri (#2710)
Need to pass a string to `gin.H` to show a message correctly.
2021-05-01 13:57:22 +08:00
zzjin
c0418c48e4
Add support go-json, another drop-in json replacement. (#2680)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-04-21 08:45:49 +08:00
thinkerou
ee4de846a8
Remove go1.12 support (#2679)
* Revert "Adding ppc64le architecture support on travis-ci (#2538)"

This reverts commit fca3f95d7c.

* not support go1.12

* fix

* Update errors_test.go

* Update debug.go
2021-04-12 00:29:34 +08:00
Manu MA
bfc8ca285e
feat(engine): add trustedproxies and remoteIP (#2632)
Co-authored-by: Søren L. Hansen <soren@linux2go.dk>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Javier Provecho Fernandez <javiertitan@gmail.com>
2021-04-06 11:37:25 +08:00
Ross Wolf
f3de8132c5
Add mixed param and non-param paths (port of httprouter#329) (#2663)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-04-06 10:49:08 +08:00
Alexander Melentyev
e899771392
chore: Deleted spaces (#2622) 2021-01-27 09:58:21 +08:00
Josep Jesus Bigorra Algaba
46ddd4259c
Fixes to the graceful shutdown example (#2552)
* Change error comparison to use errors.Is() and add a line of whitespace before the if statement on graceful shutdown

* Change from log.Fatalf to log.Printf to ensure the graceful shutdown actually works

Co-authored-by: J. J. Bigorra <josep@prowarehouse.nl>
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-01-13 09:06:12 +08:00
thinkerou
16cd8cdd4e
ci: romove go1.11 for gin1.7 (#2540) 2020-10-25 17:08:30 +08:00
Zasda Yusuf Mikail
d541085b59
Add some missing dots on README (#2519)
Signed-off-by: Zasda Yusuf Mikail <zasdaym@gmail.com>

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-10-16 09:32:10 +08:00
yugu
1f232c7f47
docs:close the body of the response (#2494) 2020-09-09 20:00:44 +08:00
Dennis Cho
b860d8672d
Fix typo (#2489) 2020-09-02 23:15:25 +08:00
森 優太
c6d6df6d5a
Docs: Update README.md Custom Validator sample code (#2448)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-08-01 15:26:29 +08:00
Hiroyuki Tanaka
44e78a78d4
README: Change badge to pkg.go.dev (#2449) 2020-08-01 15:03:33 +08:00
Johnny Dallas
4cabdd303f
Add CustomRecovery builtin middleware (#2322)
* Add CustomRecovery and CustomRecoveryWithWriter methods

* add CustomRecovery example to README

* add test for CustomRecovery

* support RecoveryWithWriter(io.Writer, ...RecoveryFunc)
2020-07-09 09:40:00 +08:00
Miles
5f261fa752
Add a redirect sample for POST method (#2389)
* Add a redirect sample for POST method

Refer to issue https://github.com/gin-gonic/gin/issues/444

* put an empty line before 1396

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-24 11:37:32 +08:00
Anup Kumar Panwar
82b284fd77
uncomment the code (#2362) 2020-05-08 08:50:26 +08:00
bn4t
235898e642
Fix typo (#2358) 2020-05-05 23:20:00 +08:00
Bo-Yi Wu
05464a8f6b
docs: update benchmark result v1.6.3 (#2355) 2020-05-05 16:37:40 +08:00
thinkerou
747efffd2a
chore: update godoc address (#2357) 2020-05-05 14:06:42 +08:00
Shilin Wang
4f208887e1
update set cookie example (#2312)
fix #2308
2020-04-08 23:31:31 +08:00
Igor H. Vieira
c4fd2489ce
Improved the graceful shutdown and restart section and removed… (#2288) 2020-03-22 10:25:35 +08:00
Nikifor Seryakov
1d055af1bc
FileFromFS (#2112)
* Context.FileFromFS added

* Context File and FileFromFS examples at README

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-07 10:23:33 +08:00
Bo-Yi Wu
863ad2d4de
docs(badge): add todo badge (#2240)
fix https://github.com/gin-gonic/gin/issues/2236

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-02-21 16:33:36 +08:00
Andy Pan
07c0f05f24 Renew README to fit the modification of SetCookie method (#2217)
fix #2214
2020-01-23 07:54:08 +08:00
John Bampton
59ab588bf5 Remove broken link from README. (#2198) 2019-12-30 21:55:08 +08:00
Lin Kao-Yuan
9b3477ef9d Update validator to v10 (#2190)
Passed my manual test, output nothing different.
2019-12-20 14:01:58 +08:00
飞雪无情
cc14a770cd upgrade go-validator to v10 for README (#2189) 2019-12-19 11:21:58 +08:00
Lin Kao-Yuan
1b480ed294 Update to currently output (#2188)
Excuse me, I forgot change output in #2186
2019-12-18 21:08:58 +08:00
Lin Kao-Yuan
aee83e040b Fix "Custom Validators" example (#2186)
* Update fixed error code from merged commit

According to [this](874dcfa6c4) merged commit.

* Fixed incorrect testing date.

Original testing date incompatible demo require, can't get expect result.
check_in date need NOT AFTER check_out date.
2019-12-18 09:44:33 +08:00
Victor Castell
77b8344169 Add project to README (#2165)
Add Dkron as user of Gin in the README
2019-12-02 20:59:56 +08:00
thinkerou
3c8e29b53c
drop support govendor (#2148) 2019-11-25 15:42:23 +08:00
BradyBromley
3737520f17 Changed wording for clarity in README.md (#2122) 2019-11-25 11:03:36 +08:00
thinkerou
2ee0e96394 Drop support go1.10 (#2147) 2019-11-24 23:07:56 +08:00
Ildar1111
089016a092 Update README.md (#2106)
* Update README.md

c:\>curl 0.0.0.0:8080
"Failed to connect to 0.0.0.0 port 8080: Address not available"
Connecting to address 0.0.0.0:8080 is not allowed on windows. From http://msdn.microsoft.com/en-us/library/aa923167.aspx

" ... If the address member of the structure specified by the name parameter is
all zeroes, connect will return the error WSAEADDRNOTAVAIL. ..."

* Update README.md

edit comment
2019-10-25 10:03:53 +08:00
John Bampton
4fd3234840 Fix spelling. (#2080) 2019-10-03 07:46:41 +08:00
bullgare
9b9f4fab34 Updated Readme.md: file.Close() for template read (#2068) 2019-09-24 22:18:41 +08:00
bullgare
f45c83c70c Updated Readme.md for serving multiple services (#2067)
Previous version had issues - if one service did not start for any reason, you would never know about it.
2019-09-23 23:48:10 +08:00
Jim Filippou
b80d675864 Added specific installation instructions for Mac (#2011)
Made it more clear for Mac users using Go version 1.8 and greater.
2019-09-05 21:50:54 +08:00
Johnny Dallas
6ece26c7c5 Add Header bind methods to README (#2025) 2019-08-30 10:58:55 +08:00
guonaihong
502c898d75 binding: support unix time (#1980)
* binding: support unix time

ref:#1979

* binding: support unix time

add test file
modify readme

```golang
package main

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

type shareTime struct {
        CreateTime time.Time `form:"createTime" time_format:"unixNano"`
        UnixTime   time.Time `form:"unixTime" time_format:"unix"`
}

func main() {
        r := gin.Default()
        unix := r.Group("/unix")

        testCT := time.Date(2019, 7, 6, 16, 0, 33, 123, time.Local)
        fmt.Printf("%d\n", testCT.UnixNano())

        testUT := time.Date(2019, 7, 6, 16, 0, 33, 0, time.Local)
        fmt.Printf("%d\n", testUT.Unix())

        unix.GET("/nano", func(c *gin.Context) {
                s := shareTime{}

                c.ShouldBindQuery(&s)

                if !testCT.Equal(s.CreateTime) {
                        c.String(500, "want %d got %d", testCT.UnixNano(), s.CreateTime)
                        return
                }

                c.JSON(200, s)
        })

        unix.GET("/sec", func(c *gin.Context) {
                s := shareTime{}

                c.ShouldBindQuery(&s)

                if !testUT.Equal(s.UnixTime) {
                        c.String(500, "want %d got %d", testCT.Unix(), s.UnixTime)
                        return
                }

                c.JSON(200, s)

        })

        r.Run()
}

```

* Contraction variable scope
2019-07-10 13:02:40 +08:00
thinkerou
3f53a58d4a
Add user case: brigade (#1937) 2019-06-29 00:09:53 +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