apihelper

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllUrlQueryValues

func GetAllUrlQueryValues[T any](query url.Values, valueKey string, parser Parser[T]) (*[]T, error)

func GetContextValue

func GetContextValue[T any](ctx context.Context, valueKey string) (*T, error)

func GetUrlQueryValue

func GetUrlQueryValue[T any](query url.Values, valueKey string, parser Parser[T]) (*T, error)

func HandlePing

func HandlePing() func(w http.ResponseWriter, r *http.Request)

func MapUuidHeader

func MapUuidHeader(header string) func(next http.Handler) http.Handler

func MapUuidQueries

func MapUuidQueries(w http.ResponseWriter, r *url.URL, query string, trg *[]uuid.UUID) error

func UnmarshalJsonAndValidate

func UnmarshalJsonAndValidate(logger *zap.SugaredLogger, rw http.ResponseWriter, r *http.Request, data interface{}) bool

returns true when unmarshal succeeded, otherwise writes error to response and returns false expects a pointer to a dto

func UnmarshalJsonAndValidateWithError

func UnmarshalJsonAndValidateWithError(rw http.ResponseWriter, r *http.Request, data interface{}) error

expects a pointer to a dto

func WriteCreateRessourceResponse

func WriteCreateRessourceResponse(w http.ResponseWriter, r *http.Request, id uuid.UUID)

Types

type CreateRessourceResponse

type CreateRessourceResponse struct {
	ID *uuid.UUID `json:"id"`
}

type GetContextValueError

type GetContextValueError struct {
	standardisedError.StandardisedError
	Param string `json:"param"`
}

define custom error to catch later in withErrorHandler

func (*GetContextValueError) Error

func (m *GetContextValueError) Error() string

func (*GetContextValueError) GetStandardisedError

func (m *GetContextValueError) GetStandardisedError() *standardisedError.StandardisedError

type GetUrlQueryValueError

type GetUrlQueryValueError struct {
	standardisedError.StandardisedError
	Param string `json:"param"`
}

define custom error to catch later in withErrorHandler

func (*GetUrlQueryValueError) Error

func (m *GetUrlQueryValueError) Error() string

func (*GetUrlQueryValueError) GetStandardisedError

func (m *GetUrlQueryValueError) GetStandardisedError() *standardisedError.StandardisedError

type HandlerFuncWithError

type HandlerFuncWithError func(http.ResponseWriter, *http.Request) error

type Parser

type Parser[T any] interface {
	Parse(string) (*T, error)
}

type UrlQueryTypes

type UrlQueryTypes interface {
	string | int64 | float64 | uuid.UUID
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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