config

package
v0.0.0-...-2bc8f10 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Server: ServerConfig{
		HTTP: HTTPConfig{
			Address: ":8080",
		},
		HTTPS: HTTPSConfig{
			Enabled:    true,
			CAKeyFile:  "",
			CACertFile: "",
			Transparent: TransparentConfig{
				Address: ":8443",
			},
		},
	},
	Cache: CacheConfig{
		TTL:    "",
		Folder: "./cache",
	},
	Rules: RulesConfig{
		Mode:  RulesModeBlacklist,
		Rules: []CacheRule{},
	},
	Log: LogConfig{
		Level:      "info",
		ThirdParty: false,
	},
}

DefaultConfig holds the default configuration values

Functions

func MatchesStatusCode

func MatchesStatusCode(statusCode int, pattern string) bool

MatchesStatusCode checks if a status code matches a pattern

Types

type CacheConfig

type CacheConfig struct {
	TTL    string `koanf:"ttl"`
	Folder string `koanf:"folder"`
}

CacheConfig contains cache-related configuration

type CacheRule

type CacheRule struct {
	BaseURI     string   `koanf:"base_uri"`
	Methods     []string `koanf:"methods"`
	StatusCodes []string `koanf:"status_codes,omitempty"` // e.g., ["200", "404", "4xx", "5xx"]
}

CacheRule defines a caching rule

func NewCacheRule

func NewCacheRule(baseURI string, methods ...string) CacheRule

type Config

type Config struct {
	Server ServerConfig `koanf:"server"`
	Cache  CacheConfig  `koanf:"cache"`
	Rules  RulesConfig  `koanf:"rules"`
	Log    LogConfig    `koanf:"log"`
}

Config represents the application configuration

func Load

func Load(path string) (*Config, error)

Load loads configuration from a YAML file using koanf

func (*Config) GetCacheTTL

func (c *Config) GetCacheTTL() (time.Duration, error)

GetCacheTTL parses and returns the cache TTL duration

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type HTTPConfig

type HTTPConfig struct {
	Address string `koanf:"address"`
}

type HTTPSConfig

type HTTPSConfig struct {
	Enabled     bool              `koanf:"enabled"`
	CAKeyFile   string            `koanf:"ca_key_file"`
	CACertFile  string            `koanf:"ca_cert_file"`
	Transparent TransparentConfig `koanf:"transparent"`
}

type LogConfig

type LogConfig struct {
	Level      string `koanf:"level"`
	ThirdParty bool   `koanf:"third_party"`
}

type RulesConfig

type RulesConfig struct {
	Mode  RulesMode   `koanf:"mode"` // "whitelist" or "blacklist"
	Rules []CacheRule `koanf:"rules"`
}

func NewRulesConfig

func NewRulesConfig(mode RulesMode, rules ...CacheRule) *RulesConfig

type RulesMode

type RulesMode string

RulesMode represents the mode of rule evaluation (whitelist or blacklist)

const (
	RulesModeWhitelist RulesMode = "whitelist"
	RulesModeBlacklist RulesMode = "blacklist"
)

type ServerConfig

type ServerConfig struct {
	HTTP  HTTPConfig  `koanf:"http"`
	HTTPS HTTPSConfig `koanf:"https"`
}

ServerConfig contains server-related configuration Updated for nested http/https config

type TransparentConfig

type TransparentConfig struct {
	Address string `koanf:"address"`
}

Jump to

Keyboard shortcuts

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