Documentation
¶
Index ¶
- func IsFromLocalhost(req *http.Request) bool
- func MapToStruct[T any](m map[string]any) *T
- func PrettyJSON(v any) json.RawMessage
- func StructToMap[T any](v *T) map[string]any
- func StructToMapLC(v any, opts ...Option) map[string]any
- func WriteJSONResponse(w http.ResponseWriter, status int, v any) error
- type Option
- type SplitLevelHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsFromLocalhost ¶
func MapToStruct ¶
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 ¶
StructToMap serializes a pointer to any json-tagged struct into a map[string]any. Returns nil if v is nil.
func StructToMapLC ¶ added in v0.1.0
StructToMapLC converts a struct to map[string]any using reflection, converting PascalCase field names to camelCase (first character lowercased). Embedded structs are flattened into the parent map. Optional behaviors (ID suffix conversion, omit-empty) can be enabled via Option. Returns nil if v is nil or not a struct.
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, status int, v any) error
Types ¶
type Option ¶ added in v0.1.1
type Option func(*options)
Option configures the behavior of StructToMapLC.
func WithIDSuffix ¶ added in v0.1.1
func WithIDSuffix() Option
WithIDSuffix converts field names ending in "ID" to end in "Id". e.g. "UserID" becomes "userId" instead of "userID".
func WithOmitEmpty ¶ added in v0.1.1
func WithOmitEmpty() Option
WithOmitEmpty skips fields with empty values: empty string, nil pointer, nil or zero-length slice. Numeric and boolean fields are never omitted.
type SplitLevelHandler ¶
SplitLevelHandler routes log records to stdout for levels below Error, and to stderr for Error and above.