helper

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package helper provides utility functions for the midgard package.

Index

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

func GetOrCreateID(id string) string

GetOrCreateID generates a new uuid if the given id is empty, otherwise the given id is returned.

func IntroCheck

func IntroCheck(h defs.MWBaser, w http.ResponseWriter, r *http.Request) bool

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

func Must[T any](val T, err error) T

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

func WrapIfError(text string, err error) error

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.

Jump to

Keyboard shortcuts

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