parse

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 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 String added in v0.1.9

func String(_ string, _ string, value string) (string, error)

String is used to parse a parameter as string value. As all parameters are string by default this returns the original value.

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 Date added in v0.1.9

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

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

func Int added in v0.1.9

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

Int parses a parameter as [int].

func Int64 added in v0.1.9

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

Int64 parses a parameter as [int64].

Jump to

Keyboard shortcuts

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