gin/binding/query.go
Krzysztof Szafrański b626f63906 Add support for contextual validation
By passing the Gin context to bindings, custom validators can take
advantage of the information in the context.
2021-11-05 18:28:46 +01:00

29 lines
653 B
Go

// 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 (
"context"
"net/http"
)
type queryBinding struct{}
func (queryBinding) Name() string {
return "query"
}
func (b queryBinding) Bind(req *http.Request, obj interface{}) error {
return b.BindContext(context.Background(), req, obj)
}
func (queryBinding) BindContext(ctx context.Context, req *http.Request, obj interface{}) error {
values := req.URL.Query()
if err := mapForm(obj, values); err != nil {
return err
}
return validateContext(ctx, obj)
}