utils

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 10 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 ActivityRuntimeContext

func ActivityRuntimeContext(requestCtx context.Context, appCtx context.Context) context.Context

ActivityRuntimeContext returns a context suitable for activity-backed work.

func AsStringMap

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

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

func BoolOrDefault

func BoolOrDefault(value string, defaultValue bool) bool

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

func CamelCaseToScreamingSnakeCase

func CamelCaseToScreamingSnakeCase(s string) string

func CamelCaseToSnakeCase

func CamelCaseToSnakeCase(str string) string

func CapitalizeFirstLetter

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

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

Contains checks if a string slice contains an item

func DerefString

func DerefString(p *string) string

func ExtractCategoryMetadata

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

func GenerateRandomString(length int) string

func GetStringOrDefault

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

func IntOrDefault

func IntOrDefault(value string, defaultValue int) int

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

func IsAppLifecycleContext

func IsAppLifecycleContext(ctx context.Context) bool

IsAppLifecycleContext reports whether ctx is tied to the application lifecycle.

func ParseKeywords

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

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

func StringOrDefault(value, defaultValue string) string

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

func StringPtrEqual

func StringPtrEqual(a, b *string) bool

func StringPtrFromTrimmed

func StringPtrFromTrimmed(value string) *string

func ToString

func ToString(v any) string

ToString converts any value to a trimmed string.

func TrimQuotes

func TrimQuotes(s string) string

func UniqueNonEmptyStrings

func UniqueNonEmptyStrings(items []string) []string

UniqueNonEmptyStrings returns unique, non-empty, trimmed strings.

func UpdateIfChanged

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 WithAppLifecycleContext

func WithAppLifecycleContext(ctx context.Context) context.Context

WithAppLifecycleContext marks ctx as the application lifecycle context.

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.
Package iconcatalog resolves Arcane icon metadata into catalog URLs.
Package iconcatalog resolves Arcane icon metadata into catalog URLs.

Jump to

Keyboard shortcuts

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