config

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OnChanged is a global callback for configuration changes.
	OnChanged provider.ChangeFunc
)

Functions

func IsValidDomain added in v0.2.0

func IsValidDomain(domain string) bool

IsValidDomain checks if the given string is a valid domain name.

func TestAndSkipResolver added in v0.9.0

func TestAndSkipResolver(path string) (string, error)

TestAndSkipResolver loads the configuration and sets SkipResolver to true, returning the config path.

func ValidateConfig

func ValidateConfig(mainOptions Options, mode ValidationMode) error

ValidateConfig checks if the config's values are valid, but does not check if the config's value mapping is valid.

func Watch

func Watch() error

Watch starts watching for configuration changes.

Types

type AccessLogOptions

type AccessLogOptions struct {
	Output     string        `json:"output"      yaml:"output"`
	Template   string        `json:"template"    yaml:"template"`
	TimeFormat string        `json:"time_format" yaml:"time_format"`
	Escape     EscapeType    `json:"escape"      yaml:"escape"`
	BufferSize int           `json:"buffer_size" yaml:"buffer_size"`
	Flush      time.Duration `json:"flush"       yaml:"flush"`
}

AccessLogOptions defines configuration for access logs.

type ActiveHealthOptions added in v0.4.0

type ActiveHealthOptions struct {
	Path             string        `json:"path"              yaml:"path"`
	Method           string        `json:"method"            yaml:"method"`
	Interval         time.Duration `json:"interval"          yaml:"interval"`
	Port             int           `json:"port"              yaml:"port"`
	SuccessThreshold int           `json:"success_threshold" yaml:"success_threshold"`
	FailureThreshold int           `json:"failure_threshold" yaml:"failure_threshold"`
}

ActiveHealthOptions defines configuration for active health checks.

type BalancerOptions added in v0.7.0

type BalancerOptions struct {
	Type   string `json:"type"   yaml:"type"`
	Params any    `json:"params" yaml:"params"`
}

BalancerOptions defines load balancer configuration.

type ChangeFunc

type ChangeFunc func() error

ChangeFunc is a function called when configuration changes.

type DNSProviderOptions added in v0.4.0

type DNSProviderOptions struct {
	Servers []string      `json:"servers" yaml:"servers"`
	Valid   time.Duration `json:"valid"   yaml:"valid"`
	Enabled bool          `json:"enabled" yaml:"enabled"`
}

DNSProviderOptions defines configuration for DNS service discovery.

type DefaultOptions added in v0.3.0

type DefaultOptions struct {
	Service  DefaultServiceOptions  `json:"service"  yaml:"service"`
	Upstream DefaultUpstreamOptions `json:"upstream" yaml:"upstream"`
}

DefaultOptions defines default configuration for various components.

type DefaultServiceOptions added in v0.3.0

type DefaultServiceOptions struct {
	MaxConnsPerHost *int                  `json:"max_conns_per_host" yaml:"max_conns_per_host"`
	Protocol        Protocol              `json:"protocol"           yaml:"protocol"`
	Timeout         ServiceTimeoutOptions `json:"timeout"            yaml:"timeout"`
}

DefaultServiceOptions defines default configuration for services.

type DefaultUpstreamOptions added in v0.3.0

type DefaultUpstreamOptions struct {
	MaxFails    uint          `json:"max_fails"    yaml:"max_fails"`
	FailTimeout time.Duration `json:"fail_timeout" yaml:"fail_timeout"`
}

DefaultUpstreamOptions defines default configuration for upstreams.

type DiscoveryOptions added in v0.4.0

type DiscoveryOptions struct {
	Type      string `json:"type"      yaml:"type"`
	Namespace string `json:"namespace" yaml:"namespace"`
	Name      string `json:"name"      yaml:"name"`
}

DiscoveryOptions defines service discovery configuration.

type EscapeType

type EscapeType string

EscapeType defines the log escape type.

const (
	// NoneEscape means no character escaping is performed.
	NoneEscape EscapeType = "none"
	// DefaultEscape means default character escaping is performed.
	DefaultEscape EscapeType = "default"
	// JSONEscape means characters are escaped for JSON output.
	JSONEscape EscapeType = "json"
)

type ExperimentOptions added in v0.4.0

type ExperimentOptions struct {
	ChunkedTransfer bool `json:"chunked_transfer" yaml:"chunked_transfer"`
}

ExperimentOptions defines experimental features.

type File added in v0.3.0

type File struct {
	DataID string `json:"data_id" yaml:"data_id"`
	Group  string `json:"group"   yaml:"group"`
}

File defines Nacos data ID and group.

type FileProviderOptions

type FileProviderOptions struct {
	Paths      []string `json:"paths"      yaml:"paths"`
	Extensions []string `json:"extensions" yaml:"extensions"`
	Enabled    bool     `json:"enabled"    yaml:"enabled"`
}

FileProviderOptions defines configuration for the file-based configuration provider.

type HealthCheckOptions added in v0.4.0

type HealthCheckOptions struct {
	Passive PassiveHealthOptions `json:"passive" yaml:"passive"`
	Active  ActiveHealthOptions  `json:"active"  yaml:"active"`
}

HealthCheckOptions defines health check configuration.

type InvalidConfigError added in v0.9.0

type InvalidConfigError struct {
	Value     any
	Message   string
	Structure []string
}

InvalidConfigError represents an error in the configuration.

func (InvalidConfigError) Error added in v0.9.0

func (e InvalidConfigError) Error() string

type K8SProviderOptions added in v0.5.0

type K8SProviderOptions struct {
	APIServer string `json:"api_server" yaml:"api_server"`
	Enabled   bool   `json:"enabled"    yaml:"enabled"`
}

K8SProviderOptions defines configuration for Kubernetes service discovery.

type LoggingOptions added in v0.10.0

type LoggingOptions struct {
	Level                    string `json:"level"                      yaml:"level"`
	Handler                  string `json:"handler"                    yaml:"handler"`
	Output                   string `json:"output"                     yaml:"output"`
	DisableRedirectStdStream bool   `json:"disable_redirect_stdstream" yaml:"disable_redirect_stdstream"`
}

LoggingOptions defines configuration for logging.

type MetricsOptions

type MetricsOptions struct {
	Prometheus PrometheusOptions  `json:"prometheus" yaml:"prometheus"`
	OTLP       OTLPMetricsOptions `json:"otlp"       yaml:"otlp"`
}

MetricsOptions defines configuration for metrics collection.

type MiddlwareOptions

type MiddlwareOptions struct {
	ID     string `json:"-"      yaml:"-"`
	Type   string `json:"type"   yaml:"type"`
	Params any    `json:"params" yaml:"params"`
	Use    string `json:"use"    yaml:"use"`
}

MiddlwareOptions defines configuration for a middleware.

type NacosConfigOptions added in v0.3.0

type NacosConfigOptions struct {
	Watch       *bool         `json:"watch"        yaml:"watch"`
	Username    string        `json:"username"     yaml:"username"`
	Password    string        `json:"password"     yaml:"password"`
	NamespaceID string        `json:"namespace_id" yaml:"namespace_id"`
	Prefix      string        `json:"prefix"       yaml:"prefix"`
	LogLevel    string        `json:"log_level"    yaml:"log_level"`
	LogDir      string        `json:"log_dir"      yaml:"log_dir"`
	CacheDir    string        `json:"cache_dir"    yaml:"cache_dir"`
	Endpoints   []string      `json:"endpoints"    yaml:"endpoints"`
	Files       []*File       `json:"files"        yaml:"files"`
	Timeout     time.Duration `json:"timeout"      yaml:"timeout"`
	Enabled     bool          `json:"enabled"      yaml:"enabled"`
}

NacosConfigOptions defines configuration for Nacos configuration center.

type NacosDiscoveryOptions added in v0.4.0

type NacosDiscoveryOptions struct {
	Username    string        `json:"username"     yaml:"username"`
	Password    string        `json:"password"     yaml:"password"`
	NamespaceID string        `json:"namespace_id" yaml:"namespace_id"`
	Prefix      string        `json:"prefix"       yaml:"prefix"`
	LogDir      string        `json:"log_dir"      yaml:"log_dir"`
	LogLevel    string        `json:"log_level"    yaml:"log_level"`
	CacheDir    string        `json:"cache_dir"    yaml:"cache_dir"`
	Endpoints   []string      `json:"endpoints"    yaml:"endpoints"`
	Timeout     time.Duration `json:"timeout"      yaml:"timeout"`
	Enabled     bool          `json:"enabled"      yaml:"enabled"`
}

NacosDiscoveryOptions defines configuration for Nacos service discovery.

type NacosProviderOptions added in v0.3.0

type NacosProviderOptions struct {
	Config    NacosConfigOptions    `json:"config"    yaml:"config"`
	Discovery NacosDiscoveryOptions `json:"discovery" yaml:"discovery"`
}

NacosProviderOptions defines configuration for Nacos provider.

type OTLPMetricsOptions added in v0.8.0

type OTLPMetricsOptions struct {
	ServiceName string        `json:"service_name" yaml:"service_name"`
	Endpoint    string        `json:"endpoint"     yaml:"endpoint"`
	Flush       time.Duration `json:"flush"        yaml:"flush"`
	Timeout     time.Duration `json:"timeout"      yaml:"timeout"`
	Insecure    bool          `json:"insecure"     yaml:"insecure"`
	Enabled     bool          `json:"enabled"      yaml:"enabled"`
}

OTLPMetricsOptions defines configuration for OpenTelemetry Protocol metrics.

type Observability added in v0.2.0

type Observability struct {
	Tracing ServerTracingOptions `json:"tracing" yaml:"tracing"`
}

Observability defines observability configuration.

type Options

type Options struct {
	Watch       *bool                       `json:"watch"            yaml:"watch"`
	AccessLogs  map[string]AccessLogOptions `json:"access_logs"      yaml:"access_logs"`
	Servers     map[string]ServerOptions    `json:"servers"          yaml:"servers"`
	RoutesMap   *yaml.Node                  `json:"routes"           yaml:"routes"`
	Middlewares map[string]MiddlwareOptions `json:"middlewares"      yaml:"middlewares"`
	Services    map[string]ServiceOptions   `json:"services"         yaml:"services"`
	Upstreams   map[string]UpstreamOptions  `json:"upstreams"        yaml:"upstreams"`
	Providers   ProviderOptions             `json:"providers"        yaml:"providers"`

	User            string          `json:"user"             yaml:"user"`
	Group           string          `json:"group"            yaml:"group"`
	Metrics         MetricsOptions  `json:"metrics"          yaml:"metrics"`
	Logging         LoggingOptions  `json:"logging"          yaml:"logging"`
	Routes          []*RouteOptions `json:"-"                yaml:"-"`
	Redis           []RedisOptions  `json:"redis"            yaml:"redis"`
	Resolver        ResolverOptions `json:"resolver"         yaml:"resolver"`
	Tracing         TracingOptions  `json:"tracing"          yaml:"tracing"`
	Default         DefaultOptions  `json:"default"          yaml:"default"`
	EventLoops      int             `json:"event_loops"      yaml:"event_loops"`
	TimerResolution time.Duration   `json:"timer_resolution" yaml:"timer_resolution"`
	SkipResolver    bool            `json:"-"                yaml:"-"`
	Gopool          bool            `json:"gopool"           yaml:"gopool"`
	// contains filtered or unexported fields
}

Options defines the global configuration for Bifrost.

func Load

func Load(path string) (Options, error)

Load reads and parses the configuration from the given path.

func NewOptions

func NewOptions() Options

NewOptions creates a new Options instance with default values.

func (*Options) ConfigPath added in v0.2.0

func (opt *Options) ConfigPath() string

ConfigPath returns the path to the configuration file.

func (*Options) IsWatch

func (opt *Options) IsWatch() bool

IsWatch returns true if configuration watching is enabled.

func (*Options) UnmarshalYAML added in v0.3.0

func (opt *Options) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML custom unmarshaler for Options.

type PassiveHealthOptions added in v0.4.0

type PassiveHealthOptions struct {
	MaxFails    *uint         `json:"max_fails"    yaml:"max_fails"`
	FailTimeout time.Duration `json:"fail_timeout" yaml:"fail_timeout"`
}

PassiveHealthOptions defines configuration for passive health checks.

type PrometheusOptions

type PrometheusOptions struct {
	ServerID string    `json:"server_id" yaml:"server_id"`
	Path     string    `json:"path"      yaml:"path"`
	Buckets  []float64 `json:"buckets"   yaml:"buckets"`
	Enabled  bool      `json:"enabled"   yaml:"enabled"`
}

PrometheusOptions defines configuration for Prometheus metrics.

type Protocol

type Protocol string

Protocol defines the network protocol.

const (
	// ProtocolHTTP represents the standard HTTP protocol.
	ProtocolHTTP Protocol = "http"
	// ProtocolHTTP2 represents the HTTP/2 protocol.
	ProtocolHTTP2 Protocol = "http2"
	// ProtocolGRPC represents the gRPC protocol.
	ProtocolGRPC Protocol = "grpc"
)

type ProviderOptions added in v0.8.0

type ProviderOptions struct {
	K8S   K8SProviderOptions   `json:"k8s"   yaml:"k8s"`
	Nacos NacosProviderOptions `json:"nacos" yaml:"nacos"`
	File  FileProviderOptions  `json:"file"  yaml:"file"`
	DNS   DNSProviderOptions   `json:"dns"   yaml:"dns"`
}

ProviderOptions defines configuration for different configuration providers.

type RedisOptions

type RedisOptions struct {
	ID       string   `json:"id"        yaml:"id"`
	Username string   `json:"username"  yaml:"username"`
	Password string   `json:"password"  yaml:"password"`
	Addrs    []string `json:"addrs"     yaml:"addrs"`
	DB       int      `json:"db"        yaml:"db"`
	SkipPing bool     `json:"skip_ping" yaml:"skip_ping"`
}

RedisOptions defines configuration for Redis.

type ResolverOptions

type ResolverOptions struct {
	Servers   []string      `json:"servers"    yaml:"servers"`
	Hostsfile string        `json:"hosts_file" yaml:"hosts_file"`
	Order     []string      `json:"order"      yaml:"order"`
	Timeout   time.Duration `json:"timeout"    yaml:"timeout"`
}

ResolverOptions defines configuration for DNS resolver.

type RouteOptions

type RouteOptions struct {
	ID          string             `json:"-"           yaml:"-"`
	Route       string             `json:"route"       yaml:"route"`
	ServiceID   string             `json:"service_id"  yaml:"service_id"`
	Methods     []string           `json:"methods"     yaml:"methods"`
	Paths       []string           `json:"paths"       yaml:"paths"`
	Servers     []string           `json:"servers"     yaml:"servers"`
	Tags        []string           `json:"tags"        yaml:"tags"`
	Middlewares []MiddlwareOptions `json:"middlewares" yaml:"middlewares"`
}

RouteOptions defines configuration for a route.

type ServerOptions

type ServerOptions struct {
	Observability      Observability        `json:"observability"         yaml:"observability"`
	TLS                TLSOptions           `json:"tls"                   yaml:"tls"`
	ID                 string               `json:"-"                     yaml:"-"`
	Bind               string               `json:"bind"                  yaml:"bind"`
	AccessLogID        string               `json:"access_log_id"         yaml:"access_log_id"`
	Logging            LoggingOptions       `json:"logging"               yaml:"logging"`
	Middlewares        []MiddlwareOptions   `json:"middlewares"           yaml:"middlewares"`
	TrustedCIDRS       []string             `json:"trusted_cidrs"         yaml:"trusted_cidrs"`
	RemoteIPHeaders    []string             `json:"remote_ip_headers"     yaml:"remote_ip_headers"`
	Timeout            ServerTimeoutOptions `json:"timeout"               yaml:"timeout"`
	Backlog            int                  `json:"backlog"               yaml:"backlog"`
	MaxRequestBodySize int                  `json:"max_request_body_size" yaml:"max_request_body_size"`
	ReadBufferSize     int                  `json:"read_buffer_size"      yaml:"read_buffer_size"`
	ReusePort          bool                 `json:"reuse_port"            yaml:"reuse_port"`
	TCPQuickAck        bool                 `json:"tcp_quick_ack"         yaml:"tcp_quick_ack"`
	TCPFastOpen        bool                 `json:"tcp_fast_open"         yaml:"tcp_fast_open"`
	HTTP2              bool                 `json:"http2"                 yaml:"http2"`
	PPROF              bool                 `json:"pprof"                 yaml:"pprof"`
	ProxyProtocol      bool                 `json:"proxy_protocol"        yaml:"proxy_protocol"`
}

ServerOptions defines configuration for a server instance.

type ServerTimeoutOptions

type ServerTimeoutOptions struct {
	Graceful  time.Duration `json:"graceful"     yaml:"graceful"`
	Idle      time.Duration `json:"idle_timeout" yaml:"idle"`
	KeepAlive time.Duration `json:"keepalive"    yaml:"keepalive"`
	Read      time.Duration `json:"read"         yaml:"read"`
	Write     time.Duration `json:"write"        yaml:"write"`
}

ServerTimeoutOptions defines timeout configuration for a server.

type ServerTracingOptions added in v0.2.0

type ServerTracingOptions struct {
	Enabled    *bool             `json:"enabled"    yaml:"enabled"`
	Attributes map[string]string `json:"attributes" yaml:"attributes"`
}

ServerTracingOptions defines tracing configuration for a server.

func (ServerTracingOptions) IsEnabled added in v0.2.0

func (options ServerTracingOptions) IsEnabled() bool

IsEnabled returns true if server tracing is enabled.

type ServiceOptions

type ServiceOptions struct {
	MaxConnsPerHost *int                  `json:"max_conns_per_host" yaml:"max_conns_per_host"`
	ID              string                `json:"-"                  yaml:"-"`
	Protocol        Protocol              `json:"protocol"           yaml:"protocol"`
	URL             string                `json:"url"                yaml:"url"`
	Middlewares     []MiddlwareOptions    `json:"middlewares"        yaml:"middlewares"`
	Timeout         ServiceTimeoutOptions `json:"timeout"            yaml:"timeout"`
	TLSVerify       bool                  `json:"tls_verify"         yaml:"tls_verify"`
	PassHostHeader  *bool                 `json:"pass_host_header"   yaml:"pass_host_header"`
}

ServiceOptions defines configuration for a service.

func (ServiceOptions) IsPassHostHeader added in v0.5.0

func (options ServiceOptions) IsPassHostHeader() bool

IsPassHostHeader returns true if host header should be passed to upstream.

type ServiceTimeoutOptions

type ServiceTimeoutOptions struct {
	Read        time.Duration `json:"read"          yaml:"read"`
	Write       time.Duration `json:"write"         yaml:"write"`
	Dail        time.Duration `json:"dail"          yaml:"dail"`
	MaxConnWait time.Duration `json:"max_conn_wait" yaml:"max_conn_wait"`
	GRPC        time.Duration `json:"grpc"          yaml:"grpc"`
}

ServiceTimeoutOptions defines timeout configuration for a service.

type TLSOptions

type TLSOptions struct {
	MinVersion string `json:"min_version" yaml:"min_version"`
	CertPEM    string `json:"cert_pem"    yaml:"cert_pem"`
	KeyPEM     string `json:"key_pem"     yaml:"key_pem"`
}

TLSOptions defines TLS configuration.

type TargetOptions

type TargetOptions struct {
	Target string            `json:"target" yaml:"target"`
	Weight uint32            `json:"weight" yaml:"weight"`
	Tags   map[string]string `json:"tags"   yaml:"tags"`
}

TargetOptions defines configuration for an upstream target.

type TracingOptions

type TracingOptions struct {
	ServiceName  string        `json:"service_name"  yaml:"service_name"`
	Endpoint     string        `json:"endpoint"      yaml:"endpoint"`
	Propagators  []string      `json:"propagators"   yaml:"propagators"`
	SamplingRate float64       `json:"sampling_rate" yaml:"sampling_rate"`
	BatchSize    int64         `json:"batch_size"    yaml:"batch_size"`
	QueueSize    int64         `json:"queue_size"    yaml:"queue_size"`
	Flush        time.Duration `json:"flush"         yaml:"flush"`
	Timeout      time.Duration `json:"timeout"       yaml:"timeout"`
	Enabled      bool          `json:"enabled"       yaml:"enabled"`
	Insecure     bool          `json:"insecure"      yaml:"insecure"`
}

TracingOptions defines global tracing configuration.

type UpstreamOptions

type UpstreamOptions struct {
	ID          string             `json:"-"            yaml:"-"`
	Balancer    BalancerOptions    `json:"balancer"     yaml:"balancer"`
	HashOn      string             `json:"hash_on"      yaml:"hash_on"`
	Discovery   DiscoveryOptions   `json:"discovery"    yaml:"discovery"`
	Targets     []TargetOptions    `json:"targets"      yaml:"targets"`
	HealthCheck HealthCheckOptions `json:"health_check" yaml:"health_check"`
}

UpstreamOptions defines configuration for an upstream service.

type ValidationMode added in v0.10.0

type ValidationMode int

ValidationMode defines the mode for configuration validation.

const (
	// ModeBasic only validates basic configuration values.
	ModeBasic ValidationMode = iota
	// ModeFull validates the entire configuration, including resource existence.
	ModeFull
)

Jump to

Keyboard shortcuts

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