parse

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parse contains helper functions for parsing different kinds of URL and Query parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayQueryParam

func ArrayQueryParam[T any](
	r *http.Request,
	paramName string,
	defaultValue []T,
	parserFunc ParserFunc[T],
) ([]T, error)

ArrayQueryParam is used to parse an optional array parameter provided to a query. The format that should be used here is: ?paramName=1,2,3&...

func QueryParam

func QueryParam[T any](
	r *http.Request,
	paramName string,
	defaultValue T,
	parserFunc ParserFunc[T],
) (T, error)

QueryParam is used to parse an optional parameter provided to a query.

func RequiredArrayQueryParam

func RequiredArrayQueryParam[T any](
	r *http.Request,
	paramName string,
	parserFunc ParserFunc[T],
) ([]T, error)

RequiredArrayQueryParam is used to parse a required array parameter provided to a query. The format that should be used here is: ?paramName=1,2,3&...

func RequiredQueryParam

func RequiredQueryParam[T any](
	r *http.Request,
	paramName string,
	parserFunc ParserFunc[T],
) (T, error)

RequiredQueryParam is used to parse a required parameter provided to a query.

func URLParam

func URLParam[T any](
	r *http.Request,
	paramName string,
	parserFunc ParserFunc[T],
) (T, error)

URLParam is used to parse a required parameter provided to a URL.

func UUID

func UUID(paramType string, paramName string, value string) (string, error)

UUID is used to parse a parameter as UUID value. Technically this only validates if a string is a UUID.

Types

type ParserFunc

type ParserFunc[T any] func(paramType string, paramName string, value string) (T, error)

ParserFunc is the expected format used for parsing data using any parsing function.

func DateFunc

func DateFunc(layout string) ParserFunc[time.Time]

DateFunc parses a parameter as a date. The parameter should match the required date layout.

func Int64Func

func Int64Func(isPositive bool, isZero bool) ParserFunc[int64]

Int64Func parses a parameter as [int64].

func IntFunc

func IntFunc(isPositive bool, isZero bool) ParserFunc[int]

IntFunc parses a parameter as [int].

Jump to

Keyboard shortcuts

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