sanitize

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: BSD-3-Clause Imports: 3 Imported by: 10

README

go-http/v3/sanitize

See also

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(req *http.Request, param string) (bool, error)

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

func GetBoolMulti(req *http.Request, param string) ([]bool, error)

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

func GetFloat64(req *http.Request, param string) (float64, error)

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

func GetFloat64Multi(req *http.Request, param string) ([]float64, error)

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

func GetInt(req *http.Request, param string) (int, error)

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

func GetInt64(req *http.Request, param string) (int64, error)

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

func GetInt64Multi(req *http.Request, param string) ([]int64, error)

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

func GetIntMulti(req *http.Request, param string) ([]int, error)

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

func GetString(req *http.Request, param string) (string, error)

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

func GetStringMulti(req *http.Request, param string) ([]string, error)

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

func HeaderBool(req *go_http.Request, param string) (bool, error)

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

func HeaderInt64(req *go_http.Request, param string) (int64, error)

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

func HeaderString(req *go_http.Request, param string) (string, error)

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

func PostBool(req *http.Request, param string) (bool, error)

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

func PostBoolMulti(req *http.Request, param string) ([]bool, error)

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

func PostFloat64(req *http.Request, param string) (float64, error)

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

func PostFloat64Multi(req *http.Request, param string) ([]float64, error)

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

func PostInt(req *http.Request, param string) (int, error)

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

func PostInt64(req *http.Request, param string) (int64, error)

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

func PostInt64Multi(req *http.Request, param string) ([]int64, error)

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

func PostIntMulti(req *http.Request, param string) ([]int, error)

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

func PostString(req *http.Request, param string) (string, error)

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

func PostStringMulti(req *http.Request, param string) ([]string, error)

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 RequestBool

func RequestBool(req *http.Request, param string) (bool, error)

func RequestBoolMulti added in v4.1.0

func RequestBoolMulti(req *http.Request, param string) ([]bool, error)

func RequestFloat64

func RequestFloat64(req *http.Request, param string) (float64, error)

func RequestFloat64Multi added in v4.1.0

func RequestFloat64Multi(req *http.Request, param string) ([]float64, error)

func RequestInt

func RequestInt(req *http.Request, param string) (int, error)

func RequestInt64

func RequestInt64(req *http.Request, param string) (int64, error)

func RequestInt64Multi added in v4.1.0

func RequestInt64Multi(req *http.Request, param string) ([]int64, error)

func RequestIntMulti added in v4.1.0

func RequestIntMulti(req *http.Request, param string) ([]int, error)

func RequestString

func RequestString(req *http.Request, param string) (string, error)

func RequestStringMulti added in v4.1.0

func RequestStringMulti(req *http.Request, param string) ([]string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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