config

package
v0.0.0-...-c02b23a Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultExt  = ".conf"
	DefaultPath = "./"
)
View Source
const (
	DefaultLockTTL = time.Second * 90
)

Variables

This section is empty.

Functions

func ConfigureLogging

func ConfigureLogging(config *LoggingConfig) (hclog.Logger, error)

ConfigureLogging will take the logging configuration and also adds a few default parameters

func CreateDistributedLock

func CreateDistributedLock(config *mongoConf) (*lock.Client, error)

CreateDistributedLock creates the the lock

func DecodeToml

func DecodeToml(file string, val interface{}) error

func EncodeToml

func EncodeToml(val interface{}) ([]byte, error)

func ParseJsonFile

func ParseJsonFile(f string, val interface{}) error

Types

type Config

type Config struct {
	Paths []string
	Files []string
}

func New

func New() *Config

func (*Config) AddPath

func (c *Config) AddPath(path string) error

func (*Config) Load

func (c *Config) Load() error

func (*Config) Parse

func (c *Config) Parse(v interface{}) error

func (*Config) Watch

func (c *Config) Watch(dir string)

func (*Config) WatchConfig

func (c *Config) WatchConfig()

type ConfigConnection

type ConfigConnection struct {
	Type          string `json:"type" hcl:",label"`
	User          string `json:"username" hcl:"username"`
	Password      string `json:"password" hcl:"password"`
	Port          int    `json:"port" hcl:"port"`
	ScreenLength  string `json:"screen_length" hcl:"screen_length,optional"`
	RegexPrompt   string `json:"default_prompt" hcl:"default_prompt"`
	Errors        string `json:"default_errors" hcl:"default_errors"`
	CacheTTL      string `json:"cache_ttl" hcl:"cache_ttl,optional"`
	ReadDeadLine  string `json:"read_dead_line" hcl:"read_dead_line,optional"`
	WriteDeadLine string `json:"write_dead_line" hcl:"write_dead_line,optional"`
	SSHKeyPath    string `json:"ssh_key_path" hcl:"ssh_key_path,optional"`
}

func (ConfigConnection) CastToConnection

func (c ConfigConnection) CastToConnection() (*connection.Config, error)

type ConfigSnmp

type ConfigSnmp struct {
	StringVersion      string `json:"stringVersion" hcl:",label"`
	Community          string `json:"community" hcl:"community"`
	Version            uint8  `json:"version" hcl:"version,optional"`
	Port               uint16 `json:"port" hcl:"port"`
	Timeout            string `json:"timeout" hcl:"timeout"`
	Retries            int    `json:"retries" hcl:"retries"`
	MaxIterations      int    `json:"max_iterations" hcl:"max_iterations,optional"`
	MaxRepetitions     int    `json:"max_repetitions" hcl:"max_repetitions,optional"`
	NonRepeaters       int    `json:"non_repeaters" hcl:"non_repeaters,optional"`
	DynamicRepetitions bool   `json:"dynamic_repetitions" hcl:"dynamic_repetitions,optional"`
}

func (ConfigSnmp) CastToSNMPC

func (c ConfigSnmp) CastToSNMPC() (*snmpc.C, error)

type Configuration

type Configuration struct {
	// Default
	Group       string             `json:"group" hcl:"group"`
	NatsServers []*NatsServerEntry `json:"nats_servers" hcl:"nats_server,block"`

	ReceiverQueues []string `json:"receiver_queues" hcl:"receiver_queues"`
	ResponseGroup  string   `json:"response_group" hcl:"response_group"`

	LogConfig *LoggingConfig `json:"logging" hcl:"logging,block"`

	RPCPort int `json:"rpc_port" hcl:"rpc_port"`

	// Poller
	Poller *PollerConf `json:"poller" hcl:"poller,block"`

	// Dispatcher
	Dispatcher *DispatcherConf `json:"dispatcher" hcl:"dispatcher,block"`

	MongoConf *mongoConf `json:"mongo" hcl:"mongo,block"`
	LockConf  *LockConf  `json:"distributed_lock" hcl:"distributed_lock,block"`
}

Configuration is the place to store your config for this app.

func DefaultConfig

func DefaultConfig() *Configuration

DefaultConfig returns a default configuration

func LoadConfig

func LoadConfig(cmd *cobra.Command) (*Configuration, error)

func Parse

func Parse(src []byte, filename string) (c *Configuration, err error)

func (Configuration) GetServers

func (c Configuration) GetServers() (string, error)

GetServers parses the NatsServerEntries and returns a []string with servers server:port, server:port ...

type DispatcherConf

type DispatcherConf struct {
	SendCache    int `json:"send_queue_cache" hcl:"send_queue_cache"`
	ReceiveCache int `json:"receive_queue_cache" hcl:"receive_queue_cache"`
}

type LockConf

type LockConf struct {
	Enabled bool `hcl:"enabled,attr"`
	// Parse as time.Duration(	)
	TTL string `hcl:"ttl,attr"`
}

func (LockConf) GetTTL

func (c LockConf) GetTTL() time.Duration

func (LockConf) ParseTTL

func (c LockConf) ParseTTL() (time.Duration, error)

ParseTTL parses and returns a time.Duration from TTL(string)

type LoggingConfig

type LoggingConfig struct {
	Level string `hcl:"level,optional"`
	File  string `hcl:"file,optional"`
	Json  bool   `hcl:"as_json,optional"`
}

LoggingConfig specifies all the parameters needed for logging

type MongoServerEntry

type MongoServerEntry struct {
	Addr    string `hcl:"addr"`
	Port    int    `hcl:"port"`
	Replica string `hcl:"replica,optional"`
}

type NatsServerEntry

type NatsServerEntry struct {
	Addr string `hcl:"addr"`
	Port int    `hcl:"port"`
}

NatsServer

type PollerConf

type PollerConf struct {
	MessageCache int                 `json:"message_cache" hcl:"message_cache"`
	NoWorkers    int                 `json:"workers" hcl:"workers"`
	Snmp         []*ConfigSnmp       `json:"snmp" hcl:"snmp,block"`
	Connection   []*ConfigConnection `json:"connection" hcl:"connection,block"`
}

Jump to

Keyboard shortcuts

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