Documentation ¶
Index ¶
- Variables
- func InitConfig(v *viper.Viper, name string)
- func Log(ctx context.Context, e *zerolog.Event, format string, v ...any)
- func ValidateConfig(validate *validator.Validate, cfg *Config) error
- type Config
- type ListenerConfig
- type ListenerPolicyConfig
- type NetworkConfig
- type ReqIdCtxKey
- type Resolver
- type Rule
- type ServiceConfig
- type UpstreamConfig
Constants ¶
This section is empty.
Variables ¶
var ProxyLog = zerolog.New(io.Discard)
ProxyLog emits the log record for proxy operations. The caller should set it only once.
Functions ¶
func InitConfig ¶
InitConfig initializes default config values for given *viper.Viper instance.
func Log ¶
Log emits the logs for a particular zerolog event. The request id associated with the context will be included if presents.
func ValidateConfig ¶
ValidateConfig validates the given config.
Types ¶
type Config ¶
type Config struct { Service ServiceConfig `mapstructure:"service"` Network map[string]*NetworkConfig `mapstructure:"network" toml:"network" validate:"min=1,dive"` Upstream map[string]*UpstreamConfig `mapstructure:"upstream" toml:"upstream" validate:"min=1,dive"` Listener map[string]*ListenerConfig `mapstructure:"listener" toml:"listener" validate:"min=1,dive"` }
Config represents ctrld supported configuration.
type ListenerConfig ¶
type ListenerConfig struct { IP string `mapstructure:"ip" toml:"ip" validate:"ip"` Port int `mapstructure:"port" toml:"port" validate:"gt=0"` Restricted bool `mapstructure:"restricted" toml:"restricted"` Policy *ListenerPolicyConfig `mapstructure:"policy" toml:"policy"` }
ListenerConfig specifies the networks configuration that ctrld will run on.
func (*ListenerConfig) Init ¶
func (lc *ListenerConfig) Init()
Init initialized necessary values for an ListenerConfig.
type ListenerPolicyConfig ¶
type ListenerPolicyConfig struct { Name string `mapstructure:"name" toml:"name"` Networks []Rule `mapstructure:"networks" toml:"networks" validate:"dive,len=1"` Rules []Rule `mapstructure:"rules" toml:"rules" validate:"dive,len=1"` FailoverRcodes []string `mapstructure:"failover_rcodes" toml:"failover_rcodes" validate:"dive,dnsrcode"` FailoverRcodeNumbers []int `mapstructure:"-" toml:"-"` }
ListenerPolicyConfig specifies the policy rules for ctrld to filter incoming requests.
type NetworkConfig ¶
type NetworkConfig struct { Name string `mapstructure:"name" toml:"name"` Cidrs []string `mapstructure:"cidrs" toml:"cidrs" validate:"dive,cidr"` IPNets []*net.IPNet `mapstructure:"-" toml:"-"` }
NetworkConfig specifies configuration for networks where ctrld will handle requests.
type ReqIdCtxKey ¶
type ReqIdCtxKey struct{}
ReqIdCtxKey is the context.Context key for a request id.
type Resolver ¶
Resolver is the interface that wraps the basic DNS operations.
Resolve resolves the DNS query, return the result and the corresponding error.
func NewResolver ¶
func NewResolver(uc *UpstreamConfig) (Resolver, error)
NewResolver creates a Resolver based on the given upstream config.
type Rule ¶
Rule is a map from source to list of upstreams. ctrld uses rule to perform requests matching and forward the request to corresponding upstreams if it's matched.
type ServiceConfig ¶
type ServiceConfig struct { LogLevel string `mapstructure:"log_level" toml:"log_level"` LogPath string `mapstructure:"log_path" toml:"log_path"` Daemon bool `mapstructure:"-" toml:"-"` AllocateIP bool `mapstructure:"-" toml:"-"` }
ServiceConfig specifies the general ctrld config.
type UpstreamConfig ¶
type UpstreamConfig struct { Name string `mapstructure:"name" toml:"name"` Type string `mapstructure:"type" toml:"type" validate:"oneof=doh doh3 dot doq os legacy"` Endpoint string `mapstructure:"endpoint" toml:"endpoint" validate:"required_unless=Type os"` BootstrapIP string `mapstructure:"bootstrap_ip" toml:"bootstrap_ip"` Domain string `mapstructure:"-" toml:"-"` Timeout int `mapstructure:"timeout" toml:"timeout" validate:"gte=0"` }
UpstreamConfig specifies configuration for upstreams that ctrld will forward requests to.
func (*UpstreamConfig) Init ¶
func (uc *UpstreamConfig) Init()
Init initialized necessary values for an UpstreamConfig.