mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Fnlb was moved to its own repo: fnproject/lb (#702)
* Fnlb was moved to its own repo: fnproject/lb * Clean up fnlb leftovers * Newer deps
This commit is contained in:
committed by
Reed Allman
parent
4ffa3d5005
commit
d3be603e54
12
vendor/github.com/gin-gonic/gin/binding/binding.go
generated
vendored
12
vendor/github.com/gin-gonic/gin/binding/binding.go
generated
vendored
@@ -4,11 +4,7 @@
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
validator "gopkg.in/go-playground/validator.v8"
|
||||
)
|
||||
import "net/http"
|
||||
|
||||
const (
|
||||
MIMEJSON = "application/json"
|
||||
@@ -35,11 +31,6 @@ type StructValidator interface {
|
||||
// If the struct is not valid or the validation itself fails, a descriptive error should be returned.
|
||||
// Otherwise nil must be returned.
|
||||
ValidateStruct(interface{}) error
|
||||
|
||||
// RegisterValidation adds a validation Func to a Validate's map of validators denoted by the key
|
||||
// NOTE: if the key already exists, the previous validation function will be replaced.
|
||||
// NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation
|
||||
RegisterValidation(string, validator.Func) error
|
||||
}
|
||||
|
||||
var Validator StructValidator = &defaultValidator{}
|
||||
@@ -48,7 +39,6 @@ var (
|
||||
JSON = jsonBinding{}
|
||||
XML = xmlBinding{}
|
||||
Form = formBinding{}
|
||||
Query = queryBinding{}
|
||||
FormPost = formPostBinding{}
|
||||
FormMultipart = formMultipartBinding{}
|
||||
ProtoBuf = protobufBinding{}
|
||||
|
||||
27
vendor/github.com/gin-gonic/gin/binding/binding_test.go
generated
vendored
27
vendor/github.com/gin-gonic/gin/binding/binding_test.go
generated
vendored
@@ -67,18 +67,6 @@ func TestBindingForm2(t *testing.T) {
|
||||
"", "")
|
||||
}
|
||||
|
||||
func TestBindingQuery(t *testing.T) {
|
||||
testQueryBinding(t, "POST",
|
||||
"/?foo=bar&bar=foo", "/",
|
||||
"foo=unused", "bar2=foo")
|
||||
}
|
||||
|
||||
func TestBindingQuery2(t *testing.T) {
|
||||
testQueryBinding(t, "GET",
|
||||
"/?foo=bar&bar=foo", "/?bar2=foo",
|
||||
"foo=unused", "")
|
||||
}
|
||||
|
||||
func TestBindingXML(t *testing.T) {
|
||||
testBodyBinding(t,
|
||||
XML, "xml",
|
||||
@@ -216,21 +204,6 @@ func testFormBinding(t *testing.T, method, path, badPath, body, badBody string)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testQueryBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
||||
b := Query
|
||||
assert.Equal(t, b.Name(), "query")
|
||||
|
||||
obj := FooBarStruct{}
|
||||
req := requestWithBody(method, path, body)
|
||||
if method == "POST" {
|
||||
req.Header.Add("Content-Type", MIMEPOSTForm)
|
||||
}
|
||||
err := b.Bind(req, &obj)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, obj.Foo, "bar")
|
||||
assert.Equal(t, obj.Bar, "foo")
|
||||
}
|
||||
|
||||
func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
||||
assert.Equal(t, b.Name(), name)
|
||||
|
||||
|
||||
5
vendor/github.com/gin-gonic/gin/binding/default_validator.go
generated
vendored
5
vendor/github.com/gin-gonic/gin/binding/default_validator.go
generated
vendored
@@ -28,11 +28,6 @@ func (v *defaultValidator) ValidateStruct(obj interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *defaultValidator) RegisterValidation(key string, fn validator.Func) error {
|
||||
v.lazyinit()
|
||||
return v.validate.RegisterValidation(key, fn)
|
||||
}
|
||||
|
||||
func (v *defaultValidator) lazyinit() {
|
||||
v.once.Do(func() {
|
||||
config := &validator.Config{TagName: "binding"}
|
||||
|
||||
6
vendor/github.com/gin-gonic/gin/binding/form.go
generated
vendored
6
vendor/github.com/gin-gonic/gin/binding/form.go
generated
vendored
@@ -6,8 +6,6 @@ package binding
|
||||
|
||||
import "net/http"
|
||||
|
||||
const defaultMemory = 32 * 1024 * 1024
|
||||
|
||||
type formBinding struct{}
|
||||
type formPostBinding struct{}
|
||||
type formMultipartBinding struct{}
|
||||
@@ -20,7 +18,7 @@ func (formBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return err
|
||||
}
|
||||
req.ParseMultipartForm(defaultMemory)
|
||||
req.ParseMultipartForm(32 << 10) // 32 MB
|
||||
if err := mapForm(obj, req.Form); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +44,7 @@ func (formMultipartBinding) Name() string {
|
||||
}
|
||||
|
||||
func (formMultipartBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
if err := req.ParseMultipartForm(defaultMemory); err != nil {
|
||||
if err := req.ParseMultipartForm(32 << 10); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mapForm(obj, req.MultipartForm.Value); err != nil {
|
||||
|
||||
10
vendor/github.com/gin-gonic/gin/binding/json.go
generated
vendored
10
vendor/github.com/gin-gonic/gin/binding/json.go
generated
vendored
@@ -5,13 +5,8 @@
|
||||
package binding
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin/json"
|
||||
)
|
||||
|
||||
var (
|
||||
EnableDecoderUseNumber = false
|
||||
)
|
||||
|
||||
type jsonBinding struct{}
|
||||
@@ -22,9 +17,6 @@ func (jsonBinding) Name() string {
|
||||
|
||||
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
decoder := json.NewDecoder(req.Body)
|
||||
if EnableDecoderUseNumber {
|
||||
decoder.UseNumber()
|
||||
}
|
||||
if err := decoder.Decode(obj); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
4
vendor/github.com/gin-gonic/gin/binding/msgpack.go
generated
vendored
4
vendor/github.com/gin-gonic/gin/binding/msgpack.go
generated
vendored
@@ -17,8 +17,12 @@ func (msgpackBinding) Name() string {
|
||||
}
|
||||
|
||||
func (msgpackBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
|
||||
if err := codec.NewDecoder(req.Body, new(codec.MsgpackHandle)).Decode(&obj); err != nil {
|
||||
//var decoder *codec.Decoder = codec.NewDecoder(req.Body, &codec.MsgpackHandle)
|
||||
//if err := decoder.Decode(&obj); err != nil {
|
||||
return err
|
||||
}
|
||||
return validate(obj)
|
||||
|
||||
}
|
||||
|
||||
23
vendor/github.com/gin-gonic/gin/binding/query.go
generated
vendored
23
vendor/github.com/gin-gonic/gin/binding/query.go
generated
vendored
@@ -1,23 +0,0 @@
|
||||
// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type queryBinding struct{}
|
||||
|
||||
func (queryBinding) Name() string {
|
||||
return "query"
|
||||
}
|
||||
|
||||
func (queryBinding) Bind(req *http.Request, obj interface{}) error {
|
||||
values := req.URL.Query()
|
||||
if err := mapForm(obj, values); err != nil {
|
||||
return err
|
||||
}
|
||||
return validate(obj)
|
||||
}
|
||||
42
vendor/github.com/gin-gonic/gin/binding/validate_test.go
generated
vendored
42
vendor/github.com/gin-gonic/gin/binding/validate_test.go
generated
vendored
@@ -6,12 +6,9 @@ package binding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
validator "gopkg.in/go-playground/validator.v8"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -193,42 +190,3 @@ func TestValidatePrimitives(t *testing.T) {
|
||||
assert.NoError(t, validate(&str))
|
||||
assert.Equal(t, str, "value")
|
||||
}
|
||||
|
||||
// structCustomValidation is a helper struct we use to check that
|
||||
// custom validation can be registered on it.
|
||||
// The `notone` binding directive is for custom validation and registered later.
|
||||
type structCustomValidation struct {
|
||||
Integer int `binding:"notone"`
|
||||
}
|
||||
|
||||
// notOne is a custom validator meant to be used with `validator.v8` library.
|
||||
// The method signature for `v9` is significantly different and this function
|
||||
// would need to be changed for tests to pass after upgrade.
|
||||
// See https://github.com/gin-gonic/gin/pull/1015.
|
||||
func notOne(
|
||||
v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value,
|
||||
field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string,
|
||||
) bool {
|
||||
if val, ok := field.Interface().(int); ok {
|
||||
return val != 1
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestRegisterValidation(t *testing.T) {
|
||||
// This validates that the function `notOne` matches
|
||||
// the expected function signature by `defaultValidator`
|
||||
// and by extension the validator library.
|
||||
err := Validator.RegisterValidation("notone", notOne)
|
||||
// Check that we can register custom validation without error
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Create an instance which will fail validation
|
||||
withOne := structCustomValidation{Integer: 1}
|
||||
errs := validate(withOne)
|
||||
|
||||
// Check that we got back non-nil errs
|
||||
assert.NotNil(t, errs)
|
||||
// Check that the error matches expactation
|
||||
assert.Error(t, errs, "", "", "notone")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user