config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cover

func Cover(path string, config *Config) error

func Exist

func Exist(path string) (bool, error)

func GetStringSlicePreserveString

func GetStringSlicePreserveString(cfg Provider, key string) []string

GetStringSlicePreserveString returns a string slice from the given config and key. It differs from the GetStringSlice method in that if the config value is a string, we do not attempt to split it into fields.

func MakeDir

func MakeDir(path string) error

func RandSecret

func RandSecret() ([]byte, error)

RandSecret If the daemon does not have a secret key configured, it is automatically generated

Types

type Config

type Config struct {
	Port         string        `json:"port"`
	Secret       string        `json:"secret"`
	ReadTimeout  time.Duration `json:"readTimeout"`
	WriteTimeout time.Duration `json:"writeTimeout"`
	IdleTimeout  time.Duration `json:"idleTimeout"`
	Log          *LogConfig    `json:"log"`
	DB           *DBConfig     `json:"db"`
}

func DecodeConfig

func DecodeConfig(path string) (c *Config, err error)

func DefaultConfig

func DefaultConfig() (*Config, error)

type DBConfig

type DBConfig struct {
	Type         DBType        `json:"type"`
	DSN          string        `json:"dsn"`
	MaxOpenConns int           `json:"maxOpenConns"`
	MaxIdleConns int           `json:"maxIdleConns"`
	MaxLifeTime  time.Duration `json:"maxLifeTime"`
	MaxIdleTime  time.Duration `json:"maxIdleTime"`
}

type DBType

type DBType = string
const (
	Mysql  DBType = "mysql"
	Badger DBType = "badger"
)

type InfluxDBConfig

type InfluxDBConfig struct {
	ServerURL     string        `json:"serverURL"`
	AuthToken     string        `json:"authToken"`
	Org           string        `json:"org"`
	Bucket        string        `json:"bucket"`
	FlushInterval time.Duration `json:"flushInterval"`
	BatchSize     uint          `json:"batchSize"`
}

type LogConfig

type LogConfig struct {
	LogLevel   string          `json:"logLevel"`
	Type       LogHookType     `json:"type"`
	HookSwitch bool            `json:"hookSwitch"`
	InfluxDB   *InfluxDBConfig `json:"influxdb"`
}

type LogHookType

type LogHookType = int
const (
	LHTInfluxDB LogHookType = 1
)

type Provider

type Provider interface {
	GetString(key string) string
	GetInt(key string) int
	GetBool(key string) bool
	GetStringMap(key string) map[string]interface{}
	GetStringMapString(key string) map[string]string
	GetStringSlice(key string) []string
	Get(key string) interface{}
	Set(key string, value interface{})
	IsSet(key string) bool
	WatchConfig()
	OnConfigChange(run func(in fsnotify.Event))
	Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error
	UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error
}

func FromConfigString

func FromConfigString(path, configType string) (Provider, error)

FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.

Jump to

Keyboard shortcuts

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