contexts

package
v2.1.93 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextFunctions0Arg = getFakes()
	ContextFunctions1Arg = getFakeFuncFactoryWithString()
	ContextFunctions2Arg = getFakeFuncFactoryWith2Strings()
)

Functions

func Load

func Load(files map[string][]byte, parsed []map[string]map[string]any) map[string]map[string]any

Load processes context files and parsed contexts, resolving aliases and functions.

The function operates in three phases:

  1. Parse phase: Parses YAML files and extracts aliases and raw data
  2. Alias resolution phase: Resolves all aliases across namespaces
  3. function processing phase: Processes function prefixes (fake, func, botify, join)

Parameters:

  • files: Map of namespace names to YAML file contents
  • parsed: Pre-parsed contexts to merge with file-based contexts

Returns a map of namespace names to their resolved context data.

Supported alias syntax:

  • alias:namespace.key.path - References a value from another namespace

Supported function prefixes:

  • fake: - Generates fake data using available faker functions
  • fake:path.to.func - Uses a specific faker function by path
  • func:name - Calls a registered no-arg function
  • func:name:arg - Calls a registered function with one argument
  • func:name:arg1,arg2 - Calls a registered function with two arguments (e.g., func:int_between:1,10)
  • botify:pattern - Generates random strings based on pattern (? for letter, # for digit)
  • join:separator,ns.key1,ns.key2 - Joins values from multiple keys with separator

Example:

files := map[string][]byte{
    "common": []byte(`
        host: localhost
        port: 8080
    `),
    "app": []byte(`
        server_host: alias:common.host
        server_port: alias:common.port
        code: botify:???###
    `),
}
result := Load(files, nil)
// result["app"]["server_host"] == "localhost"
// result["app"]["server_port"] == 8080
// result["app"]["code"] is a function that generates strings like "abc123"

Types

type BoolValue

type BoolValue bool

func (BoolValue) Get

func (b BoolValue) Get() any

type FakeFunc

type FakeFunc func() MixedValue

FakeFunc is a function that returns a MixedValue. This is u unified way to work with different return types from fake library.

type FakeFuncFactoryWith2Strings

type FakeFuncFactoryWith2Strings func(arg1, arg2 string) FakeFunc

FakeFuncFactoryWith2Strings is a function that returns a FakeFunc with 2 string arguments.

type FakeFuncFactoryWithString

type FakeFuncFactoryWithString func(value string) FakeFunc

FakeFuncFactoryWithString is a function that returns a FakeFunc.

type Float64Value

type Float64Value float64

func (Float64Value) Get

func (f Float64Value) Get() any

type IntValue

type IntValue int

func (IntValue) Get

func (i IntValue) Get() any

type MixedValue

type MixedValue interface {
	Get() any
}

MixedValue is a value that can represent string, int, float64, or bool type.

type StringValue

type StringValue string

func (StringValue) Get

func (s StringValue) Get() any

Jump to

Keyboard shortcuts

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