Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ContextFunctions0Arg = getFakes() ContextFunctions1Arg = getFakeFuncFactoryWithString() ContextFunctions2Arg = getFakeFuncFactoryWith2Strings() )
Functions ¶
func Load ¶
Load processes context files and parsed contexts, resolving aliases and functions.
The function operates in three phases:
- Parse phase: Parses YAML files and extracts aliases and raw data
- Alias resolution phase: Resolves all aliases across namespaces
- 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 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 ¶
FakeFuncFactoryWith2Strings is a function that returns a FakeFunc with 2 string arguments.
type FakeFuncFactoryWithString ¶
FakeFuncFactoryWithString is a function that returns a FakeFunc.
type Float64Value ¶
type Float64Value float64
func (Float64Value) Get ¶
func (f Float64Value) Get() any
type MixedValue ¶
type MixedValue interface {
Get() any
}
MixedValue is a value that can represent string, int, float64, or bool type.
Click to show internal directories.
Click to hide internal directories.