utils

package
v1.19.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	HeaderAgentBootstrap = "X-Arcane-Agent-Bootstrap"
	HeaderAgentToken     = "X-Arcane-Agent-Token" // #nosec G101: header name, not a credential
	HeaderApiKey         = "X-API-Key"            // #nosec G101: header name, not a credential
	AgentPairingPrefix   = "/api/environments/0/agent/pair"
)

Auth header names and path prefixes shared between the Echo middleware (WebSocket/diagnostics) and the Huma auth bridge (REST). Keep these in one place so a change to a header name applies to every route type at once.

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 BoolOrDefault added in v1.19.0

func BoolOrDefault(value string, defaultValue bool) bool

BoolOrDefault parses value as a bool, falling back to defaultValue when empty or unparseable.

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 IntOrDefault added in v1.19.0

func IntOrDefault(value string, defaultValue int) int

IntOrDefault parses value as an int, falling back to defaultValue when empty or unparseable.

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 StringOrDefault added in v1.19.0

func StringOrDefault(value, defaultValue string) string

StringOrDefault returns the trimmed value if non-empty, otherwise defaultValue.

func StringPtrEqual added in v1.19.0

func StringPtrEqual(a, b *string) bool

func StringPtrFromTrimmed added in v1.19.1

func StringPtrFromTrimmed(value string) *string

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.

Directories

Path Synopsis
Package dbutil provides small generic helpers around GORM that consolidate repetitive single-row lookup and transaction boilerplate found across services.
Package dbutil provides small generic helpers around GORM that consolidate repetitive single-row lookup and transaction boilerplate found across services.

Jump to

Keyboard shortcuts

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