Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode populates a parameter struct with values from an HTTP request and performs validation on the struct.
func ExtractAndValidateFieldTagLookupKeys ¶
func ExtractAndValidateFieldTagLookupKeys[T any]() (*readonly.Map[Tag, LookupKeyToFieldName], error)
ExtractAndValidateFieldTagLookupKeys validates the struct tags and returns a map of unique tag lookup keys for each field in the struct.
type MyStruct struct { HeaderParameter string `httpHeader:"x-my-parameter" json"-"` PathParameter string `urlPath:"my-id" json"-"` }
Returns the following map:
{ "httpHeader": { "x-my-parameter": "MyParameter" }, "urlPath": { "my-id": "PathParameter" } }
func TagLookupKeyFollowsNamingConvention ¶
TagLookupKeyFollowsNamingConvention verifies if the tag value (the lookup key) follows the naming convention.
Types ¶
type LookupKeyToFieldName ¶
LookupKeyToFieldName is the tag's lookup key to the name of the field on the struct.
type MyStruct struct { HeaderParameter string `httpHeader:"x-my-parameter" json"-"` }
Returns the following map:
{ "x-my-parameter": "MyParameter", }
type Tag ¶
type Tag string
Tag is a string of metadata associated at compile time with a field of a struct.
type MyStruct struct { HeaderParameter string `httpHeader:"x-my-parameter"` }
In this case, the tag would be "httpHeader".
const ( // QueryTag is a struct field tag used to specify that the field's value should be sourced from URL query parameters. QueryTag Tag = "urlQuery" // HeaderTag is a struct field tag used to specify that the field's value should be sourced from the HTTP headers. HeaderTag Tag = "httpHeader" // PathTag is a struct field tag used to specify that the field's value should be sourced from the URL path parameters. PathTag Tag = "urlPath" // JSONTag is a struct field tag used to specify that the field's value should be sourced from the request JSON body. JSONTag Tag = "json" // TagLookupKeyNamingConvention is the naming convention a tags lookup key must adhere to. TagLookupKeyNamingConvention = `^[a-zA-Z][a-zA-Z0-9_-]*$` )
Click to show internal directories.
Click to hide internal directories.