Documentation
¶
Overview ¶
Package env builds a RuleSet from an environment variable holding a source/terms string, so an already-built binary can be faulted at process start with no recompile. It NEVER reads the environment in init(): the caller decides when and whether, keeping production opt-in. Pairs with engine.WithProductionGuard.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromEnv ¶
FromEnv reads the environment variable named varName (or "CHAOTIC_RULES" when varName is ""), parses its value with source/terms, and returns a RuleSet. An empty or unset variable yields an empty RuleSet, so the engine stays a no-op.
Example ¶
package main
import (
"fmt"
"os"
"github.com/RomanAgaltsev/chaotic/engine"
"github.com/RomanAgaltsev/chaotic/source/env"
)
func main() {
os.Setenv("CHAOTIC_RULES", `kind(http_client)=error("boom")`)
defer os.Unsetenv("CHAOTIC_RULES")
rs, err := env.FromEnv("CHAOTIC_RULES")
if err != nil {
panic(err)
}
// Pair with a production guard so a real binary stays opt-in.
eng := engine.New(engine.WithRuleSource(rs))
fmt.Println(eng.Enabled())
}
Output: true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.