Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalDotEnv ¶
func RegisterFlags ¶
func RegisterFlags[T any](config *T, persistent bool, app *cobra.Command, options ...ParseOption) func() error
Parse takes every object and is able to fill and validate that object depending on config file, env file and flag values. https://github.com/knadh/koanf Your passed struct must define . delimited koanf struct tags in order to match env/.env and flag values to your struct. Additionally your struct may define a Validate() error method which is called at the end of parsing the config Registers flags and returns a parser function that can be used as PreRunE.
Types ¶
type Config ¶
type Config struct { IPHubToken string `koanf:"iphub.token" description:"api key for https://iphub.info"` ProxyCheckToken string `koanf:"proxycheck.token" description:"api key for https://proxycheck.io"` VPNApiToken string `koanf:"vpnapi.token" description:"api key for https://vpnapi.io"` RedisAddress string `koanf:"redis.address" validate:"required"` RedisPassword string `koanf:"redis.password" description:"optional password for the redis database"` RedisDB int `koanf:"redis.db.vpn" validate:"gte=0,lte=15" description:"redis database to use for the vpn ip data (0-15)"` EconServersString string `koanf:"econ.addresses" validate:"required" description:"comma separated list of econ addresses"` EconServers []string EconPasswordsString string `koanf:"econ.passwords" validate:"required" description:"comma separated list of econ passwords"` EconPasswords []string ReconnectDelay time.Duration `koanf:"reconnect.delay" validate:"required"` ReconnectTimeout time.Duration `koanf:"reconnect.timeout" validate:"required"` VPNBanTime time.Duration `koanf:"vpn.ban.duration" validate:"required"` VPNBanReason string `koanf:"vpn.ban.reason" validate:"required"` Offline bool `` /* 137-byte string literal not displayed */ BanThreshold float64 `koanf:"perma.ban.threshold" validate:"required"` Whitelist string `koanf:"ip.whitelist" description:"comma separated list of ip ranges to whitelist"` Blacklist string `koanf:"ip.blacklist" description:"comma separated list of ip ranges to blacklist"` Whitelists []string Blacklists []string }
Config represents the application configuration
func New ¶
func New() *Config
New creates a new configuration file based on the data that has been retrieved from the .env environment file. any call after the first one will return the config of the first call the location of the .env file can be changed via the DefaultEnvFile variable
type ConnectConfig ¶
type ConnectConfig struct { RedisAddress string `koanf:"redis.address" validate:"required"` RedisPassword string `koanf:"redis.password"` RedisDB int `koanf:"redis.db.vpn"` }
func NewConnect ¶
func NewConnect() *ConnectConfig
func (*ConnectConfig) Validate ¶
func (c *ConnectConfig) Validate() error
type ParseOption ¶
type ParseOption func(*parseOption)
func WithDelimiter ¶
func WithDelimiter(delimiter string) ParseOption
func WithDescriptionStructTagName ¶
func WithDescriptionStructTagName(tag string) ParseOption
func WithEnvPrefix ¶
func WithEnvPrefix(prefix string) ParseOption
func WithStructTagName ¶
func WithStructTagName(tag string) ParseOption
func WithoutConfigFile ¶
func WithoutConfigFile() ParseOption
WithoutConfigFile removes the -c or --config flag from the command
type Validatable ¶
type Validatable interface {
Validate() error
}