* 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
* 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>
* 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
* 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>
* Add CustomRecovery and CustomRecoveryWithWriter methods
* add CustomRecovery example to README
* add test for CustomRecovery
* support RecoveryWithWriter(io.Writer, ...RecoveryFunc)
* 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>
* 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.
* 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
``` 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
* 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