mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-24 05:55:25 +08:00
* ci: update golangci-lint configuration and lint settings - Update golangci-lint to version 2 - Enable new linters and adjust existing ones - Update lint settings across multiple test files - Remove unused struct and variable checks - Add new lint exclusions for generated code and specific directories Signed-off-by: Flc <four_leaf_clover@foxmail.com> * ci(github): update golangci-lint-action to v8 and lint version to v2.3.4 Signed-off-by: Flc <four_leaf_clover@foxmail.com> * ci: downgrade golangci-lint to v2.1.6 Signed-off-by: Flc <four_leaf_clover@foxmail.com> * ci(golangci): add gofumpt linter and fix related issues- Added gofumpt linter to .golangci.yml Signed-off-by: Flc <four_leaf_clover@foxmail.com> * test: ignore testifylint and gofumpt lints in specific test cases Signed-off-by: Flc <four_leaf_clover@foxmail.com> * build(deps): remove golang.org/x/lint - Remove golang.org/x/lint package from go.mod - Update related dependencies in go.sum Signed-off-by: flc1125 <four_leaf_clover@foxmail.com> * build(deps): downgrade golang.org/x/mod and golang.org/x/tools - Downgrade golang.org/x/mod from v0.24.0 to v0.18.0 - Downgrade golang.org/x/tools from v0.33.0 to v.22.0 These changes are made to address compatibility issues with the current project setup. Signed-off-by: flc1125 <four_leaf_clover@foxmail.com> --------- Signed-off-by: Flc <four_leaf_clover@foxmail.com> Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
// Copyright 2014 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 (
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
const defaultMemory = 32 << 20
|
|
|
|
type (
|
|
formBinding struct{}
|
|
formPostBinding struct{}
|
|
formMultipartBinding struct{}
|
|
)
|
|
|
|
func (formBinding) Name() string {
|
|
return "form"
|
|
}
|
|
|
|
func (formBinding) Bind(req *http.Request, obj any) error {
|
|
if err := req.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
if err := req.ParseMultipartForm(defaultMemory); err != nil && !errors.Is(err, http.ErrNotMultipart) {
|
|
return err
|
|
}
|
|
if err := mapForm(obj, req.Form); err != nil {
|
|
return err
|
|
}
|
|
return validate(obj)
|
|
}
|
|
|
|
func (formPostBinding) Name() string {
|
|
return "form-urlencoded"
|
|
}
|
|
|
|
func (formPostBinding) Bind(req *http.Request, obj any) error {
|
|
if err := req.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
if err := mapForm(obj, req.PostForm); err != nil {
|
|
return err
|
|
}
|
|
return validate(obj)
|
|
}
|
|
|
|
func (formMultipartBinding) Name() string {
|
|
return "multipart/form-data"
|
|
}
|
|
|
|
func (formMultipartBinding) Bind(req *http.Request, obj any) error {
|
|
if err := req.ParseMultipartForm(defaultMemory); err != nil {
|
|
return err
|
|
}
|
|
if err := mappingByPtr(obj, (*multipartRequest)(req), "form"); err != nil {
|
|
return err
|
|
}
|
|
|
|
return validate(obj)
|
|
}
|