Commit Graph

57 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
thinkerou
521d06c81d support bind uri param (#1612)
* support bind uri (1)

* uri binding successful run

* fix vet warning: github.com/gin-gonic/gin/internal.Param composite literal uses unkeyed fields

* fix code style

* update function name

* fix test function signature

* add test for CanSet

* update readme and add test case

* remove internal.Params

* add coverage

* fix warning
2018-11-22 09:29:48 +08:00
Gordon Tyler
8cb390f8fe Yaml binding (#1618)
* Add YAML binding for application/x-yaml.

* Add YAML binding methods to Context.

* Review fixes.

* Revert accidentally removed import.
2018-11-06 09:49:45 +08:00
Barnabus
7a374f9a47 Fix typos (#1626) 2018-11-05 14:17:04 +08:00
田欧
cdd02fa9d6 update error(err) to err (#1416)
the pull request update `return error(err)` to `return err`, and remove `kindOfData`.
2018-07-01 21:10:48 +08:00
JINNOUCHI Yasushi
995fa8e9ce Fix #216: Enable to call binding multiple times in some formats (#1341)
* Add interface to read body bytes in binding

* Add BindingBody implementation for some binding

* Fix to use `BindBodyBytesKey` for key

* Revert "Fix to use `BindBodyBytesKey` for key"

This reverts commit 2c82901ceab6ae53730a3cfcd9839bee11a08f13.

* Use private-like key for body bytes

* Add tests for BindingBody & ShouldBindBodyWith

* Add note for README

* Remove redundant space between sentences
2018-05-11 10:33:33 +08:00
Suhas Karanth
6d913fc343 fix(binding): Expose validator engine used by the default Validator (#1277)
* fix(binding): Expose validator engine used by the default Validator

- Add func ValidatorEngine for returning the underlying validator engine used
  in the default StructValidator implementation.
- Remove the function RegisterValidation from the StructValidator interface
  which made it immpossible to use a StructValidator implementation without the
  validator.v8 library.
- Update and rename test for registering validation
  Test{RegisterValidation => ValidatorEngine}.
- Update readme and example for registering custom validation.
- Add example for registering struct level validation.
- Add documentation for the following binding funcs/types:
  - Binding interface
  - StructValidator interface
  - Validator instance
  - Binding implementations
  - Default func

* fix(binding): Move validator engine getter inside interface

* docs: rm date cmd from custom validation demo
2018-03-29 14:33:07 +08:00
田欧
b7e8a6b9b0 style(import): not use aliase when import package (#1146) 2017-10-29 13:12:22 +01:00
Suhas Karanth
26c3f42095 feat(binding): add support for custom validator / validation tags (#1068)
* feat(binding): Add support for custom validation tags

* docs: Add example for custom validation tag

* test(binding): Add test for registering custom validation
2017-08-27 09:37:39 +02:00
Eason Lin
c19aa0598b feat(context): add BindQuery func (#1029)
* feat(context): add BindQuery func, only parse/bind the query string params.

* docs(readme): add BindQuery section.

* docs(readme): fix import.

* docs(readme): separate import
2017-07-19 09:50:05 +02:00
田欧
4a2b55037f delete else keyword (#945) 2017-06-12 21:36:37 -05:00
Harindu Perera
5be2123c1a Added support for MessagePack binding and rendering (#808)
Added deps to vendor.json and fixed rendering bug
2017-02-23 22:08:37 +08:00
Javier Provecho Fernandez
e5339a3f4d Merge branch 'new-binding-validator' of https://github.com/zhing/gin into zhing-new-binding-validator
Conflicts:
	binding/binding.go
	binding/binding_test.go
2015-10-02 10:42:58 +02:00
zhing
04917e8307 correct the mime type to x-protobuf 2015-07-18 15:18:01 +08:00
zhing
9d644d22e0 add protobuf binding for gin 2015-07-12 17:42:39 +08:00
Manu Mtz-Almeida
4194adce4c Adds additional bindings for multipart and form 2015-07-03 04:20:00 +02:00
Manu Mtz-Almeida
0c9f086b74 Renames Validate() to validate() 2015-05-31 16:30:00 +02:00
Manu Mtz-Almeida
fecde9fed6 Refactors binding validation 2015-05-31 16:18:50 +02:00
Manu Mtz-Almeida
9584e4ea5c Fix for #310 2015-05-29 20:34:41 +02:00
Manu Mtz-Almeida
ec1ce34d32 Merge branch 'multipart-form-data-fix' of https://github.com/konjoot/gin
- the merge was manually modified before committing.
2015-05-26 16:47:10 +02:00
Maksimov Sergey
e46f4980b9 Restored support of multipart/form-data 2015-05-26 15:21:35 +03:00
Manu Mtz-Almeida
8549810e2e Using "validator.v5" 2015-05-22 16:46:21 +02:00
Manu Mtz-Almeida
f414648384 - More unit tests
- Improves HTML debug render
- InputHolder removed
- More debug logs
2015-05-05 15:06:38 +02:00
Manu Mtz-Almeida
0a192fb0fa Tons of unit tests 2015-04-09 12:15:02 +02:00
Manu Mtz-Almeida
ee3b67eda1 Experimenting with new validation library!!! 2015-04-07 12:30:16 +02:00
Manu Mtz-Almeida
d4413b6e91 Refactors binding module 2015-03-31 17:51:10 +02:00
Manu Mtz-Almeida
3e3ced70d4 Using log.Panic instead 2015-03-23 05:50:10 +01:00
Javier Provecho Fernandez
51599d3c0a Merge branch 'develop' of github.com:gin-gonic/gin into develop 2015-03-08 15:53:06 +01:00
Aleksandr Didenko
0fb7bed1c0 Added support multipart/form-data #109 2015-03-08 15:43:37 +01:00
Javier Provecho Fernandez
1333a65081 Merge pull request #217 from ethankan/develop
Added support for unsigned integers in binding parameters of form posts....
2015-03-08 14:36:21 +01:00
Javier Provecho Fernandez
0f46ae2b81 Merge pull request #224 from zazab/bind-check-sub-structs
Add validating sub structures
2015-03-08 14:33:22 +01:00
Evgeny Persienko
b537c5d15e Add slice elements check for not required slice 2015-02-20 14:33:50 +06:00
Evgeny Persienko
f145e435c7 Add validating sub structures 2015-02-20 11:46:24 +06:00
Ethan Kan
70f280f880 Added support for unsigned integers in binding parameters of form posts. Also changed parsing of integer fields to take into account the size of the fields. 2015-02-09 15:13:05 -08:00
Javier Provecho Fernandez
5dad47bca2 Merge pull request #188 from gin-gonic/fix-binding
Fix unexported field detection
2015-02-07 14:38:40 +01:00
Javier Provecho Fernandez
d936320e0e Sync master into develop
- Add 265faff4ba
- Update "github.com/julienschmidt/httprouter" version in Godeps
- Add 28b9ff9e34
2015-02-04 12:56:19 +01:00
Javier Provecho Fernandez
6d92063b99 Fix unexported field detection 2015-01-01 16:22:02 +01:00
Javier Provecho Fernandez
dcad0df8f7 Fix binding.go panic 2014-11-11 08:43:48 +01:00
Andrey Smirnov
e36f2945bb Validate should ignore unexported struct fields. 2014-10-07 01:52:18 +04:00
Jimmy Pettersson
c4237c363c Merge remote-tracking branch 'upstream/master' into validate 2014-09-17 11:45:55 +02:00