Documentation
¶
Overview ¶
Package helper provides utility functions for the midgard package.
Index ¶
- func DummyHandler(w http.ResponseWriter, _ *http.Request)
- func GetOrCreateID(id string) string
- func IntroCheck(h defs.MWBaser, w http.ResponseWriter, r *http.Request) bool
- func MapKeys[T comparable, S any](source map[T]S) []T
- func Must[T any](val T, err error) T
- func WrapIfError(text string, err error) error
- func WriteState(w http.ResponseWriter, log *slog.Logger, httpState int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DummyHandler ¶
func DummyHandler(w http.ResponseWriter, _ *http.Request)
DummyHandler is a handler used for internal testing. It simply writes the text "dummy" to the given http.ResponseWriter.
func GetOrCreateID ¶
GetOrCreateID generates a new uuid if the given id is empty, otherwise the given id is returned.
func IntroCheck ¶
IntroCheck is used to facilitate the introductory check in each handler for the basic requirements. It manages the corresponding logging operations and can be used as follows:
if !helper.IntroCheck(h, w, r) {
return
}
func MapKeys ¶
func MapKeys[T comparable, S any](source map[T]S) []T
MapKeys gets the keys of the given map and saves them into a slice. There is not to expect a particular order of the elements in that slice. A nil map will produce a nil result, an empty map produces an empty slice.
func Must ¶
Must exits the program if the given pair of function return and error contains a non-nil error value, otherwise the function return value val is returned.
func WrapIfError ¶
WrapIfError wraps an existing error with the provided text. It returns nil if `err` is nil, or the original `err` if `text` is empty. Otherwise, it returns a new error with the format "text: original_error".
func WriteState ¶
func WriteState(w http.ResponseWriter, log *slog.Logger, httpState int)
WriteState sets the specified HTTP response code and writes the code-specific text as body. If an error occurs on writing to the client, it is logged to the specified logging instance. It is intended to give error feedback to clients.
Types ¶
This section is empty.