Documentation
¶
Index ¶
- Variables
- func ParseEnvBool(key string, defaultValue bool) bool
- func ParseEnvFloat64(key string, defaultValue float64) (float64, error)
- func ParseEnvInt(key string, defaultValue int) (int, error)
- func ParseEnvIntPanic(key string) int
- func ParseEnvString(key string, defaultValue string) string
- func ParseEnvStringPanic(key string) string
- func ParseIDPathParam(r *http.Request) (int64, error)
- func ParseJSONMapInt64(m map[string]any, key string) (int64, error)
- func ParseJSONMapString(m map[string]any, key string) (string, error)
- func ParseQSBool(queryValues url.Values, key string, defaultValue *bool) *bool
- func ParseQSInt(queryValues url.Values, key string, defaultValue *int) *int
- func ParseQSInt64(queryValues url.Values, key string, defaultValue *int64) *int64
- func ParseQSString(queryValues url.Values, key string, defaultValue *string) *string
- func ParseQSStringSlice(queryValues url.Values, key string, defaultSlice []string) []string
- func StructsToFilteredMaps(v interface{}, includeFields []string) ([]map[string]interface{}, error)
- type Filters
- type PaginationMetadata
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidMapKey = errors.New("invalid key") ErrInvalidFieldType = errors.New("invalid field type") )
var ErrInvalidPathParam = errors.New("invalid path param")
ErrInvalidPathParam is returned when the path parameter is invalid.
Functions ¶
func ParseEnvBool ¶
func ParseEnvIntPanic ¶
func ParseEnvString ¶
func ParseEnvStringPanic ¶
func ParseIDPathParam ¶
Retrieve the "id" URL parameter from the current request context, then convert it to an integer and return it. If the operation isn't successful, return 0 and an error.
func ParseJSONMapInt64 ¶
ParseJSONMapInt64 parses a map[string]any and returns the value as an int64. Since json.Unmarshal() converts all numbers to float64, we need to convert them back to int64. Caller should ensure that castint from float64 to int64 is safe.
func ParseJSONMapString ¶
ParseJSONMapString parses a map[string]any and returns the value as a string.
func ParseQSBool ¶
ParseQSBool returns a boolean value from the query string or the provided default value if no matching key can be found.
func ParseQSInt ¶
ParseQSInt returns an integer value from the query string or the provided default value if no matching key can be found.
func ParseQSInt64 ¶
ParseQSInt64 returns an integer value from the query string or the provided default value if no matching key can be found.
func ParseQSString ¶
ParseQSString returns a string value from the query string or the provided default value if no matching key can be found.
func ParseQSStringSlice ¶
func StructsToFilteredMaps ¶
StructsToFilteredMaps converts a slice of structs to filtered maps using dot notation.
Types ¶
type Filters ¶
Filters contains common query string parameters for fieldsets, pagination, and sort.
func (*Filters) ParseQSMetadata ¶
func (f *Filters) ParseQSMetadata( queryValues url.Values, v *validation.Validator, fieldSafeList, sortSafeList []string, )
ParseQSMetadata parses the query string sort, page, and page size and populates the Filters struct.
type PaginationMetadata ¶
type PaginationMetadata struct { CurrentPage int `json:"currentPage,omitempty"` PageSize int `json:"pageSize,omitempty"` FirstPage int `json:"firstPage,omitempty"` LastPage int `json:"lastPage,omitempty"` TotalRecords int `json:"totalRecords,omitempty"` }
PaginationMetadata contains metadata about the current page of paginated data.
func ParsePaginationMetadata ¶
func ParsePaginationMetadata(totalRecords, page, pageSize int) PaginationMetadata
ParsePaginationMetadata calculates the pagination metadata based on the total number of records, the current page, and the page size.