Documentation
¶
Overview ¶
Package sanitize provides helper functions for extracting and sanitising parameters from HTTP requests. The package supports retrieving values from URL query strings, POST form bodies and request headers, and converting them to common Go types (string, int, int64, float64, bool). All string values are sanitised using the options defined in the package variable `sn_opts`.
Index ¶
- func GetBool(req *http.Request, param string) (bool, error)
- func GetBoolMulti(req *http.Request, param string) ([]bool, error)
- func GetFloat64(req *http.Request, param string) (float64, error)
- func GetFloat64Multi(req *http.Request, param string) ([]float64, error)
- func GetInt(req *http.Request, param string) (int, error)
- func GetInt64(req *http.Request, param string) (int64, error)
- func GetInt64Multi(req *http.Request, param string) ([]int64, error)
- func GetIntMulti(req *http.Request, param string) ([]int, error)
- func GetString(req *http.Request, param string) (string, error)
- func GetStringMulti(req *http.Request, param string) ([]string, error)
- func HeaderBool(req *go_http.Request, param string) (bool, error)
- func HeaderInt64(req *go_http.Request, param string) (int64, error)
- func HeaderString(req *go_http.Request, param string) (string, error)
- func PostBool(req *http.Request, param string) (bool, error)
- func PostBoolMulti(req *http.Request, param string) ([]bool, error)
- func PostFloat64(req *http.Request, param string) (float64, error)
- func PostFloat64Multi(req *http.Request, param string) ([]float64, error)
- func PostInt(req *http.Request, param string) (int, error)
- func PostInt64(req *http.Request, param string) (int64, error)
- func PostInt64Multi(req *http.Request, param string) ([]int64, error)
- func PostIntMulti(req *http.Request, param string) ([]int, error)
- func PostString(req *http.Request, param string) (string, error)
- func PostStringMulti(req *http.Request, param string) ([]string, error)
- func RequestBool(req *http.Request, param string) (bool, error)
- func RequestBoolMulti(req *http.Request, param string) ([]bool, error)
- func RequestFloat64(req *http.Request, param string) (float64, error)
- func RequestFloat64Multi(req *http.Request, param string) ([]float64, error)
- func RequestInt(req *http.Request, param string) (int, error)
- func RequestInt64(req *http.Request, param string) (int64, error)
- func RequestInt64Multi(req *http.Request, param string) ([]int64, error)
- func RequestIntMulti(req *http.Request, param string) ([]int, error)
- func RequestString(req *http.Request, param string) (string, error)
- func RequestStringMulti(req *http.Request, param string) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBool ¶
GetBool returns a bool extracted from the URL query parameters of the given request for the specified key. The value is first sanitised and then parsed as a bool. If the key is missing or the value is empty, false is returned.
func GetBoolMulti ¶ added in v4.1.0
GetBoolMulti returns a slice of bool values extracted from the URL query parameters of the given request for the specified key. The raw values are sanitised before being parsed as bool.
func GetFloat64 ¶
GetFloat64 returns a float64 extracted from the URL query parameters of the given request for the specified key. The value is first sanitised and then parsed as a float64. If the key is missing or the value is empty, zero is returned.
func GetFloat64Multi ¶ added in v4.1.0
GetFloat64Multi returns a slice of float64 values extracted from the URL query parameters of the given request for the specified key. The raw values are sanitised before being parsed as float64.
func GetInt ¶
GetInt returns an int extracted from the URL query parameters of the given request for the specified key. The value is first sanitised and then parsed as an int. If the key is missing or the value is empty, zero is returned.
func GetInt64 ¶
GetInt64 returns an int64 extracted from the URL query parameters of the given request for the specified key. The value is first sanitised and then parsed as an int64. If the key is missing or the value is empty, zero is returned.
func GetInt64Multi ¶ added in v4.1.0
GetInt64Multi returns a slice of int64 values extracted from the URL query parameters of the given request for the specified key. The raw values are sanitised before being parsed as int64.
func GetIntMulti ¶ added in v4.1.0
GetIntMulti returns a slice of integers extracted from the URL query parameters of the given request for the specified key. The function first sanitises the raw string values and then converts each to an `int`. If the key is not present an empty slice is returned.
func GetString ¶
GetString returns a sanitised string extracted from the URL query parameters of the given request for the specified key. If the key is missing an empty string is returned.
func GetStringMulti ¶ added in v4.1.0
GetStringMulti returns a slice of sanitised strings extracted from the URL query parameters of the given request for the specified key. If the key is not present an empty slice is returned without error.
func HeaderBool ¶
HeaderBool returns a bool extracted from the request header for the specified key. The header value is first sanitised and then parsed as bool. An error is returned if the conversion fails.
func HeaderInt64 ¶
HeaderInt64 returns an int64 extracted from the request header for the specified key. The header value is first sanitised and then parsed as int64. An error is returned if the conversion fails.
func HeaderString ¶
HeaderString returns a sanitised string extracted from the request header for the specified key. If the header is missing an empty string is returned.
func PostBool ¶
PostBool returns a bool extracted from the POST form body of the given request for the specified key. The value is first sanitised and then parsed as bool. If the key is missing or the value is empty, false is returned.
func PostBoolMulti ¶ added in v4.1.0
PostBoolMulti returns a slice of bool values extracted from the POST form body of the given request for the specified key. The values are sanitised before being parsed as bool.
func PostFloat64 ¶
PostFloat64 returns a float64 extracted from the POST form body of the given request for the specified key. The value is first sanitised and then parsed as float64. If the key is missing or the value is empty, zero is returned.
func PostFloat64Multi ¶ added in v4.1.0
PostFloat64Multi returns a slice of float64 values extracted from the POST form body of the given request for the specified key. The values are sanitised before being parsed as float64.
func PostInt ¶
PostInt returns an int extracted from the POST form body of the given request for the specified key. The value is first sanitised and then parsed as int. If the key is missing or the value is empty, zero is returned.
func PostInt64 ¶
PostInt64 returns an int64 extracted from the POST form body of the given request for the specified key. The value is first sanitised and then parsed as int64. If the key is missing or the value is empty, zero is returned.
func PostInt64Multi ¶ added in v4.1.0
PostInt64Multi returns a slice of int64 values extracted from the POST form body of the given request for the specified key. The values are sanitised before being parsed as int64.
func PostIntMulti ¶ added in v4.1.0
PostIntMulti returns a slice of ints extracted from the POST form body of the given request for the specified key. The values are sanitised before being parsed as int.
func PostString ¶
PostString returns a sanitised string extracted from the POST form body of the given request for the specified key. If the key is missing an empty string is returned.
func PostStringMulti ¶ added in v4.1.0
PostStringMulti returns a slice of sanitised strings extracted from the POST form body of the given request for the specified key. If the key is not present an empty slice is returned.
func RequestBoolMulti ¶ added in v4.1.0
func RequestFloat64Multi ¶ added in v4.1.0
func RequestInt64Multi ¶ added in v4.1.0
func RequestIntMulti ¶ added in v4.1.0
Types ¶
This section is empty.