utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFromLocalhost

func IsFromLocalhost(req *http.Request) bool

func MapToStruct

func MapToStruct[T any](m map[string]any) *T

MapToStruct deserializes a map[string]any back into a typed struct pointer. Returns nil if m is nil or empty.

func PrettyJSON

func PrettyJSON(v any) json.RawMessage

func StructToMap

func StructToMap[T any](v *T) map[string]any

StructToMap serializes a pointer to any json-tagged struct into a map[string]any. Returns nil if v is nil.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, status int, v any) error

Types

type SplitLevelHandler

type SplitLevelHandler struct {
	StdHandler slog.Handler
	ErrHandler slog.Handler
}

SplitLevelHandler routes log records to stdout for levels below Error, and to stderr for Error and above.

func (*SplitLevelHandler) Enabled

func (h *SplitLevelHandler) Enabled(_ context.Context, level slog.Level) bool

func (*SplitLevelHandler) Handle

func (h *SplitLevelHandler) Handle(ctx context.Context, r slog.Record) error

func (*SplitLevelHandler) WithAttrs

func (h *SplitLevelHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SplitLevelHandler) WithGroup

func (h *SplitLevelHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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