config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	Key() string
	Validate() error
}

Config defines the interface for modules that provide configuration

type ConfigLoader

type ConfigLoader[T Settings] struct {
	// contains filtered or unexported fields
}

ConfigLoader handles loading and validation of all configurations

func NewConfigLoader

func NewConfigLoader[T Settings]() *ConfigLoader[T]

NewConfigLoader creates a new configuration loader

func (*ConfigLoader[T]) GetCore

func (l *ConfigLoader[T]) GetCore() *CoreConfig

GetCore returns the core configuration

func (*ConfigLoader[T]) GetProject

func (l *ConfigLoader[T]) GetProject() T

GetProject returns the project settings

func (*ConfigLoader[T]) LoadFromFile

func (l *ConfigLoader[T]) LoadFromFile(path string) error

LoadFromFile loads configuration from a YAML/JSON file

func (*ConfigLoader[T]) LoadModuleConfig

func (l *ConfigLoader[T]) LoadModuleConfig(config Config) error

LoadModuleConfig retrieves configuration for a specific module

func (*ConfigLoader[T]) ValidateAll

func (l *ConfigLoader[T]) ValidateAll() []ValidationError

ValidateAll performs validation on all configurations

type CoreConfig

type CoreConfig struct {
	Environment string         `yaml:"environment" json:"environment" validate:"required,oneof=development staging production test"`
	Debug       bool           `yaml:"debug" json:"debug"`
	Database    DatabaseConfig `yaml:"database" json:"database"`
	Server      ServerConfig   `yaml:"server" json:"server" validate:"required"`
	ProjectRoot string         `yaml:"-" json:"-"`
}

CoreConfig represents the essential framework configuration

func (*CoreConfig) IsProduction

func (c *CoreConfig) IsProduction() bool

func (*CoreConfig) Validate

func (c *CoreConfig) Validate() error

type DatabaseConfig

type DatabaseConfig struct {
	Enabled  bool   `yaml:"enabled" json:"enabled"`
	Driver   string `yaml:"driver" json:"driver" validate:"omitempty,oneof=postgres sqlite cloudsqlpostgres"`
	Host     string `yaml:"host" json:"host"`
	Port     string `yaml:"port" json:"port"`
	Name     string `yaml:"name" json:"name"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	SSLMode  string `yaml:"sslmode" json:"sslmode"`
}

DatabaseConfig holds database connection settings

type RawConfig

type RawConfig[T Settings] struct {
	Core    CoreConfig     `yaml:"core" json:"core" validate:"required"`
	Modules map[string]any `yaml:"modules" json:"modules"`
	Project T              `yaml:"project" json:"project" validate:"required"`
}

RawConfig represents the structure of the configuration file

type ServerConfig

type ServerConfig struct {
	Host            string        `yaml:"host" json:"host" validate:"required"`
	Port            string        `yaml:"port" json:"port" validate:"required"`
	AllowedOrigins  string        `yaml:"allowedOrigins" json:"allowedOrigins"`
	ReadTimeout     time.Duration `yaml:"readTimeout" json:"readTimeout"`
	WriteTimeout    time.Duration `yaml:"writeTimeout" json:"writeTimeout"`
	ShutdownTimeout time.Duration `yaml:"shutdownTimeout" json:"shutdownTimeout"`
}

ServerConfig holds HTTP server settings

type Settings

type Settings interface {
	Validate() error
	IsProduction() bool
}

Settings defines the base interface that all settings must implement

type ValidationError

type ValidationError struct {
	Field   string
	Message string
	Section string
}

ValidationError represents a configuration validation error

Jump to

Keyboard shortcuts

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