diff options
| author | 2024-05-21 13:17:22 +0000 | |
|---|---|---|
| committer | 2024-05-21 14:17:22 +0100 | |
| commit | 6c0d93c6cb082992fbc3c9bcbd85a99807563519 (patch) | |
| tree | a9e86538cd911451bc927c304e1e20a68de00071 /vendor/github.com/gin-gonic/gin | |
| parent | [chore]: Bump github.com/gin-contrib/cors from 1.7.1 to 1.7.2 (#2912) (diff) | |
| download | gotosocial-6c0d93c6cb082992fbc3c9bcbd85a99807563519.tar.xz | |
[chore] dependabot updates (#2922)
* [chore]: Bump github.com/prometheus/client_golang from 1.18.0 to 1.19.1
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.18.0 to 1.19.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* [chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.0 to 0.6.1
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.0 to 0.6.1.
- [Release notes](https://github.com/KimMachineGun/automemlimit/releases)
- [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.0...v0.6.1)
---
updated-dependencies:
- dependency-name: github.com/KimMachineGun/automemlimit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.20 to 2.20.24
Bumps [github.com/tdewolff/minify/v2](https://github.com/tdewolff/minify) from 2.20.20 to 2.20.24.
- [Release notes](https://github.com/tdewolff/minify/releases)
- [Commits](https://github.com/tdewolff/minify/compare/v2.20.20...v2.20.24)
---
updated-dependencies:
- dependency-name: github.com/tdewolff/minify/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* [chore]: Bump github.com/go-swagger/go-swagger
Bumps [github.com/go-swagger/go-swagger](https://github.com/go-swagger/go-swagger) from 0.30.6-0.20240418033037-c46c303aaa02 to 0.31.0.
- [Release notes](https://github.com/go-swagger/go-swagger/releases)
- [Changelog](https://github.com/go-swagger/go-swagger/blob/master/.goreleaser.yml)
- [Commits](https://github.com/go-swagger/go-swagger/commits/v0.31.0)
---
updated-dependencies:
- dependency-name: github.com/go-swagger/go-swagger
  dependency-type: direct:production
  update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* [chore]: Bump github.com/gin-gonic/gin from 1.9.1 to 1.10.0
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.1 to 1.10.0.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.9.1...v1.10.0)
---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/gin-gonic/gin')
19 files changed, 274 insertions, 105 deletions
| diff --git a/vendor/github.com/gin-gonic/gin/.gitignore b/vendor/github.com/gin-gonic/gin/.gitignore index bdd50c95c..1ea0e2b95 100644 --- a/vendor/github.com/gin-gonic/gin/.gitignore +++ b/vendor/github.com/gin-gonic/gin/.gitignore @@ -5,3 +5,7 @@ count.out  test  profile.out  tmp.out + +# Develop tools +.idea/ +.vscode/ diff --git a/vendor/github.com/gin-gonic/gin/.golangci.yml b/vendor/github.com/gin-gonic/gin/.golangci.yml index 91dae02c3..4a72f7342 100644 --- a/vendor/github.com/gin-gonic/gin/.golangci.yml +++ b/vendor/github.com/gin-gonic/gin/.golangci.yml @@ -3,7 +3,6 @@ run:  linters:    enable:      - asciicheck -    - depguard      - dogsled      - durationcheck      - errcheck diff --git a/vendor/github.com/gin-gonic/gin/.goreleaser.yaml b/vendor/github.com/gin-gonic/gin/.goreleaser.yaml index e435e56aa..99b66fee7 100644 --- a/vendor/github.com/gin-gonic/gin/.goreleaser.yaml +++ b/vendor/github.com/gin-gonic/gin/.goreleaser.yaml @@ -1,8 +1,7 @@  project_name: gin  builds: -  - -    # If true, skip the build. +  - # If true, skip the build.      # Useful for library projects.      # Default is false      skip: true @@ -10,7 +9,7 @@ builds:  changelog:    # Set it to true if you wish to skip the changelog generation.    # This may result in an empty release notes on GitHub/GitLab/Gitea. -  skip: false +  disable: false    # Changelog generation implementation to use.    # @@ -21,7 +20,7 @@ changelog:    # - `github-native`: uses the GitHub release notes generation API, disables the groups feature.    #    # Defaults to `git`. -  use: git +  use: github    # Sorts the changelog by the commit's messages.    # Could either be asc, desc or empty @@ -38,20 +37,20 @@ changelog:      - title: Features        regexp: "^.*feat[(\\w)]*:+.*$"        order: 0 -    - title: 'Bug fixes' +    - title: "Bug fixes"        regexp: "^.*fix[(\\w)]*:+.*$"        order: 1 -    - title: 'Enhancements' +    - title: "Enhancements"        regexp: "^.*chore[(\\w)]*:+.*$"        order: 2 +    - title: "Refactor" +      regexp: "^.*refactor[(\\w)]*:+.*$" +      order: 3 +    - title: "Build process updates" +      regexp: ^.*?(build|ci)(\(.+\))??!?:.+$ +      order: 4 +    - title: "Documentation updates" +      regexp: ^.*?docs?(\(.+\))??!?:.+$ +      order: 4      - title: Others        order: 999 - -  filters: -    # Commit messages matching the regexp listed here will be removed from -    # the changelog -    # Default is empty -    exclude: -      - '^docs' -      - 'CICD' -      - typo diff --git a/vendor/github.com/gin-gonic/gin/Makefile b/vendor/github.com/gin-gonic/gin/Makefile index ebde4ee84..b58f24f32 100644 --- a/vendor/github.com/gin-gonic/gin/Makefile +++ b/vendor/github.com/gin-gonic/gin/Makefile @@ -42,6 +42,7 @@ fmt-check:  		exit 1; \  	fi; +.PHONY: vet  vet:  	$(GO) vet $(VETPACKAGES) diff --git a/vendor/github.com/gin-gonic/gin/auth.go b/vendor/github.com/gin-gonic/gin/auth.go index 2503c5156..5d3222d56 100644 --- a/vendor/github.com/gin-gonic/gin/auth.go +++ b/vendor/github.com/gin-gonic/gin/auth.go @@ -16,6 +16,9 @@ import (  // AuthUserKey is the cookie name for user credential in basic auth.  const AuthUserKey = "user" +// AuthProxyUserKey is the cookie name for proxy_user credential in basic auth for proxy. +const AuthProxyUserKey = "proxy_user" +  // Accounts defines a key/value for user/pass list of authorized logins.  type Accounts map[string]string @@ -89,3 +92,25 @@ func authorizationHeader(user, password string) string {  	base := user + ":" + password  	return "Basic " + base64.StdEncoding.EncodeToString(bytesconv.StringToBytes(base))  } + +// BasicAuthForProxy returns a Basic HTTP Proxy-Authorization middleware. +// If the realm is empty, "Proxy Authorization Required" will be used by default. +func BasicAuthForProxy(accounts Accounts, realm string) HandlerFunc { +	if realm == "" { +		realm = "Proxy Authorization Required" +	} +	realm = "Basic realm=" + strconv.Quote(realm) +	pairs := processAccounts(accounts) +	return func(c *Context) { +		proxyUser, found := pairs.searchCredential(c.requestHeader("Proxy-Authorization")) +		if !found { +			// Credentials doesn't match, we return 407 and abort handlers chain. +			c.Header("Proxy-Authenticate", realm) +			c.AbortWithStatus(http.StatusProxyAuthRequired) +			return +		} +		// The proxy_user credentials was found, set proxy_user's id to key AuthProxyUserKey in this context, the proxy_user's id can be read later using +		// c.MustGet(gin.AuthProxyUserKey). +		c.Set(AuthProxyUserKey, proxyUser) +	} +} diff --git a/vendor/github.com/gin-gonic/gin/binding/binding.go b/vendor/github.com/gin-gonic/gin/binding/binding.go index 40948529a..94723879a 100644 --- a/vendor/github.com/gin-gonic/gin/binding/binding.go +++ b/vendor/github.com/gin-gonic/gin/binding/binding.go @@ -21,6 +21,7 @@ const (  	MIMEMSGPACK           = "application/x-msgpack"  	MIMEMSGPACK2          = "application/msgpack"  	MIMEYAML              = "application/x-yaml" +	MIMEYAML2             = "application/yaml"  	MIMETOML              = "application/toml"  ) @@ -72,18 +73,18 @@ var Validator StructValidator = &defaultValidator{}  // These implement the Binding interface and can be used to bind the data  // present in the request to struct instances.  var ( -	JSON          = jsonBinding{} -	XML           = xmlBinding{} -	Form          = formBinding{} -	Query         = queryBinding{} -	FormPost      = formPostBinding{} -	FormMultipart = formMultipartBinding{} -	ProtoBuf      = protobufBinding{} -	MsgPack       = msgpackBinding{} -	YAML          = yamlBinding{} -	Uri           = uriBinding{} -	Header        = headerBinding{} -	TOML          = tomlBinding{} +	JSON          BindingBody = jsonBinding{} +	XML           BindingBody = xmlBinding{} +	Form          Binding     = formBinding{} +	Query         Binding     = queryBinding{} +	FormPost      Binding     = formPostBinding{} +	FormMultipart Binding     = formMultipartBinding{} +	ProtoBuf      BindingBody = protobufBinding{} +	MsgPack       BindingBody = msgpackBinding{} +	YAML          BindingBody = yamlBinding{} +	Uri           BindingUri  = uriBinding{} +	Header        Binding     = headerBinding{} +	TOML          BindingBody = tomlBinding{}  )  // Default returns the appropriate Binding instance based on the HTTP method @@ -102,7 +103,7 @@ func Default(method, contentType string) Binding {  		return ProtoBuf  	case MIMEMSGPACK, MIMEMSGPACK2:  		return MsgPack -	case MIMEYAML: +	case MIMEYAML, MIMEYAML2:  		return YAML  	case MIMETOML:  		return TOML diff --git a/vendor/github.com/gin-gonic/gin/binding/binding_nomsgpack.go b/vendor/github.com/gin-gonic/gin/binding/binding_nomsgpack.go index 93ad8ba30..552a86b2d 100644 --- a/vendor/github.com/gin-gonic/gin/binding/binding_nomsgpack.go +++ b/vendor/github.com/gin-gonic/gin/binding/binding_nomsgpack.go @@ -19,6 +19,7 @@ const (  	MIMEMultipartPOSTForm = "multipart/form-data"  	MIMEPROTOBUF          = "application/x-protobuf"  	MIMEYAML              = "application/x-yaml" +	MIMEYAML2             = "application/yaml"  	MIMETOML              = "application/toml"  ) @@ -96,7 +97,7 @@ func Default(method, contentType string) Binding {  		return XML  	case MIMEPROTOBUF:  		return ProtoBuf -	case MIMEYAML: +	case MIMEYAML, MIMEYAML2:  		return YAML  	case MIMEMultipartPOSTForm:  		return FormMultipart diff --git a/vendor/github.com/gin-gonic/gin/binding/default_validator.go b/vendor/github.com/gin-gonic/gin/binding/default_validator.go index e216b8546..ac43d7cc5 100644 --- a/vendor/github.com/gin-gonic/gin/binding/default_validator.go +++ b/vendor/github.com/gin-gonic/gin/binding/default_validator.go @@ -54,7 +54,10 @@ func (v *defaultValidator) ValidateStruct(obj any) error {  	value := reflect.ValueOf(obj)  	switch value.Kind() {  	case reflect.Ptr: -		return v.ValidateStruct(value.Elem().Interface()) +		if value.Elem().Kind() != reflect.Struct { +			return v.ValidateStruct(value.Elem().Interface()) +		} +		return v.validateStruct(obj)  	case reflect.Struct:  		return v.validateStruct(obj)  	case reflect.Slice, reflect.Array: diff --git a/vendor/github.com/gin-gonic/gin/binding/form_mapping.go b/vendor/github.com/gin-gonic/gin/binding/form_mapping.go index 540bbbb84..db235e566 100644 --- a/vendor/github.com/gin-gonic/gin/binding/form_mapping.go +++ b/vendor/github.com/gin-gonic/gin/binding/form_mapping.go @@ -7,6 +7,7 @@ package binding  import (  	"errors"  	"fmt" +	"mime/multipart"  	"reflect"  	"strconv"  	"strings" @@ -164,6 +165,23 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter  	return setter.TrySet(value, field, tagValue, setOpt)  } +// BindUnmarshaler is the interface used to wrap the UnmarshalParam method. +type BindUnmarshaler interface { +	// UnmarshalParam decodes and assigns a value from an form or query param. +	UnmarshalParam(param string) error +} + +// trySetCustom tries to set a custom type value +// If the value implements the BindUnmarshaler interface, it will be used to set the value, we will return `true` +// to skip the default value setting. +func trySetCustom(val string, value reflect.Value) (isSet bool, err error) { +	switch v := value.Addr().Interface().(type) { +	case BindUnmarshaler: +		return true, v.UnmarshalParam(val) +	} +	return false, nil +} +  func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {  	vs, ok := form[tagValue]  	if !ok && !opt.isDefaultExists { @@ -193,6 +211,9 @@ func setByForm(value reflect.Value, field reflect.StructField, form map[string][  		if len(vs) > 0 {  			val = vs[0]  		} +		if ok, err := trySetCustom(val, value); ok { +			return ok, err +		}  		return true, setWithProperType(val, value, field)  	}  } @@ -235,10 +256,17 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel  		switch value.Interface().(type) {  		case time.Time:  			return setTimeField(val, field, value) +		case multipart.FileHeader: +			return nil  		}  		return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface())  	case reflect.Map:  		return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface()) +	case reflect.Ptr: +		if !value.Elem().IsValid() { +			value.Set(reflect.New(value.Type().Elem())) +		} +		return setWithProperType(val, value.Elem(), field)  	default:  		return errUnknownType  	} diff --git a/vendor/github.com/gin-gonic/gin/codecov.yml b/vendor/github.com/gin-gonic/gin/codecov.yml new file mode 100644 index 000000000..47782e50d --- /dev/null +++ b/vendor/github.com/gin-gonic/gin/codecov.yml @@ -0,0 +1,13 @@ +coverage: +  require_ci_to_pass: true + +  status: +    project: +      default: +        target: 99% +        threshold: 99% + +    patch: +      default: +        target: 99% +        threshold: 95%
\ No newline at end of file diff --git a/vendor/github.com/gin-gonic/gin/context.go b/vendor/github.com/gin-gonic/gin/context.go index 420ff1678..391adafed 100644 --- a/vendor/github.com/gin-gonic/gin/context.go +++ b/vendor/github.com/gin-gonic/gin/context.go @@ -43,6 +43,10 @@ const BodyBytesKey = "_gin-gonic/gin/bodybyteskey"  // ContextKey is the key that a Context returns itself for.  const ContextKey = "_gin-gonic/gin/contextkey" +type ContextKeyType int + +const ContextRequestKey ContextKeyType = 0 +  // abortIndex represents a typical value used in abort functions.  const abortIndex int8 = math.MaxInt8 >> 1 @@ -113,20 +117,27 @@ func (c *Context) Copy() *Context {  	cp := Context{  		writermem: c.writermem,  		Request:   c.Request, -		Params:    c.Params,  		engine:    c.engine,  	} +  	cp.writermem.ResponseWriter = nil  	cp.Writer = &cp.writermem  	cp.index = abortIndex  	cp.handlers = nil -	cp.Keys = map[string]any{} -	for k, v := range c.Keys { +	cp.fullPath = c.fullPath + +	cKeys := c.Keys +	cp.Keys = make(map[string]any, len(cKeys)) +	c.mu.RLock() +	for k, v := range cKeys {  		cp.Keys[k] = v  	} -	paramCopy := make([]Param, len(cp.Params)) -	copy(paramCopy, cp.Params) -	cp.Params = paramCopy +	c.mu.RUnlock() + +	cParams := c.Params +	cp.Params = make([]Param, len(cParams)) +	copy(cp.Params, cParams) +  	return &cp  } @@ -386,7 +397,7 @@ func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)  //  //	router.GET("/user/:id", func(c *gin.Context) {  //	    // a GET request to /user/john -//	    id := c.Param("id") // id == "/john" +//	    id := c.Param("id") // id == "john"  //	    // a GET request to /user/john/  //	    id := c.Param("id") // id == "/john/"  //	}) @@ -728,7 +739,7 @@ func (c *Context) ShouldBindHeader(obj any) error {  // ShouldBindUri binds the passed struct pointer using the specified binding engine.  func (c *Context) ShouldBindUri(obj any) error { -	m := make(map[string][]string) +	m := make(map[string][]string, len(c.Params))  	for _, v := range c.Params {  		m[v.Key] = []string{v.Value}  	} @@ -763,6 +774,26 @@ func (c *Context) ShouldBindBodyWith(obj any, bb binding.BindingBody) (err error  	return bb.BindBody(body, obj)  } +// ShouldBindBodyWithJSON is a shortcut for c.ShouldBindBodyWith(obj, binding.JSON). +func (c *Context) ShouldBindBodyWithJSON(obj any) error { +	return c.ShouldBindBodyWith(obj, binding.JSON) +} + +// ShouldBindBodyWithXML is a shortcut for c.ShouldBindBodyWith(obj, binding.XML). +func (c *Context) ShouldBindBodyWithXML(obj any) error { +	return c.ShouldBindBodyWith(obj, binding.XML) +} + +// ShouldBindBodyWithYAML is a shortcut for c.ShouldBindBodyWith(obj, binding.YAML). +func (c *Context) ShouldBindBodyWithYAML(obj any) error { +	return c.ShouldBindBodyWith(obj, binding.YAML) +} + +// ShouldBindBodyWithTOML is a shortcut for c.ShouldBindBodyWith(obj, binding.TOML). +func (c *Context) ShouldBindBodyWithTOML(obj any) error { +	return c.ShouldBindBodyWith(obj, binding.TOML) +} +  // ClientIP implements one best effort algorithm to return the real client IP.  // It calls c.RemoteIP() under the hood, to check if the remote IP is a trusted proxy or not.  // If it is it will then try to parse the headers defined in Engine.RemoteIPHeaders (defaulting to [X-Forwarded-For, X-Real-Ip]). @@ -873,6 +904,9 @@ func (c *Context) GetHeader(key string) string {  // GetRawData returns stream data.  func (c *Context) GetRawData() ([]byte, error) { +	if c.Request.Body == nil { +		return nil, errors.New("cannot read nil body") +	}  	return io.ReadAll(c.Request.Body)  } @@ -1215,7 +1249,7 @@ func (c *Context) Err() error {  // if no value is associated with key. Successive calls to Value with  // the same key returns the same result.  func (c *Context) Value(key any) any { -	if key == 0 { +	if key == ContextRequestKey {  		return c.Request  	}  	if key == ContextKey { diff --git a/vendor/github.com/gin-gonic/gin/debug.go b/vendor/github.com/gin-gonic/gin/debug.go index 1fc0cafe1..1761fe325 100644 --- a/vendor/github.com/gin-gonic/gin/debug.go +++ b/vendor/github.com/gin-gonic/gin/debug.go @@ -23,6 +23,9 @@ func IsDebugging() bool {  // DebugPrintRouteFunc indicates debug log output format.  var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int) +// DebugPrintFunc indicates debug log output format. +var DebugPrintFunc func(format string, values ...interface{}) +  func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {  	if IsDebugging() {  		nuHandlers := len(handlers) @@ -48,12 +51,19 @@ func debugPrintLoadTemplate(tmpl *template.Template) {  }  func debugPrint(format string, values ...any) { -	if IsDebugging() { -		if !strings.HasSuffix(format, "\n") { -			format += "\n" -		} -		fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...) +	if !IsDebugging() { +		return +	} + +	if DebugPrintFunc != nil { +		DebugPrintFunc(format, values...) +		return +	} + +	if !strings.HasSuffix(format, "\n") { +		format += "\n"  	} +	fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)  }  func getMinVer(v string) (uint64, error) { diff --git a/vendor/github.com/gin-gonic/gin/deprecated.go b/vendor/github.com/gin-gonic/gin/deprecated.go index 9521308f1..b4c6cd88e 100644 --- a/vendor/github.com/gin-gonic/gin/deprecated.go +++ b/vendor/github.com/gin-gonic/gin/deprecated.go @@ -12,6 +12,8 @@ import (  // BindWith binds the passed struct pointer using the specified binding engine.  // See the binding package. +// +// Deprecated: Use MustBindWith or ShouldBindWith.  func (c *Context) BindWith(obj any, b binding.Binding) error {  	log.Println(`BindWith(\"any, binding.Binding\") error is going to  	be deprecated, please check issue #662 and either use MustBindWith() if you diff --git a/vendor/github.com/gin-gonic/gin/gin.go b/vendor/github.com/gin-gonic/gin/gin.go index ed8b6dad7..1633fe13f 100644 --- a/vendor/github.com/gin-gonic/gin/gin.go +++ b/vendor/github.com/gin-gonic/gin/gin.go @@ -47,6 +47,9 @@ var regRemoveRepeatedChar = regexp.MustCompile("/{2,}")  // HandlerFunc defines the handler used by gin middleware as return value.  type HandlerFunc func(*Context) +// OptionFunc defines the function to change the default configuration +type OptionFunc func(*Engine) +  // HandlersChain defines a HandlerFunc slice.  type HandlersChain []HandlerFunc @@ -77,6 +80,8 @@ const (  	// PlatformCloudflare when using Cloudflare's CDN. Trust CF-Connecting-IP for determining  	// the client's IP  	PlatformCloudflare = "CF-Connecting-IP" +	// PlatformFlyIO when running on Fly.io. Trust Fly-Client-IP for determining the client's IP +	PlatformFlyIO = "Fly-Client-IP"  )  // Engine is the framework's instance, it contains the muxer, middleware and configuration settings. @@ -180,7 +185,7 @@ var _ IRouter = (*Engine)(nil)  // - ForwardedByClientIP:    true  // - UseRawPath:             false  // - UnescapePathValues:     true -func New() *Engine { +func New(opts ...OptionFunc) *Engine {  	debugPrintWARNINGNew()  	engine := &Engine{  		RouterGroup: RouterGroup{ @@ -209,15 +214,15 @@ func New() *Engine {  	engine.pool.New = func() any {  		return engine.allocateContext(engine.maxParams)  	} -	return engine +	return engine.With(opts...)  }  // Default returns an Engine instance with the Logger and Recovery middleware already attached. -func Default() *Engine { +func Default(opts ...OptionFunc) *Engine {  	debugPrintWARNINGDefault()  	engine := New()  	engine.Use(Logger(), Recovery()) -	return engine +	return engine.With(opts...)  }  func (engine *Engine) Handler() http.Handler { @@ -311,6 +316,15 @@ func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {  	return engine  } +// With returns a new Engine instance with the provided options. +func (engine *Engine) With(opts ...OptionFunc) *Engine { +	for _, opt := range opts { +		opt(engine) +	} + +	return engine +} +  func (engine *Engine) rebuild404Handlers() {  	engine.allNoRoute = engine.combineHandlers(engine.noRoute)  } @@ -334,7 +348,6 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {  	}  	root.addRoute(path, handlers) -	// Update maxParams  	if paramsCount := countParams(path); paramsCount > engine.maxParams {  		engine.maxParams = paramsCount  	} @@ -634,17 +647,25 @@ func (engine *Engine) handleHTTPRequest(c *Context) {  	}  	if engine.HandleMethodNotAllowed { +		// According to RFC 7231 section 6.5.5, MUST generate an Allow header field in response +		// containing a list of the target resource's currently supported methods. +		allowed := make([]string, 0, len(t)-1)  		for _, tree := range engine.trees {  			if tree.method == httpMethod {  				continue  			}  			if value := tree.root.getValue(rPath, nil, c.skippedNodes, unescape); value.handlers != nil { -				c.handlers = engine.allNoMethod -				serveError(c, http.StatusMethodNotAllowed, default405Body) -				return +				allowed = append(allowed, tree.method)  			}  		} +		if len(allowed) > 0 { +			c.handlers = engine.allNoMethod +			c.writermem.Header().Set("Allow", strings.Join(allowed, ", ")) +			serveError(c, http.StatusMethodNotAllowed, default405Body) +			return +		}  	} +  	c.handlers = engine.allNoRoute  	serveError(c, http.StatusNotFound, default404Body)  } diff --git a/vendor/github.com/gin-gonic/gin/logger.go b/vendor/github.com/gin-gonic/gin/logger.go index cd1e7fa6e..db2c6832b 100644 --- a/vendor/github.com/gin-gonic/gin/logger.go +++ b/vendor/github.com/gin-gonic/gin/logger.go @@ -47,8 +47,15 @@ type LoggerConfig struct {  	// SkipPaths is an url path array which logs are not written.  	// Optional.  	SkipPaths []string + +	// Skip is a Skipper that indicates which logs should not be written. +	// Optional. +	Skip Skipper  } +// Skipper is a function to skip logs based on provided Context +type Skipper func(c *Context) bool +  // LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter  type LogFormatter func(params LogFormatterParams) string @@ -83,6 +90,8 @@ func (p *LogFormatterParams) StatusCodeColor() string {  	code := p.StatusCode  	switch { +	case code >= http.StatusContinue && code < http.StatusOK: +		return white  	case code >= http.StatusOK && code < http.StatusMultipleChoices:  		return green  	case code >= http.StatusMultipleChoices && code < http.StatusBadRequest: @@ -239,32 +248,34 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {  		// Process request  		c.Next() -		// Log only when path is not being skipped -		if _, ok := skip[path]; !ok { -			param := LogFormatterParams{ -				Request: c.Request, -				isTerm:  isTerm, -				Keys:    c.Keys, -			} - -			// Stop timer -			param.TimeStamp = time.Now() -			param.Latency = param.TimeStamp.Sub(start) +		// Log only when it is not being skipped +		if _, ok := skip[path]; ok || (conf.Skip != nil && conf.Skip(c)) { +			return +		} -			param.ClientIP = c.ClientIP() -			param.Method = c.Request.Method -			param.StatusCode = c.Writer.Status() -			param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String() +		param := LogFormatterParams{ +			Request: c.Request, +			isTerm:  isTerm, +			Keys:    c.Keys, +		} -			param.BodySize = c.Writer.Size() +		// Stop timer +		param.TimeStamp = time.Now() +		param.Latency = param.TimeStamp.Sub(start) -			if raw != "" { -				path = path + "?" + raw -			} +		param.ClientIP = c.ClientIP() +		param.Method = c.Request.Method +		param.StatusCode = c.Writer.Status() +		param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String() -			param.Path = path +		param.BodySize = c.Writer.Size() -			fmt.Fprint(out, formatter(param)) +		if raw != "" { +			path = path + "?" + raw  		} + +		param.Path = path + +		fmt.Fprint(out, formatter(param))  	}  } diff --git a/vendor/github.com/gin-gonic/gin/render/render.go b/vendor/github.com/gin-gonic/gin/render/render.go index 7955000c6..4bdcfa232 100644 --- a/vendor/github.com/gin-gonic/gin/render/render.go +++ b/vendor/github.com/gin-gonic/gin/render/render.go @@ -15,22 +15,22 @@ type Render interface {  }  var ( -	_ Render     = JSON{} -	_ Render     = IndentedJSON{} -	_ Render     = SecureJSON{} -	_ Render     = JsonpJSON{} -	_ Render     = XML{} -	_ Render     = String{} -	_ Render     = Redirect{} -	_ Render     = Data{} -	_ Render     = HTML{} -	_ HTMLRender = HTMLDebug{} -	_ HTMLRender = HTMLProduction{} -	_ Render     = YAML{} -	_ Render     = Reader{} -	_ Render     = AsciiJSON{} -	_ Render     = ProtoBuf{} -	_ Render     = TOML{} +	_ Render     = (*JSON)(nil) +	_ Render     = (*IndentedJSON)(nil) +	_ Render     = (*SecureJSON)(nil) +	_ Render     = (*JsonpJSON)(nil) +	_ Render     = (*XML)(nil) +	_ Render     = (*String)(nil) +	_ Render     = (*Redirect)(nil) +	_ Render     = (*Data)(nil) +	_ Render     = (*HTML)(nil) +	_ HTMLRender = (*HTMLDebug)(nil) +	_ HTMLRender = (*HTMLProduction)(nil) +	_ Render     = (*YAML)(nil) +	_ Render     = (*Reader)(nil) +	_ Render     = (*AsciiJSON)(nil) +	_ Render     = (*ProtoBuf)(nil) +	_ Render     = (*TOML)(nil)  )  func writeContentType(w http.ResponseWriter, value []string) { diff --git a/vendor/github.com/gin-gonic/gin/render/yaml.go b/vendor/github.com/gin-gonic/gin/render/yaml.go index fc927c1f2..042bb821d 100644 --- a/vendor/github.com/gin-gonic/gin/render/yaml.go +++ b/vendor/github.com/gin-gonic/gin/render/yaml.go @@ -15,7 +15,7 @@ type YAML struct {  	Data any  } -var yamlContentType = []string{"application/x-yaml; charset=utf-8"} +var yamlContentType = []string{"application/yaml; charset=utf-8"}  // Render (YAML) marshals the given interface object and writes data with custom ContentType.  func (r YAML) Render(w http.ResponseWriter) error { diff --git a/vendor/github.com/gin-gonic/gin/tree.go b/vendor/github.com/gin-gonic/gin/tree.go index dda8f4f7b..878023d1c 100644 --- a/vendor/github.com/gin-gonic/gin/tree.go +++ b/vendor/github.com/gin-gonic/gin/tree.go @@ -351,7 +351,10 @@ func (n *node) insertChild(path string, fullPath string, handlers HandlersChain)  		}  		if len(n.path) > 0 && n.path[len(n.path)-1] == '/' { -			pathSeg := strings.SplitN(n.children[0].path, "/", 2)[0] +			pathSeg := "" +			if len(n.children) != 0 { +				pathSeg = strings.SplitN(n.children[0].path, "/", 2)[0] +			}  			panic("catch-all wildcard '" + path +  				"' in new path '" + fullPath +  				"' conflicts with existing path segment '" + pathSeg + @@ -478,7 +481,7 @@ walk: // Outer loop for walking the tree  					// We can recommend to redirect to the same URL without a  					// trailing slash if a leaf exists for that path.  					value.tsr = path == "/" && n.handlers != nil -					return +					return value  				}  				// Handle wildcard child, which is always at the end of the array @@ -497,7 +500,14 @@ walk: // Outer loop for walking the tree  					}  					// Save param value -					if params != nil && cap(*params) > 0 { +					if params != nil { +						// Preallocate capacity if necessary +						if cap(*params) < int(globalParamsCount) { +							newParams := make(Params, len(*params), globalParamsCount) +							copy(newParams, *params) +							*params = newParams +						} +  						if value.params == nil {  							value.params = params  						} @@ -526,12 +536,12 @@ walk: // Outer loop for walking the tree  						// ... but we can't  						value.tsr = len(path) == end+1 -						return +						return value  					}  					if value.handlers = n.handlers; value.handlers != nil {  						value.fullPath = n.fullPath -						return +						return value  					}  					if len(n.children) == 1 {  						// No handle found. Check if a handle for this path + a @@ -539,11 +549,18 @@ walk: // Outer loop for walking the tree  						n = n.children[0]  						value.tsr = (n.path == "/" && n.handlers != nil) || (n.path == "" && n.indices == "/")  					} -					return +					return value  				case catchAll:  					// Save param value  					if params != nil { +						// Preallocate capacity if necessary +						if cap(*params) < int(globalParamsCount) { +							newParams := make(Params, len(*params), globalParamsCount) +							copy(newParams, *params) +							*params = newParams +						} +  						if value.params == nil {  							value.params = params  						} @@ -564,7 +581,7 @@ walk: // Outer loop for walking the tree  					value.handlers = n.handlers  					value.fullPath = n.fullPath -					return +					return value  				default:  					panic("invalid node type") @@ -595,7 +612,7 @@ walk: // Outer loop for walking the tree  			// Check if this node has a handle registered.  			if value.handlers = n.handlers; value.handlers != nil {  				value.fullPath = n.fullPath -				return +				return value  			}  			// If there is no handle for this route, but this route has a @@ -603,12 +620,12 @@ walk: // Outer loop for walking the tree  			// additional trailing slash  			if path == "/" && n.wildChild && n.nType != root {  				value.tsr = true -				return +				return value  			}  			if path == "/" && n.nType == static {  				value.tsr = true -				return +				return value  			}  			// No handle found. Check if a handle for this path + a @@ -618,11 +635,11 @@ walk: // Outer loop for walking the tree  					n = n.children[i]  					value.tsr = (len(n.path) == 1 && n.handlers != nil) ||  						(n.nType == catchAll && n.children[0].handlers != nil) -					return +					return value  				}  			} -			return +			return value  		}  		// Nothing found. We can recommend to redirect to the same URL with an @@ -648,7 +665,7 @@ walk: // Outer loop for walking the tree  			}  		} -		return +		return value  	}  } diff --git a/vendor/github.com/gin-gonic/gin/version.go b/vendor/github.com/gin-gonic/gin/version.go index 85462e555..93ad96541 100644 --- a/vendor/github.com/gin-gonic/gin/version.go +++ b/vendor/github.com/gin-gonic/gin/version.go @@ -5,4 +5,4 @@  package gin  // Version is the current gin framework's version. -const Version = "v1.9.1" +const Version = "v1.10.0" | 
