Omkar P
44d0dd7092
fix: Add pointer support for url query params ( #3659 ) ( #3666 )
...
The pointer support in url query params (using []*Struct for binding query params) was previously available in Gin, but was removed in commit 0d50ce8
since there wasn't a test case for such a scenario, and so the case block was removed as a redundant one.
2023-11-16 23:46:43 +08:00
thinkerou
1e1f0b1e76
chore: support min go version 1.18 ( #3511 )
...
* chore: min go version 1.18
* fix build tag error
* remove build tag
* fix word
* remove any.go
* replace interface{} instead of any
2023-03-01 10:03:48 +08:00
Heliner
1660995a04
Adjust the position of some functions ( #3385 )
...
Co-authored-by: fredhan <fredhan@futunn.com>
2023-01-17 14:23:54 +08:00
thinkerou
c9b27249fb
chore(yaml): upgrade dependency to v3 version ( #3456 )
...
fixes https://github.com/gin-gonic/gin/issues/3451
fixes https://github.com/gin-gonic/gin/issues/3306
fixes https://github.com/gin-gonic/gin/issues/3362
fixes https://github.com/gin-gonic/gin/issues/2581
2023-01-02 12:40:48 +08:00
Qt
6150c488e7
remove deprecated of package io/ioutil ( #3395 )
2022-11-17 22:35:55 +08:00
Jesse
51aea73ba0
fix: modify interface check way ( #3327 )
2022-10-20 00:49:19 +08:00
hopehook
33ab0fc155
refactor(struct): Remove redundant type conversions ( #3345 )
2022-10-16 09:49:24 +08:00
John Bampton
24a1d2adb9
fix(typo): spelling covert
-> convert
( #3325 )
2022-10-16 09:41:14 +08:00
thinkerou
38eb5acc6b
add v1.8.0 changelog ( #3160 )
2022-05-30 15:16:10 +08:00
thinkerou
4b68a5f12a
chore: update go.mod and remove space from copyright ( #3158 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-28 10:42:28 +08:00
Valentine Oragbakosi
ed03102ef0
[GIN-001] - Add TOML bining for gin ( #3081 )
...
Co-authored-by: GitstartHQ <gitstart@users.noreply.github.com>
2022-05-28 08:34:43 +08:00
Kacper Bąk
c706ace929
fix: removed YODA conditions, removed blank identifier from invalid_obj
( #3129 )
...
* fix: removed YODA conditions, unnecessary binding.binding
* fix: remove BindingBody change
2022-04-23 18:01:03 +08:00
thinkerou
2bde107686
test support go1.18 ( #2990 )
2022-03-21 09:43:17 +08:00
jincheng9
8a0f95cc71
fix: typo ( #2993 )
2021-12-20 17:42:54 +08:00
edebernis
57ede9c95a
Export struct sliceValidateError to allow error casting and rename it as ( #2777 )
...
SliceValidationError
Co-authored-by: Emeric de Bernis <emeric.debernis@adevinta.com>
2021-11-21 21:45:03 +08:00
axiaoxin
1a2bc0e7cb
setted typo fix: There’s no such word as setted
, set
is set, set, setting ( #2886 )
2021-09-30 10:04:28 +08:00
Matthieu MOREL
71f7087097
golangci(lint) : more linters ( #2870 )
2021-09-21 15:22:21 +08:00
Tevic
eab47b5423
fix: check obj type in protobufBinding ( #2851 )
...
* fix: check obj type in protobufBinding
* fix: UnitTest for invalid proto obj
2021-09-07 10:10:32 +08:00
Alexander Melentyev
527d950252
Delete unused arg ( #2834 )
2021-08-21 14:59:17 +08:00
Matthieu MOREL
435a76b735
chore(ci): update dependencies ( #2827 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
2021-08-19 15:46:31 +08:00
Helios
9d2883ef47
update the version of validator in the comment ( #2780 )
...
Co-authored-by: shangyilong <shangyilong@zuoyebang.com>
2021-07-06 16:36:32 +08:00
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
ziheng
e3ee01d185
improve sliceValidateError.Error performance using switch and strings.Builder ( #2765 )
...
fix missing nil pointer check
use simpler switch case
add missing tests
use for-loop instead of range
add benchmark test codes
2021-06-28 22:05:29 +08:00
tyltr
34ce2104ca
optimize code and reduce code cyclomatic complexity ( #2737 )
...
* optimize code and reduce code cyclomatic complexity
* optimize if-condtion
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-06-03 20:12:51 +08:00
heige
97a32b1de3
Optimize code adjust ( #2700 )
...
* setFormMap error of result
* adjust code for TrySet
* error export for type multipart.FileHeader
* code style adjust
* reflect code maping optimize
* Update form_mapping.go
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-06-02 07:35:30 +08:00
iamhesir
0cbb30aa94
Update default validator's docs link ( #2738 )
...
The default validator has upgraded from v8 to v10, but its docs link didn't.
2021-05-26 18:46:13 +08:00
y-yagi
168edcad80
Check multipart file header size on test ( #2716 )
...
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-05-23 11:44:41 +08:00
Qt
215c9ce231
use errors.New to replace fmt.Errorf will much better ( #2707 )
2021-04-28 18:39:09 +08:00
thinkerou
ed6f85c478
build: convert to go:build directives ( #2664 )
2021-03-27 09:09:44 +08:00
wuhuizuo
4bfae4c8c8
Support binding for slice/array obj [Rewrite] ( #2302 )
...
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-01-03 21:43:34 +08:00
Alessandro (Ale) Segala
65ed60ed13
Allow bind with a map[string]string ( #2484 )
...
Co-authored-by: thinkerou <thinkerou@gmail.com>
2020-10-31 07:20:47 +08:00
lantw44
30b5f7e2d7
binding: avoid 2038 problem on 32-bit architectures ( #2450 )
...
Function setTimeField calls strconv.ParseInt with bit size 0 when
parsing Unix time, which means it is equivalent to specifying 32 on
32-bit architectures. This causes the function to suffer from the year
2038 problem. To fix it and keep the behavior the same on both 32-bit
and 64-bit architectures, explicitly specify bit size 64.
Co-authored-by: thinkerou <thinkerou@gmail.com>
2020-08-08 17:31:08 +08:00
John Bampton
cf8b583db4
Fix spelling ( #2451 )
2020-08-04 07:04:06 +08:00
Andy Pan
982daeb1ec
Use zero-copy approach to convert types between string and byte… ( #2206 )
...
* Use zero-copy approach to convert types between string and byte slice
* Rename argument to a eligible one
Benchmark:
BenchmarkBytesConvBytesToStrRaw-4 21003800 70.9 ns/op 96 B/op 1 allocs/op
BenchmarkBytesConvBytesToStr-4 1000000000 0.333 ns/op 0 B/op 0 allocs/op
BenchmarkBytesConvStrToBytesRaw-4 18478059 59.3 ns/op 96 B/op 1 allocs/op
BenchmarkBytesConvStrToBytes-4 1000000000 0.373 ns/op 0 B/op 0 allocs/op
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-01-18 00:32:50 +08:00
Antoine GIRARD
fd8a65b252
Add build tag nomsgpack ( #1852 )
...
* add build tag nomsgpack
* Update copyright
* Update copyright
2020-01-07 11:31:10 +08:00
thinkerou
d5f12ac6d7
use http method constant ( #2155 )
...
* use http method constant
* fix typo
2019-11-29 07:50:49 +08:00
Ngalim Siregar
231ff00d1f
Refactor redirect request in gin.go ( #1970 )
...
* Refactor redirect request in gin.go
* Update http status code
2019-11-26 08:19:30 +08:00
Xudong Cai
e90e2ba9b3
upgrade go-validator to v10 ( #2149 )
...
* upgrade go-validator to v10
* fix fmt
2019-11-25 14:49:45 +08:00
Dmitry Kutakov
db9174ae0c
fix ignore walking on form mapping ( #1942 ) ( #1943 )
2019-11-01 10:47:40 +08:00
Dmitry Kutakov
393a63f3b0
Fix 'errcheck' linter warnings ( #2093 )
2019-10-27 13:58:59 +08:00
ZhangYunHao
8a1bfcfd3b
format errUnknownType ( #2103 )
2019-10-26 14:20:35 +08:00
Dmitry Kutakov
f7becac7bc
Relocate binding body tests ( #2086 )
...
* Relocate binding body tests
Every test file should be related to a tested file.
Remove useless tests.
* Add github.com/stretchr/testify/require package
2019-10-10 16:58:31 +08:00
Krzysztof Szafrański
f38c30a0d2
feat(binding): add DisallowUnknownFields() in gin.Context.BindJSON() ( #2028 )
2019-09-06 13:56:59 +08:00
thinkerou
1acb3fb30a
upgrade validator version to v9 ( #1015 )
...
* upgrade validator version to v9
* Update vendor.json
* Update go.mod
* Update go.sum
* fix
* fix
* fix bug
* Update binding_test.go
* Update validate_test.go
* Update go.sum
* Update go.mod
* Update go.sum
* Update go.mod
* Update go.sum
2019-09-05 21:39:56 +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
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
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
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