Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Permittable ¶
type Permittable interface { // IsPermitted verifies that the URL query path is permitted by the permitter rules and returns the boolean result. IsPermitted(path string) bool // contains filtered or unexported methods }
Permittable exposes the common public interface that enables verifying if provided query path is permitted
func MustParsePermitted ¶
func MustParsePermitted(rules ...string) Permittable
MustParsePermitted is equivalent to ParsePermitted but instead of returning an error it panics with error.
func ParsePermitted ¶
func ParsePermitted(rules ...string) (Permittable, error)
ParsePermitted parses and builds query string keys whitelisting rules or returns an error. Calling
ParsePermitted("Literal", "Literal", "Literal")
is equivalent to
ParsePermitted("[Literal, Literal, Literal]")
.
The rules can have the following elements:
• Key (KeyLiteral) defines a whitelisted key:
- string literal of ASCII numbers and letters, eg. "someKey"
- single quote (') wrapped string literal of ASCII numbers, letters and spaces, eg. "'some key'"
• Object (ObjectLiteral) defines a whitelisted object containing any nested literals:
- "{ KeyLiteral, KeyLiteral }" eg. "{ key1, key2 }"
matches query
"key1=value1&key2=value2"
- "{ KeyLiteral:Array, KeyLiteral:ObjectLiteral, KeyLiteral }" eg. "{ key1:[], key2:{objKey}, key3}"
matches query
"key1[]=value&key2[objKey]=objValue&key3=keyValue"
**NOTE** rule "{}" doesn't match anything
• Array (ArrayLiteral) defines a whitelisted array containing any nested literals:
- "[]" matches array of string values, eg. "[]=value1&[]value2"
or
"[0]=value1&[1]value2"
- "[ KeyLiteral ]" eg. "[ key ]"
matches query
"[0][key]=value"
- "[ KeyLiteral:Array, KeyLiteral:ObjectLiteral, KeyLiteral ]" eg. "{ key1:[], key2:{objKey}, key3 }"
matches query
"[0][key1][]=value1&[0][key1][]=value2&[0][key2][objKey]=objValue&[0][key3]=keyValue"