utils

package
v1.17.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilePerm os.FileMode = 0o644
	DirPerm  os.FileMode = 0o755
)

Functions

func AsStringMap

func AsStringMap(value any) (map[string]any, bool)

AsStringMap attempts to convert any map-like interface to map[string]any.

func CamelCaseToScreamingSnakeCase added in v1.17.0

func CamelCaseToScreamingSnakeCase(s string) string

func CamelCaseToSnakeCase added in v1.17.0

func CamelCaseToSnakeCase(str string) string

func CapitalizeFirstLetter added in v1.17.0

func CapitalizeFirstLetter(str string) string

func Collect

func Collect[T any](value any, mapper func(any) T) []T

Collect transforms a value (single item or slice) into a slice of T using a mapper.

func Contains added in v1.17.0

func Contains(slice []string, item string) bool

Contains checks if a string slice contains an item

func DerefString added in v1.17.0

func DerefString(p *string) string

func ExtractCategoryMetadata added in v1.17.0

func ExtractCategoryMetadata(model any, categoryIDsInOrder []string) map[string]map[string]string

ExtractCategoryMetadata extracts category metadata from struct fields with catmeta tags Returns a map of category ID to category metadata in field order

func FirstNonEmpty

func FirstNonEmpty(values ...string) string

FirstNonEmpty returns the first non-empty string in a list of values.

func GenerateRandomString added in v1.17.0

func GenerateRandomString(length int) string

func GetStringOrDefault added in v1.17.0

func GetStringOrDefault(m map[string]any, key, defaultValue string) string

func ParseKeywords added in v1.17.0

func ParseKeywords(keywordsStr string) []string

ParseKeywords parses a comma-separated keywords string into a slice Returns an empty slice if the input is empty or contains only whitespace

func ParseMetaTag added in v1.17.0

func ParseMetaTag(tag string) map[string]string

ParseMetaTag parses a struct tag meta value formatted as `k=v;other=val;...` Returns a map of key-value pairs extracted from the tag

func ToString

func ToString(v any) string

ToString converts any value to a trimmed string.

func TrimQuotes added in v1.17.0

func TrimQuotes(s string) string

func UniqueNonEmptyStrings

func UniqueNonEmptyStrings(items []string) []string

UniqueNonEmptyStrings returns unique, non-empty, trimmed strings.

func UpdateIfChanged added in v1.17.0

func UpdateIfChanged(target any, value any) bool

UpdateIfChanged updates the target value if it differs from the new value. It returns true if an update occurred. Supported types: *string, *bool, **string. For *string and *bool targets, if the value is a pointer of the same type, the update only happens if the value pointer is not nil.

func UserHasRole

func UserHasRole(roles []string, role string) bool

UserHasRole reports whether the user's roles contains the given role.

Types

This section is empty.

Jump to

Keyboard shortcuts

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