Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a new method override wrapper which can be registered on any HTTP server.
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.
Types ¶
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 ¶
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 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 ¶
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 Only ¶
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:
When need to check only for headers and ignore other fields: New(Only(Headers("X-Custom-Header")))
When need to check only for (first) form field and (second) custom getter: New(Only(FormField("fieldName"), Getter(...)))
func Query ¶
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 Request.Context().Value(requestContextKey).
Defaults to nil, don't save it.