config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OnChanged provider.ChangeFunc
)

Functions

func IsValidDomain added in v0.2.0

func IsValidDomain(domain string) bool

func TestAndSkipResovler added in v0.3.0

func TestAndSkipResovler(path string) (string, error)

func ValidateConfig

func ValidateConfig(mainOptions Options, isFullMode bool) 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

Types

type AccessLogOptions

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

type ActiveHealthOptions added in v0.4.0

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

type ChangeFunc

type ChangeFunc func() error

type DNSProviderOptions added in v0.4.0

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

type DefaultOptions added in v0.3.0

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

type DefaultServiceOptions added in v0.3.0

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

type DefaultUpstreamOptions added in v0.3.0

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

type DiscoveryOptions added in v0.4.0

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

type ErrInvalidConfig

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

func (ErrInvalidConfig) Error

func (e ErrInvalidConfig) Error() string

type EscapeType

type EscapeType string
const (
	NoneEscape    EscapeType = "none"
	DefaultEscape EscapeType = "default"
	JSONEscape    EscapeType = "json"
)

type ExperimentOptions added in v0.4.0

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

type File added in v0.3.0

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

type FileProviderOptions

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

type HealthCheckOptions added in v0.4.0

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

type K8SProviderOptions added in v0.5.0

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

type LoggingOtions

type LoggingOtions struct {
	Level                 string `yaml:"level" json:"level"`
	Handler               string `yaml:"handler" json:"handler"`
	Output                string `yaml:"output" json:"output"`
	DisableRedirectStdErr bool   `yaml:"disable_redirect_stderr" json:"disable_redirect_stderr"`
}

type MetricsOptions

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

type MiddlwareOptions

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

type NacosConfigOptions added in v0.3.0

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

type NacosDiscoveryOptions added in v0.4.0

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

type NacosProviderOptions added in v0.3.0

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

type Observability added in v0.2.0

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

type Options

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

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

func Load

func Load(path string) (Options, error)

func NewOptions

func NewOptions() Options

func (Options) ConfigPath added in v0.2.0

func (opt Options) ConfigPath() string

func (Options) IsWatch

func (opt Options) IsWatch() bool

func (*Options) UnmarshalYAML added in v0.3.0

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

type PassiveHealthOptions added in v0.4.0

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

type PrometheusOptions

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

type Protocol

type Protocol string
const (
	ProtocolHTTP  Protocol = "http"
	ProtocolHTTP2 Protocol = "http2"
	ProtocolGRPC  Protocol = "grpc"
)

type ProviderOtions

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

type RedisOptions

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

type ResolverOptions

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

type RouteOptions

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

type ServerOptions

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

type ServerTimeoutOptions

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

type ServerTracingOptions added in v0.2.0

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

func (ServerTracingOptions) IsEnabled added in v0.2.0

func (options ServerTracingOptions) IsEnabled() bool

type ServiceOptions

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

func (ServiceOptions) IsPassHostHeader added in v0.5.0

func (options ServiceOptions) IsPassHostHeader() bool

type ServiceTimeoutOptions

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

type TLSOptions

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

type TargetOptions

type TargetOptions struct {
	Target string `yaml:"target" json:"target"`
	Weight uint32 `yaml:"weight" json:"weight"`
}

type TracingOptions

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

type UpstreamOptions

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

type UpstreamStrategy

type UpstreamStrategy string
const (
	RandomStrategy     UpstreamStrategy = "random"
	RoundRobinStrategy UpstreamStrategy = "round_robin"
	WeightedStrategy   UpstreamStrategy = "weighted"
	HashingStrategy    UpstreamStrategy = "hashing"
)

Jump to

Keyboard shortcuts

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