examples/

directory
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0

README

Synthra examples

Runnable programs that complement the shorter snippets in example_test.go and the package overview on pkg.go.dev.

Progression

Start at the top and work down. Each example builds on concepts from the previous ones.

Directory What it shows
basic YAML file + struct binding
webapp YAML defaults + WEBAPP_* env overrides + binding + Validate
testing synthratest.Config + source.NewMap in tests
schema WithJSONSchema validation + schema default values + patternProperties
casing Case-insensitive merge, schema as canonical key-casing authority
hooks WithTransform, WithValidator, and OnBound[T] in one pipeline
codecs WithFileAs (JSON, TOML) + WithFileDumperAs (YAML dump)
envsubst-layered Three-layer Resolver.Or precedence for ${VAR} lookups
multi-schema Two-phase WithJSONSchemaFunc around WithEnvSubst
consul WithIf(..., WithConsul(...)) conditional source

Quick start

cd examples/basic && go run .
cd examples/webapp && go run .

Tests

Every example ships with tests. Run them all at once:

go test ./examples/...

Docker (webapp)

From the repository root:

docker build -f examples/Dockerfile -t synthra-webapp-example .
docker run --rm synthra-webapp-example

The image uses the Go version pinned in Dockerfile (aligned with go.mod).

Adding a new example

  1. Create a subdirectory with main.go, README.md, and tests.
  2. Link it from this file.
  3. Keep snippets copy-paste accurate (gopherly.dev/synthra imports, real paths).

Directories

Path Synopsis
Package main shows YAML file loading and struct binding with Synthra.
Package main shows YAML file loading and struct binding with Synthra.
Package main demonstrates Synthra's case-preserving, case-insensitive merge and shows how a JSON Schema acts as the canonical authority for key casing.
Package main demonstrates Synthra's case-preserving, case-insensitive merge and shows how a JSON Schema acts as the canonical authority for key casing.
Package main shows codec usage end-to-end: JSON + TOML as input sources, merged YAML written out via WithFileDumperAs.
Package main shows codec usage end-to-end: JSON + TOML as input sources, merged YAML written out via WithFileDumperAs.
Package main loads local YAML, optionally merges Consul KV, then env.
Package main loads local YAML, optionally merges Consul KV, then env.
Package main demonstrates three-layer resolver composition with Resolver.Or.
Package main demonstrates three-layer resolver composition with Resolver.Or.
Package main demonstrates all three hook points in one pipeline.
Package main demonstrates all three hook points in one pipeline.
Package main demonstrates two-phase validation using WithJSONSchemaFunc.
Package main demonstrates two-phase validation using WithJSONSchemaFunc.
Package main demonstrates JSON Schema defaults and WithEnvSubst.
Package main demonstrates JSON Schema defaults and WithEnvSubst.
Package main exists so `go run .` works; see README and *_test.go.
Package main exists so `go run .` works; see README and *_test.go.
Package main demonstrates layered configuration (YAML defaults plus environment overrides), struct binding, and validation with Synthra.
Package main demonstrates layered configuration (YAML defaults plus environment overrides), struct binding, and validation with Synthra.

Jump to

Keyboard shortcuts

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