config

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalDotEnv

func MarshalDotEnv(cfgs ...any) ([]byte, error)

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)"`

	NutsDBDir    string        `koanf:"nutsdb.dir" validate:"required" description:"directory to store the nutsdb database"`
	NutsDBBucket string        `koanf:"nutsdb.bucket" validate:"required" description:"bucket name for the nutsdb key value database"`
	WhitelistTTL time.Duration `koanf:"whitelist.ttl" validate:"required" description:"time to live for whitelisted ips"`

	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 `` /* 170-byte string literal not displayed */

	Whitelist string `koanf:"ip.whitelist" description:"comma separated list of files to whitelist"`
	Blacklist string `koanf:"ip.blacklist" description:"comma separated list of files 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

func (*Config) APIs

func (c *Config) APIs() []vpn.VPN

apis returns a list of available apis that is constructed based on the configuration

func (*Config) Validate

func (c *Config) Validate() error

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
}

Jump to

Keyboard shortcuts

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