utils

package
v0.0.1-dev.12 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// maxFileSize is the maximum size for any single file to prevent decompression bombs
	MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB
)

Variables

This section is empty.

Functions

func CapturePrettyPrint

func CapturePrettyPrint(v ...interface{}) []any

func ExpandFilePaths

func ExpandFilePaths(paths []string, recursive bool) ([]string, error)

ExpandFilePaths expands file paths to include files in directories and glob patterns.

func ExtractLineMetadata

func ExtractLineMetadata(lineStr string) (string, string, string, string)

ExtractLineMetadata extracts metadata and content from a line Returns metadata (instanceID, instanceName, timestamp) and the remaining content

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists.

func GetYAMLFilesInDirectory

func GetYAMLFilesInDirectory(dirPath string, recursive bool) ([]string, error)

GetYAMLFilesInDirectory returns all YAML files (.yaml or .yml) in a directory.

func HasPlaceholders

func HasPlaceholders(s string) bool

HasPlaceholders reports whether a string contains template delimiters.

func IsDirectory

func IsDirectory(path string) bool

IsDirectory checks if a path is a directory.

func MapToPretty

func MapToPretty(v interface{}) string

func ParseTimestamp

func ParseTimestamp(timestampStr string) (*time.Time, error)

ParseTimestamp parses a timestamp string into a time.Time.

func PickFirstNonEmpty

func PickFirstNonEmpty(values ...string) string

PickFirstNonEmpty picks the first non-empty value from a list of strings. If all values are empty, returns the empty string.

func PreQuoteUnquotedPlaceholders

func PreQuoteUnquotedPlaceholders(in string) string

PreQuoteUnquotedPlaceholders wraps bare {{ ... }} placeholders where a value consists solely of a placeholder (key: {{...}} or - {{...}}) to avoid YAML parse errors.

func PrettyPrint

func PrettyPrint(v ...interface{})

func ProtoStringToTimestamp

func ProtoStringToTimestamp(timestamp string) *time.Time

func SafePath

func SafePath(baseDir, entryName string) (string, error)

SafePath safely constructs a target path within a base directory, preventing directory traversal

func SliceContains

func SliceContains[T comparable](s []T, e T) bool

func ToInt32NonNegative

func ToInt32NonNegative(n int) int32

Helper to safely convert non-negative ints to int32 with clamping

func ToInt32NonNegative64

func ToInt32NonNegative64(n int64) int32

func ToUint32NonNegative

func ToUint32NonNegative(n int) uint32

func ToUint64NonNegative

func ToUint64NonNegative(n int) uint64

func ToUintNonNegative

func ToUintNonNegative(n int) uint

func ValidateDNS1123Name

func ValidateDNS1123Name(name string) error

ValidateDNS1123Name validates the a name according to DNS-1123 rules

Types

type InstanceLogInfo

type InstanceLogInfo struct {
	InstanceID   string
	InstanceName string
	Reader       io.ReadCloser
}

InstanceLogInfo associates an instance ID with its log reader

type MultiLogStreamer

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

MultiLogStreamer combines log streams from multiple instances into a single stream

func NewMultiLogStreamer

func NewMultiLogStreamer(instances []InstanceLogInfo, includeMetadata bool) *MultiLogStreamer

NewMultiLogStreamer creates a new MultiLogStreamer that combines log streams from multiple instances

func (*MultiLogStreamer) Close

func (m *MultiLogStreamer) Close() error

Close implements the io.Closer interface

func (*MultiLogStreamer) Read

func (m *MultiLogStreamer) Read(p []byte) (n int, err error)

Read implements the io.Reader interface

type Renderer

type Renderer struct {
	Root          string
	Values        map[string]interface{}
	Ctx           map[string]interface{}
	FileCache     map[string]string
	TemplateCache map[string]string
	Stack         []string // include stack for cycle detection (absolute paths)
	MaxDepth      int
	PhRegex       *regexp.Regexp
	Filters       map[string]func(current interface{}, args []interface{}, ok bool) (interface{}, bool, error)
}

Renderer provides cached, guarded rendering of runeset placeholders.

func NewRenderer

func NewRenderer(root string, values map[string]interface{}, ctx map[string]interface{}) *Renderer

NewRenderer creates a renderer with sane defaults.

func (*Renderer) PreprocessValuesYAML

func (r *Renderer) PreprocessValuesYAML(text string) (string, error)

PreprocessValuesYAML pre-processes values YAML text to support unquoted placeholders by quoting bare placeholders and then rendering placeholders against the renderer state.

func (*Renderer) RenderString

func (r *Renderer) RenderString(input string, depth int) (string, error)

RenderString renders a YAML text with recursion/depth guards and caching.

func (*Renderer) RenderValuesMap

func (r *Renderer) RenderValuesMap(values map[string]interface{}) error

RenderValuesMap walks a map and renders any string placeholders using this renderer. It mutates the provided map in place.

func (*Renderer) RenderValuesMapFixpoint

func (r *Renderer) RenderValuesMapFixpoint(values map[string]interface{}, maxPasses int) error

RenderValuesMapFixpoint repeatedly renders placeholders in the map until a fixpoint is reached or maxPasses is exceeded.

Jump to

Keyboard shortcuts

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