helpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package helpers provides utility functions for building Relicta plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandGlob

func ExpandGlob(pattern string) ([]string, error)

ExpandGlob expands a glob pattern to matching file paths.

func RequiredEnvVars

func RequiredEnvVars(keys ...string) []string

RequiredEnvVars checks that required environment variables are set. Returns a list of missing variables.

func ValidateAssetPath

func ValidateAssetPath(path string) error

ValidateAssetPath validates that an asset path is safe and exists. This prevents path traversal attacks and ensures the file can be accessed.

Types

type ConfigParser

type ConfigParser struct {
	// contains filtered or unexported fields
}

ConfigParser helps parse plugin configuration with type safety and defaults.

func NewConfigParser

func NewConfigParser(config map[string]any) *ConfigParser

NewConfigParser creates a new config parser from a config map.

func (*ConfigParser) GetBool

func (p *ConfigParser) GetBool(key string, defaultVal bool) bool

GetBool returns a boolean value from config.

func (*ConfigParser) GetFloat

func (p *ConfigParser) GetFloat(key string, defaultVal float64) float64

GetFloat returns a float value from config.

func (*ConfigParser) GetInt

func (p *ConfigParser) GetInt(key string, defaultVal int) int

GetInt returns an integer value from config.

func (*ConfigParser) GetMap

func (p *ConfigParser) GetMap(key string) map[string]any

GetMap returns a map from config.

func (*ConfigParser) GetString

func (p *ConfigParser) GetString(key, envKey, defaultVal string) string

GetString returns a string value from config, with optional environment variable fallback. Priority: config value > environment variable > default value

func (*ConfigParser) GetStringSlice

func (p *ConfigParser) GetStringSlice(key string, defaultVal []string) []string

GetStringSlice returns a string slice from config.

func (*ConfigParser) Has

func (p *ConfigParser) Has(key string) bool

Has returns true if the key exists in the config.

func (*ConfigParser) Unmarshal

func (p *ConfigParser) Unmarshal(v any) error

Unmarshal decodes the config into a struct.

type ValidationBuilder

type ValidationBuilder struct {
	// contains filtered or unexported fields
}

ValidationBuilder helps construct validation responses.

func NewValidationBuilder

func NewValidationBuilder() *ValidationBuilder

NewValidationBuilder creates a new validation builder.

func (*ValidationBuilder) AddError

func (b *ValidationBuilder) AddError(field, message string) *ValidationBuilder

AddError adds a validation error.

func (*ValidationBuilder) AddErrorWithCode

func (b *ValidationBuilder) AddErrorWithCode(field, message, code string) *ValidationBuilder

AddErrorWithCode adds a validation error with an error code.

func (*ValidationBuilder) Build

Build creates the final ValidateResponse.

func (*ValidationBuilder) HasErrors

func (b *ValidationBuilder) HasErrors() bool

HasErrors returns true if there are validation errors.

func (*ValidationBuilder) RequireString

func (b *ValidationBuilder) RequireString(config map[string]any, field, envFallback string) *ValidationBuilder

RequireString adds an error if the field is empty or missing.

func (*ValidationBuilder) ValidateOneOf

func (b *ValidationBuilder) ValidateOneOf(config map[string]any, field string, allowed []string) *ValidationBuilder

ValidateOneOf validates that a field contains one of the allowed values.

func (*ValidationBuilder) ValidatePattern

func (b *ValidationBuilder) ValidatePattern(config map[string]any, field, pattern, message string) *ValidationBuilder

ValidatePattern validates that a field matches a regex pattern.

func (*ValidationBuilder) ValidateURL

func (b *ValidationBuilder) ValidateURL(config map[string]any, field string) *ValidationBuilder

ValidateURL validates that a field contains a valid URL.

Jump to

Keyboard shortcuts

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