config

package
v0.0.0-...-5398a0e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config provides several ways to configure an irc bot. Some methods are inline fluent configuration, yaml reading from any io.Reader. It also provides config validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlushConfigToFile

func FlushConfigToFile(conf *Config, filename string) (err error)

FlushConfigToFile 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.

func FlushConfigToWriter

func FlushConfigToWriter(conf *Config, writer io.Writer) (err error)

FlushConfigToWriter writes a config out to a writer

Types

type Config

type Config struct {
	Servers map[string]*Server
	Global  *Server

	Storefile string
	Errors    []error "-"
	// contains filtered or unexported fields
}

Config holds all the information related to the bot including global settings default settings, and server specific settings.

func CreateConfig

func CreateConfig() *Config

CreateConfig initializes a Config object.

func CreateConfigFromFile

func CreateConfigFromFile(filename string) *Config

CreateConfigFromFile initializes a Config object from a file.

func CreateConfigFromReader

func CreateConfigFromReader(reader io.Reader) *Config

CreateConfigFromReader initializes a Config object from a reader.

func (*Config) Altnick

func (c *Config) Altnick(altnick string) *Config

Altnick fluently sets the altnick for the current config context

func (*Config) Channels

func (c *Config) Channels(channels ...string) *Config

Channels fluently sets the channels for the current config context

func (*Config) Clone

func (c *Config) Clone() *Config

Clone deep copies a configuration object.

func (*Config) DisplayErrors

func (c *Config) DisplayErrors()

DisplayErrors is a helper function to log the output of all config to the standard logger.

func (*Config) FloodLenPenalty

func (c *Config) FloodLenPenalty(floodlenPenalty uint) *Config

FloodLenPenalty fluently sets flood lenPenalty for the current config context. This is how many characters in a message will generate an extra second of flood protection penalty.

func (*Config) FloodStep

func (c *Config) FloodStep(floodstep float64) *Config

FloodStep fluently sets flood protect step for the current config context, this is how many seconds as a base are used to protect against flooding, but may be added on to by FloodLenPenalty for sufficiently long messages.

func (*Config) FloodTimeout

func (c *Config) FloodTimeout(floodtimeout float64) *Config

FloodTimeout fluently sets flood timeout for the current config context, this is how many seconds of penalty must accumulate before flood protection is triggered, and also how long after flood protection activation it will continue to flood protect for.

func (*Config) GetContext

func (c *Config) GetContext() *Server

GetContext retrieves the current configuration context, if no context has been set, returns the global setting object.

func (*Config) GetFilename

func (c *Config) GetFilename() (filename string)

GetFilename returns fileName of the configuration, or the default.

func (*Config) GetServer

func (c *Config) GetServer(name string) *Server

GetServer retrieves the server by name if it exists, nil if not.

func (*Config) GetStoreFile

func (c *Config) GetStoreFile() (storefile string)

GetStoreFile gets the global storefile or defaultStoreFile.

func (*Config) GlobalContext

func (c *Config) GlobalContext() *Config

GlobalContext clears the configs server context

func (*Config) Host

func (c *Config) Host(host string) *Config

Host fluently sets the host for the current config context

func (*Config) IsValid

func (c *Config) IsValid() bool

IsValid checks to see if the configuration is valid. If errors are found in the config the Config.Errors property is filled with the validation errors. These can be used to display to the user. See DisplayErrors for a display helper.

func (*Config) KeepAlive

func (c *Config) KeepAlive(floodstep float64) *Config

KeepAlive fluently sets keep alive timeout for the current config context, this is how many seconds to wait on an idle connection before sending a ping to see if the server is dead.

func (*Config) Nick

func (c *Config) Nick(nick string) *Config

Nick fluently sets the nick for the current config context

func (*Config) NoReconnect

func (c *Config) NoReconnect(noreconnect bool) *Config

NoReconnect fluently sets reconnection for the current config context

func (*Config) NoState

func (c *Config) NoState(nostate bool) *Config

NoState fluently sets reconnection for the current config context, this turns off the irc state database (data package).

func (*Config) NoStore

func (c *Config) NoStore(nostore bool) *Config

NoStore fluently sets reconnection for the current config context, this turns off the irc store database (data package).

func (*Config) NoVerifyCert

func (c *Config) NoVerifyCert(noverifycert bool) *Config

NoVerifyCert fluently sets the noverifyCert for the current config context

func (*Config) Port

func (c *Config) Port(port uint16) *Config

Port fluently sets the port for the current config context

func (*Config) Prefix

func (c *Config) Prefix(prefix string) *Config

Prefix fluently sets the prefix for the current config context

func (*Config) Realname

func (c *Config) Realname(realname string) *Config

Realname fluently sets the realname for the current config context

func (*Config) ReconnectTimeout

func (c *Config) ReconnectTimeout(seconds uint) *Config

ReconnectTimeout fluently sets the port for the current config context

func (*Config) RemoveServer

func (c *Config) RemoveServer(name string) (deleted bool)

RemoveServer removes a server by name. Note that this does not work on host if a name has been set on the server.

func (*Config) Server

func (c *Config) Server(name string) *Config

Server fluently creates a server object and sets the context on the Config to the current instance. This automatically sets the Host() parameter to the same thing. If you have multiple servers connecting to the same host, you will have to use this to name the server, and Host() to set the host.

func (*Config) ServerContext

func (c *Config) ServerContext(name string) *Config

ServerContext the configs server context, adds an error if the if server key is not found.

func (*Config) Ssl

func (c *Config) Ssl(ssl bool) *Config

Ssl fluently sets the ssl for the current config context

func (*Config) SslCert

func (c *Config) SslCert(cert string) *Config

SslCert sets a filename that will be read in (pem format) to verify the server's certificate.

func (*Config) StoreFile

func (c *Config) StoreFile(storefile string) *Config

StoreFile fluently sets the storefile for the global context.

func (*Config) Userhost

func (c *Config) Userhost(userhost string) *Config

Userhost fluently sets the userhost for the current config context

func (*Config) Username

func (c *Config) Username(username string) *Config

Username fluently sets the username for the current config context

type Server

type Server struct {

	// Name of this connection
	Name string

	// Irc Server connection info
	Host string
	Port uint16

	// Ssl configuration
	Ssl          string
	SslCert      string
	NoVerifyCert string

	// State tracking
	NoState string
	NoStore string

	// Flood Protection
	FloodLenPenalty string
	FloodTimeout    string
	FloodStep       string

	// Keep alive
	KeepAlive string

	// Auto reconnection
	NoReconnect      string
	ReconnectTimeout string

	// Irc User data
	Nick     string
	Altnick  string
	Username string
	Userhost string
	Realname string

	// Dispatching options
	Prefix   string
	Channels []string
	// contains filtered or unexported fields
}

Server states the all the details necessary to connect to an irc server Although all of these are exported so they can be deserialized into a yaml file, they are not for direct reading and the helper methods should ALWAYS be used to preserve correct global-value resolution.

func (*Server) GetAltnick

func (s *Server) GetAltnick() (altnick string)

GetAltnick gets Altnick of the server, or the global altnick, or empty string.

func (*Server) GetChannels

func (s *Server) GetChannels() (channels []string)

GetChannels gets Channels of the server, or the global channels, or nil slice of string (check the length!).

func (*Server) GetFloodLenPenalty

func (s *Server) GetFloodLenPenalty() (floodLenPenalty uint)

GetFloodLenPenalty gets FloodLenPenalty of the server, or the global floodLenPenalty, or defaultFloodLenPenalty

func (*Server) GetFloodStep

func (s *Server) GetFloodStep() (floodStep float64)

GetFloodStep gets FloodStep of the server, or the global floodStep, or defaultFloodStep

func (*Server) GetFloodTimeout

func (s *Server) GetFloodTimeout() (floodTimeout float64)

GetFloodTimeout gets FloodTimeout of the server, or the global floodTimeout, or defaultFloodTimeout

func (*Server) GetHost

func (s *Server) GetHost() string

GetHost gets s.host

func (*Server) GetKeepAlive

func (s *Server) GetKeepAlive() (keepAlive float64)

GetKeepAlive gets KeepAlive of the server, or the global keepAlive, or defaultKeepAlive.

func (*Server) GetName

func (s *Server) GetName() string

GetName gets s.name

func (*Server) GetNick

func (s *Server) GetNick() (nick string)

GetNick gets Nick of the server, or the global nick, or empty string.

func (*Server) GetNoReconnect

func (s *Server) GetNoReconnect() (noReconnect bool)

GetNoReconnect gets NoReconnect of the server, or the global noReconnect, or false

func (*Server) GetNoState

func (s *Server) GetNoState() (nostate bool)

GetNoState gets NoState of the server, or the global nostate, or false

func (*Server) GetNoStore

func (s *Server) GetNoStore() (nostore bool)

GetNoStore gets NoStore of the server, or the global nostore, or false

func (*Server) GetNoVerifyCert

func (s *Server) GetNoVerifyCert() (noverifyCert bool)

GetNoVerifyCert gets NoVerifyCert of the server, or the global verifyCert, or false

func (*Server) GetPort

func (s *Server) GetPort() (port uint16)

GetPort returns gets Port of the server, or the global port, or ircDefaultPort

func (*Server) GetPrefix

func (s *Server) GetPrefix() (prefix rune)

GetPrefix gets Prefix of the server, or the global prefix, or defaultPrefix.

func (*Server) GetRealname

func (s *Server) GetRealname() (realname string)

GetRealname gets Realname of the server, or the global realname, or empty string.

func (*Server) GetReconnectTimeout

func (s *Server) GetReconnectTimeout() (reconnTimeout uint)

GetReconnectTimeout gets ReconnectTimeout of the server, or the global reconnectTimeout, or defaultReconnectTimeout

func (*Server) GetSsl

func (s *Server) GetSsl() (ssl bool)

GetSsl returns Ssl of the server, or the global ssl, or false

func (*Server) GetSslCert

func (s *Server) GetSslCert() (cert string)

GetSslCert returns the path to the certificate used when connecting.

func (*Server) GetUserhost

func (s *Server) GetUserhost() (userhost string)

GetUserhost gets Userhost of the server, or the global userhost, or empty string.

func (*Server) GetUsername

func (s *Server) GetUsername() (username string)

GetUsername gets Username of the server, or the global username, or empty string.

Jump to

Keyboard shortcuts

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