v12.2.10 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0




This section is empty.


This section is empty.


func New

func New(opt ...Option) router.WrapperFunc

New returns a new method override wrapper which can be registered with `Application.WrapRouter`.

Use this wrapper when you expecting clients that do not support certain HTTP operations such as DELETE or PUT for security reasons. This wrapper will accept a method, based on criteria, to override the POST method with.

Read more at:


type GetterFunc

type GetterFunc func(http.ResponseWriter, *http.Request) string

GetterFunc is the type signature for declaring custom logic to extract the method name which a POST request will be replaced with.

type Option

type Option func(*options)

Option sets options for a fresh method override wrapper. See `New` package-level function for more.

func FormField

func FormField(fieldName string) Option

FormField specifies a form field to use to determinate the method to override the POST method with.

Example Field: <input type="hidden" name="_method" value="DELETE">

Defaults to: "_method".

func FormFieldWithConf

func FormFieldWithConf(fieldName string, conf context.ConfigurationReadOnly) Option

FormFieldWithConf same as `FormField` but it accepts the application's configuration to parse the form based on the app core configuration.

func Getter

func Getter(customFunc GetterFunc) Option

Getter sets a custom logic to use to extract the method name to override the POST method with. Defaults to nil.

func Headers

func Headers(headers ...string) Option

Headers that client can send to specify a method to override the POST method with.

Defaults to: X-HTTP-Method X-HTTP-Method-Override X-Method-Override

func Methods

func Methods(methods ...string) Option

Methods can be used to add methods that can be overridden. Defaults to "POST".

func Only

func Only(o ...Option) Option

Only clears all default or previously registered values and uses only the "o" option(s).

The default behavior is to check for all the following by order: headers, form field, query string and any custom getter (if set). Use this method to override that behavior and use only the passed option(s) to determinate the method to override with.

Use cases:

  1. When need to check only for headers and ignore other fields: New(Only(Headers("X-Custom-Header")))

  2. When need to check only for (first) form field and (second) custom getter: New(Only(FormField("fieldName"), Getter(...)))

func Query

func Query(paramName string) Option

Query specifies a url parameter name to use to determinate the method to override the POST methos with.

Example URL Query string: http://localhost:8080/path?_method=DELETE

Defaults to: "_method".

func SaveOriginalMethod

func SaveOriginalMethod(requestContextKey interface{}) Option

SaveOriginalMethod will save the original method on Context.Request().Context().Value(requestContextKey).

Defaults to nil, don't save it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL