env

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 5 Imported by: 0

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

func FromEnv(varName string) (engine.RuleSet, error)

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.

Jump to

Keyboard shortcuts

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