parameters

package
v0.0.0-...-8e8e47b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](request *http.Request) (returnParams *T, returnErr error)

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

func TagLookupKeyFollowsNamingConvention(lookupKey string) bool

TagLookupKeyFollowsNamingConvention verifies if the tag value (the lookup key) follows the naming convention.

Types

type LookupKeyToFieldName

type LookupKeyToFieldName map[string]string

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_-]*$`
)

Jump to

Keyboard shortcuts

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