Documentation ¶
Overview ¶
Package config creates a configuration using toml.
An example configuration looks like this:
# Anything defined here provides fallback defaults for all networks. # except the immediately following fields which are global-only. # In other words, all values you see in the network definition can be # defined here and all servers will use those values unless they have their # own defined. storefile = "/path/to/store/file.db" nocorecmds = false loglevel = "debug" logfile = "/path/to/file.log" secret_key = "myunbelievablylongandsecrettoken" ignores = ["hostsuffix"] # Most of the configuration values below have healthy defaults which means # you don't have to set any of them. servers, nick, username, realname is # enough! [networks.ircnet] servers = ["localhost:3333", "server.com:6667"] nick = "Nick" altnick = "Altnick" username = "Username" realname = "Realname" password = "Password" # TLS Options # If tls is on it will connect with tls. # If tls_cert, tls_key are set it will send it in an attempt to perform # mutual TLS with the irc server. # If tls_ca_cert is present it will be used as a CA when connecting tls = true tls_ca_cert = "/path/to/ca.crt" tls_cert = "/path/to/a.crt" tls_key = "/path/to/a.key" tls_insecure_skip_verify = false # Bot Internal Database Options nostate = false nostore = false # Auto(Re)Join controls. noautojoin = false # How many seconds after connect or while banned to wait to rejoin. joindelay = 5 # Flood control fine tuning knobs. floodlenpenalty = 120 floodtimeout = 10.0 floodstep = 2.0 # Send a ping to the server every X seconds. keepalive = 60.0 # Reconnection controls. noreconnect = false reconnecttimeout = 20 # For fallback of channels below. prefix = "." [[networks.ircnet.channels]] name = "#channel1" password = "pass1" prefix = "!" [[networks.ircnet.channels]] name = "&channel2" password = "pass2" prefix = "@" # Ext provides defaults for all exts, much as the global definitions provide # defaults for all networks. [ext] # Define listen to create a extension server for extensions to connect listen = "localhost:3333" # OR listen = "/path/to/unix.sock" # If tls key & cert are present the remote extensions will require # MUTUAL tls, meaning the client will have to present a certificate as # well, you can use tls_client_ca to control which ca cert is used # to verify the client (otherwise the system ca cert pool is used). # If tls_insecure_skip_verify is set, the client's certificate # will still be required but will not be verified tls_key = "/path/to/a.key" tls_cert = "/path/to/a.crt" tls_client_ca = "/path/to/ca.crt" # A CRL (revocation list) can be passed in, client certificates # can be revoked by adding them to the crl tls_client_revs = "/path/to/ca.crl" tls_insecure_skip_verify = false # Define the execdir to start all executables in the path. execdir = "/path/to/executables" # Ext configuration is deeply nested so we can configure it globally # based on the network, or based on the channel on that network, or even # on all channels on that network. [ext.config] # Global config value key = "stringvalue" [[ext.config.channels]] # All networks for #channel name = "#channel" key = "stringvalue" [ext.config.networks.ircnet] # All channels on ircnet network key = "stringvalue" [[ext.config.networks.ircnet.channels]] # Freenode's #channel name = "#channel1" key = "stringvalue" [exts.myext] # Define exec to specify a path to the executable to launch. # NOTE: Currently NOT USED exec = "/path/to/executable" # Defining this means that the bot will try to connect to this extension # rather than expecting it to connect to the listen server in the # global configuration. Server can also be unix:/path/to/sock # # NOTE: Currently NOT USED server = "localhost:44" tls_cert = "/path/to/a.crt" noverifycert = false [exts.myext.active] ircnet = ["#channel1", "#channel2"]
Once again note the fallback mechanisms between network and the "global scope" as well as the exts and ext. This can save you lots of repetitive typing.
Index ¶
- type Channel
- type Config
- func (c *Config) Clear()
- func (c *Config) Clone() *Config
- func (c *Config) DisplayErrors(logger log15.Logger)
- func (c *Config) Errors() []error
- func (c *Config) Ext(name string) *ExtNormalCTX
- func (c *Config) ExtGlobal() *ExtGlobalCTX
- func (c *Config) Exts() []string
- func (c *Config) Filename() string
- func (c *Config) FromFile(filename string) *Config
- func (c *Config) FromReader(reader io.Reader) *Config
- func (c *Config) FromString(config string) *Config
- func (c *Config) Ignores() ([]string, bool)
- func (c *Config) LogFile() (string, bool)
- func (c *Config) LogLevel() (string, bool)
- func (c *Config) Network(name string) *NetCTX
- func (c *Config) Networks() []string
- func (c *Config) NewExt(name string) *ExtNormalCTX
- func (c *Config) NewNetwork(name string) *NetCTX
- func (c *Config) NoCoreCmds() (bool, bool)
- func (c *Config) Replace(newConfig *Config) *Config
- func (c *Config) SecretKey() (string, bool)
- func (c *Config) SetIgnores(ignores []string) *Config
- func (c *Config) SetLogFile(val string) *Config
- func (c *Config) SetLogLevel(val string) *Config
- func (c *Config) SetNoCoreCmds(val bool) *Config
- func (c *Config) SetSecretKey(key string) *Config
- func (c *Config) SetStoreFile(val string) *Config
- func (c *Config) StoreFile() (string, bool)
- func (c *Config) ToFile(filename string) error
- func (c *Config) ToWriter(writer io.Writer) error
- func (c *Config) Validate() bool
- type ExtCTX
- func (e *ExtCTX) Active(network string) ([]string, bool)
- func (e *ExtCTX) NoReconnect() (bool, bool)
- func (e *ExtCTX) ReconnectTimeout() (uint, bool)
- func (e *ExtCTX) SetActive(network string, value []string) *ExtCTX
- func (e *ExtCTX) SetNoReconnect(val bool) *ExtCTX
- func (e *ExtCTX) SetReconnectTimeout(val uint) *ExtCTX
- type ExtGlobalCTX
- func (e *ExtGlobalCTX) Config(network, channel string) map[string]string
- func (e *ExtGlobalCTX) ConfigVal(network, channel, key string) (string, bool)
- func (e *ExtGlobalCTX) ExecDir() (string, bool)
- func (e *ExtGlobalCTX) Listen() (string, bool)
- func (e *ExtGlobalCTX) SetConfig(network, channel, key, value string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetExecDir(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetListen(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetTLSCert(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetTLSClientCA(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetTLSClientRevs(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetTLSInsecureSkipVerify(val bool) *ExtGlobalCTX
- func (e *ExtGlobalCTX) SetTLSKey(val string) *ExtGlobalCTX
- func (e *ExtGlobalCTX) TLSCert() (string, bool)
- func (e *ExtGlobalCTX) TLSClientCA() (string, bool)
- func (e *ExtGlobalCTX) TLSClientRevs() (string, bool)
- func (e *ExtGlobalCTX) TLSInsecureSkipVerify() (bool, bool)
- func (e *ExtGlobalCTX) TLSKey() (string, bool)
- type ExtNormalCTX
- func (e *ExtNormalCTX) Exec() (string, bool)
- func (e *ExtNormalCTX) Server() (string, bool)
- func (e *ExtNormalCTX) SetExec(val string) *ExtNormalCTX
- func (e *ExtNormalCTX) SetServer(val string) *ExtNormalCTX
- func (e *ExtNormalCTX) SetTLSCert(val string) *ExtNormalCTX
- func (e *ExtNormalCTX) SetTLSInsecureSkipVerify(val bool) *ExtNormalCTX
- func (e *ExtNormalCTX) SetUnix(val string) *ExtNormalCTX
- func (e *ExtNormalCTX) TLSCert() (string, bool)
- func (e *ExtNormalCTX) TLSInsecureSkipVerify() (bool, bool)
- func (e *ExtNormalCTX) Unix() (string, bool)
- type NetCTX
- func (n *NetCTX) Altnick() (string, bool)
- func (n *NetCTX) ChannelPrefix(channel string) (rune, bool)
- func (n *NetCTX) Channels() (map[string]Channel, bool)
- func (n *NetCTX) FloodLenPenalty() (uint, bool)
- func (n *NetCTX) FloodStep() (float64, bool)
- func (n *NetCTX) FloodTimeout() (float64, bool)
- func (n *NetCTX) JoinDelay() (uint, bool)
- func (n *NetCTX) KeepAlive() (float64, bool)
- func (n *NetCTX) Nick() (string, bool)
- func (n *NetCTX) NoAutoJoin() (bool, bool)
- func (n *NetCTX) NoReconnect() (bool, bool)
- func (n *NetCTX) NoState() (bool, bool)
- func (n *NetCTX) NoStore() (bool, bool)
- func (n *NetCTX) Password() (string, bool)
- func (n *NetCTX) Prefix() (rune, bool)
- func (n *NetCTX) Realname() (string, bool)
- func (n *NetCTX) ReconnectTimeout() (uint, bool)
- func (n *NetCTX) Servers() ([]string, bool)
- func (n *NetCTX) SetAltnick(val string) *NetCTX
- func (n *NetCTX) SetChannels(val []Channel) *NetCTX
- func (n *NetCTX) SetFloodLenPenalty(val uint) *NetCTX
- func (n *NetCTX) SetFloodStep(val float64) *NetCTX
- func (n *NetCTX) SetFloodTimeout(val float64) *NetCTX
- func (n *NetCTX) SetJoinDelay(val uint) *NetCTX
- func (n *NetCTX) SetKeepAlive(val float64) *NetCTX
- func (n *NetCTX) SetNick(val string) *NetCTX
- func (n *NetCTX) SetNoAutoJoin(val bool) *NetCTX
- func (n *NetCTX) SetNoReconnect(val bool) *NetCTX
- func (n *NetCTX) SetNoState(val bool) *NetCTX
- func (n *NetCTX) SetNoStore(val bool) *NetCTX
- func (n *NetCTX) SetPassword(val string) *NetCTX
- func (n *NetCTX) SetPrefix(val rune) *NetCTX
- func (n *NetCTX) SetRealname(val string) *NetCTX
- func (n *NetCTX) SetReconnectTimeout(val uint) *NetCTX
- func (n *NetCTX) SetServers(val []string) *NetCTX
- func (n *NetCTX) SetTLS(val bool) *NetCTX
- func (n *NetCTX) SetTLSCACert(val string) *NetCTX
- func (n *NetCTX) SetTLSCert(val string) *NetCTX
- func (n *NetCTX) SetTLSInsecureSkipVerify(val bool) *NetCTX
- func (n *NetCTX) SetTLSKey(val string) *NetCTX
- func (n *NetCTX) SetUsername(val string) *NetCTX
- func (n *NetCTX) TLS() (bool, bool)
- func (n *NetCTX) TLSCACert() (string, bool)
- func (n *NetCTX) TLSCert() (string, bool)
- func (n *NetCTX) TLSInsecureSkipVerify() (bool, bool)
- func (n *NetCTX) TLSKey() (string, bool)
- func (n *NetCTX) Username() (string, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds all the information related to the bot including global settings default settings, and network specific settings.
func (*Config) Clear ¶
func (c *Config) Clear()
Clear re-initializes all memory in the configuration.
func (*Config) DisplayErrors ¶
func (c *Config) DisplayErrors(logger log15.Logger)
DisplayErrors is a helper function to log the output of all config errors to the standard logger.
func (*Config) Ext ¶
func (c *Config) Ext(name string) *ExtNormalCTX
Ext returns the extension context useable to get/set fields for the given extension name.
func (*Config) ExtGlobal ¶
func (c *Config) ExtGlobal() *ExtGlobalCTX
ExtGlobal returns the global extension context useable to get/set fields for all extensions.
func (*Config) FromFile ¶
FromFile overwrites the current config with the contents of the file. It will use defaultConfigFileName if filename is the empty string.
func (*Config) FromReader ¶
FromReader overwrites the current config with the contents of the reader.
func (*Config) FromString ¶
FromString overwrites the current config with the contents of the string.
func (*Config) Network ¶
Network returns the network context useable to get/set the fields for that. Leave name blank to return the global network context.
func (*Config) NewExt ¶
func (c *Config) NewExt(name string) *ExtNormalCTX
NewExt creates a extension and returns the extension's context. If the extension exists, the context will be nil.
func (*Config) NewNetwork ¶
NewNetwork creates a network and returns the network's context. If the network exists, the context will be nil.
func (*Config) NoCoreCmds ¶
NoCoreCmds gets the value of the corecmds variable.
func (*Config) SetIgnores ¶
SetIgnores sets the ignores array
func (*Config) SetLogFile ¶
SetLogFile sets the global logfile or defaultLogFile.
func (*Config) SetLogLevel ¶
SetLogLevel sets the global loglevel or defaultLogLevel.
func (*Config) SetNoCoreCmds ¶
SetNoCoreCmds gets the value of the corecmds variable.
func (*Config) SetSecretKey ¶
SetSecretKey value in the config.
func (*Config) SetStoreFile ¶
SetStoreFile sets the global storefile or defaultStoreFile.
func (*Config) ToFile ¶
ToFile writes a config out to a writer. If the filename is empty it will write to the file that this config was loaded from, or it will write to the defaultConfigFileName.
type ExtCTX ¶
type ExtCTX struct {
// contains filtered or unexported fields
}
ExtCTX is an extension context. It's getters and setters are available on both the ExtGlobalCTX and the ExtNormalCTX. When using getters from ExtCTX on an ExtNormalCTX they will fallback to the parent if there is none set.
func (*ExtCTX) NoReconnect ¶
func (*ExtCTX) ReconnectTimeout ¶
func (*ExtCTX) SetNoReconnect ¶
func (*ExtCTX) SetReconnectTimeout ¶
type ExtGlobalCTX ¶
type ExtGlobalCTX struct {
*ExtCTX
}
ExtGlobalCTX is the configuration context for the global extension config portion.
func (*ExtGlobalCTX) Config ¶
func (e *ExtGlobalCTX) Config(network, channel string) map[string]string
Config returns a map of config values for the given network and channel. Global values are overidden by more specific ones, and all global values are shared.
[ext.config] key = "val" global = "val" [ext.config.channels.#channel] key = "chan" [ext.config.networks.ircnet] key = "net" [ext.config.networks.ircnet.channels.#channel] key = "netchan"
Given this configuration these results are expected:
Config("", "") => key: "val", global: "val" Config("net", "") => key: "chan", global: "val" Config("", "chan") => key: "net", global: "val" Config("net", "chan") => key: "netchan", global: "val"
func (*ExtGlobalCTX) ConfigVal ¶
func (e *ExtGlobalCTX) ConfigVal(network, channel, key string) (string, bool)
ConfigVal returns a value from the configuration with proper fallbacking to the global extension config. Ok is false if the key was not found.
func (*ExtGlobalCTX) ExecDir ¶
func (e *ExtGlobalCTX) ExecDir() (string, bool)
func (*ExtGlobalCTX) Listen ¶
func (e *ExtGlobalCTX) Listen() (string, bool)
func (*ExtGlobalCTX) SetConfig ¶
func (e *ExtGlobalCTX) SetConfig(network, channel, key, value string) *ExtGlobalCTX
SetConfig sets a key value pair for a given network and channel. If you leave either network or channel empty, then it's set at the global level for that portion.
[ext.config] # SetConfig("", "", "key", "val") key = "val" [ext.config.channels.#channel] # SetConfig("", "#channel", "key", "val") key = "val" [ext.config.networks.ircnet] # SetConfig("ircnet", "", "key", "val") key = "val" [ext.config.networks.ircnet.channels.#channel] # SetConfig("ircnet", "#channel", "key", "val") key = "val"
func (*ExtGlobalCTX) SetExecDir ¶
func (e *ExtGlobalCTX) SetExecDir(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) SetListen ¶
func (e *ExtGlobalCTX) SetListen(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) SetTLSCert ¶
func (e *ExtGlobalCTX) SetTLSCert(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) SetTLSClientCA ¶
func (e *ExtGlobalCTX) SetTLSClientCA(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) SetTLSClientRevs ¶
func (e *ExtGlobalCTX) SetTLSClientRevs(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) SetTLSInsecureSkipVerify ¶
func (e *ExtGlobalCTX) SetTLSInsecureSkipVerify(val bool) *ExtGlobalCTX
func (*ExtGlobalCTX) SetTLSKey ¶
func (e *ExtGlobalCTX) SetTLSKey(val string) *ExtGlobalCTX
func (*ExtGlobalCTX) TLSCert ¶
func (e *ExtGlobalCTX) TLSCert() (string, bool)
func (*ExtGlobalCTX) TLSClientCA ¶
func (e *ExtGlobalCTX) TLSClientCA() (string, bool)
func (*ExtGlobalCTX) TLSClientRevs ¶
func (e *ExtGlobalCTX) TLSClientRevs() (string, bool)
func (*ExtGlobalCTX) TLSInsecureSkipVerify ¶
func (e *ExtGlobalCTX) TLSInsecureSkipVerify() (bool, bool)
func (*ExtGlobalCTX) TLSKey ¶
func (e *ExtGlobalCTX) TLSKey() (string, bool)
type ExtNormalCTX ¶
type ExtNormalCTX struct {
*ExtCTX
}
ExtNormalCTX is the configuration context for normal extensions (not global). All methods that are embedded from ExtCTX will fallback to the global values if they are not specifically set on this context.
func (*ExtNormalCTX) Exec ¶
func (e *ExtNormalCTX) Exec() (string, bool)
func (*ExtNormalCTX) Server ¶
func (e *ExtNormalCTX) Server() (string, bool)
func (*ExtNormalCTX) SetExec ¶
func (e *ExtNormalCTX) SetExec(val string) *ExtNormalCTX
func (*ExtNormalCTX) SetServer ¶
func (e *ExtNormalCTX) SetServer(val string) *ExtNormalCTX
func (*ExtNormalCTX) SetTLSCert ¶
func (e *ExtNormalCTX) SetTLSCert(val string) *ExtNormalCTX
func (*ExtNormalCTX) SetTLSInsecureSkipVerify ¶
func (e *ExtNormalCTX) SetTLSInsecureSkipVerify(val bool) *ExtNormalCTX
func (*ExtNormalCTX) SetUnix ¶
func (e *ExtNormalCTX) SetUnix(val string) *ExtNormalCTX
func (*ExtNormalCTX) TLSCert ¶
func (e *ExtNormalCTX) TLSCert() (string, bool)
func (*ExtNormalCTX) TLSInsecureSkipVerify ¶
func (e *ExtNormalCTX) TLSInsecureSkipVerify() (bool, bool)
func (*ExtNormalCTX) Unix ¶
func (e *ExtNormalCTX) Unix() (string, bool)
type NetCTX ¶
type NetCTX struct {
// contains filtered or unexported fields
}
NetCTX is a context for network parts of the config, allowing querying and setting of network related values. If this context belongs to a specific network and not the global network configuration, all the values will fallback to the global configuration if not set.
func (*NetCTX) ChannelPrefix ¶
ChannelPrefix retrieves the prefix with the correct default chain up to network and global space.