config

package
v1.38.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config provides file-based configuration loading with validation.

Stability: stable

Package config provides file-based configuration loading with validation and environment variable overrides.

Load reads a JSON file into a struct. LoadWithEnv additionally applies environment variable overrides using the "env" struct tag. Validate checks fields with the "validate" struct tag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load[T any](path string) (T, error)

Load reads a JSON configuration file at path into a value of type T.

func LoadWithEnv

func LoadWithEnv[T any](path, prefix string) (T, error)

LoadWithEnv reads a JSON configuration file and applies environment variable overrides. Fields with an `env:"NAME"` struct tag are overridden by the environment variable PREFIX_NAME if set.

Supported field types: string, int, bool.

func Validate

func Validate(v any) []string

Validate checks struct fields tagged with `validate:"required"`. Returns a slice of error messages for each field that fails validation. Returns nil if all validations pass.

Types

type DistributedConfig

type DistributedConfig struct {
	CoordinatorAddress string `env:"COORDINATOR_ADDRESS" json:"coordinator_address" validate:"required"`
	TimeoutSeconds     int    `env:"TIMEOUT_SECONDS"     json:"timeout_seconds"`
	TLSEnabled         bool   `env:"TLS_ENABLED"         json:"tls_enabled"`
}

DistributedConfig holds configuration for distributed training.

type EngineConfig

type EngineConfig struct {
	Device        string `env:"DEVICE"          json:"device"          validate:"required"`
	MemoryLimitMB int    `env:"MEMORY_LIMIT_MB" json:"memory_limit_mb"`
	LogLevel      string `env:"LOG_LEVEL"       json:"log_level"`
}

EngineConfig holds configuration for the compute engine.

type TrainingConfig

type TrainingConfig struct {
	BatchSize          int    `env:"BATCH_SIZE"          json:"batch_size"          validate:"required"`
	LearningRate       string `env:"LEARNING_RATE"       json:"learning_rate"       validate:"required"`
	Optimizer          string `env:"OPTIMIZER"           json:"optimizer"           validate:"required"`
	Epochs             int    `env:"EPOCHS"              json:"epochs"`
	CheckpointInterval int    `env:"CHECKPOINT_INTERVAL" json:"checkpoint_interval"`
}

TrainingConfig holds configuration for training workflows.

Jump to

Keyboard shortcuts

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