Documentation
¶
Overview ¶
Package config provides types and functions to collect, validate and apply user-provided settings.
Package config provides types and functions to collect, validate and apply user-provided settings.
Index ¶
- Constants
- Variables
- func Branding() string
- func MyBinaryName() string
- func Version() string
- type Config
- func (c Config) ConfigFile() string
- func (c Config) ConfigFileUsed() string
- func (c Config) ConnectionRetries() int
- func (c Config) ConnectionRetryDelay() time.Duration
- func (c Config) ConnectionTimeout() time.Duration
- func (c Config) DBQueries() dbqs.SQLQueries
- func (c *Config) ImportConfigFile(fh io.Reader) (bool, error)
- func (c *Config) Load() error
- func (c Config) LogDBStats() bool
- func (c Config) LogFormat() string
- func (c Config) LogLevel() string
- func (c Config) LogOutput() string
- func (c Config) MySQLConnMaxIdleTime() time.Duration
- func (c Config) MySQLConnMaxLifetime() time.Duration
- func (c Config) MySQLDatabase() string
- func (c Config) MySQLEncryption() string
- func (c Config) MySQLHost() string
- func (c Config) MySQLMaxIdleConns() int
- func (c Config) MySQLMaxOpenConns() int
- func (c Config) MySQLPassword() string
- func (c Config) MySQLPort() int
- func (c Config) MySQLUsername() string
- func (c Config) SQLiteBusyTimeout() int
- func (c Config) SQLiteCreateIndexes() bool
- func (c Config) SQLiteDBFile() string
- func (c Config) SQLiteDBPath() string
- func (c Config) SQLiteJournalMode() string
- func (c Config) String() string
- func (c Config) TrimWhitespace() bool
- func (c Config) Validate() error
Constants ¶
const ( // MyAppName is the branded name of this application/project. This value will // be used in user-facing output. MyAppName string = "mysql2sqlite" // MyAppURL is the branded homepage or project repo location. This value will // be used in user-facing output. MyAppURL string = "https://github.com/atc0005/" + MyAppName // MyAppDescription is used when displaying help text. MyAppDescription string = "Generate SQLite database from specified MySQL database tables" )
const ( MySQLEncryptionRequired string = "true" MySQLEncryptionPreferred string = "preferred" MySQLEncryptionSkipVerify string = "skip-verify" MySQLEncryptionDisabled string = "false" )
MySQL connection encryption settings https://github.com/go-sql-driver/mysql#tls
const ( // LogLevelFatal is used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. LogLevelFatal string = "fatal" // LogLevelError is for errors that should definitely be noted. LogLevelError string = "error" // LogLevelWarn is for non-critical entries that deserve eyes. LogLevelWarn string = "warn" // LogLevelInfo is for general application operational entries. LogLevelInfo string = "info" // LogLevelDebug is for debug-level messages and is usually enabled // when debugging. Very verbose logging. LogLevelDebug string = "debug" )
Log levels
const ( // LogFormatCLI provides human-friendly CLI output LogFormatCLI string = "cli" // LogFormatJSON provides JSON output LogFormatJSON string = "json" // LogFormatLogFmt provides logfmt plain-text output LogFormatLogFmt string = "logfmt" // LogFormatText provides human-friendly colored output LogFormatText string = "text" // LogFormatDiscard discards all logs LogFormatDiscard string = "discard" )
apex/log Handlers
--------------------------------------------------------- cli - human-friendly CLI output discard - discards all logs es - Elasticsearch handler graylog - Graylog handler json - JSON output handler kinesis - AWS Kinesis handler level - level filter handler logfmt - logfmt plain-text formatter memory - in-memory handler for tests multi - fan-out to multiple handlers papertrail - Papertrail handler text - human-friendly colored output delta - outputs the delta between log calls and spinner
const ( LogOutputStdout string = "stdout" LogOutputStderr string = "stderr" )
Log output targets. The chosen output target is user-configurable.
const ( TCPReservedPort int = 0 TCPSystemPortStart int = 1 TCPSystemPortEnd int = 1023 TCPUserPortStart int = 1024 TCPUserPortEnd int = 49151 TCPDynamicPrivatePortStart int = 49152 TCPDynamicPrivatePortEnd int = 65535 )
TCP port ranges http://www.iana.org/assignments/port-numbers Port numbers are assigned in various ways, based on three ranges: System Ports (0-1023), User Ports (1024-49151), and the Dynamic and/or Private Ports (49152-65535)
Variables ¶
var ErrCfgFileNotFound = errors.New(
"failed to load config file from known locations; " +
"see the README file for additional details",
)
ErrCfgFileNotFound is a fatal error; this error indicates that the user-specified config file could not be found, nor one of the paths automatically checked by this application.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is a unified set of configuration values for this application. The majority of values held by this object are intended to be retrieved via "Getter" methods.
func NewConfig ¶
NewConfig is a factory function that produces a new Config object based on user provided flag and config file values.
func (Config) ConfigFile ¶
ConfigFile returns the user-provided path to the config file for this application or the default value if not provided. CLI flag or environment variables are the only way to specify a value for this setting.
func (Config) ConfigFileUsed ¶
ConfigFileUsed returns the configuration file that was located and loaded for application use. This may match the user-specified file or it may instead be an alternate file automatically located if the user-specified file could not be located. This method relies upon the configuration validation checks applied at startup to ensure that a valid configuration file is returned.
func (Config) ConnectionRetries ¶
ConnectionRetries returns the user-provided number of times a connection attempt should be retried before returning an error or the default value if not provided.
func (Config) ConnectionRetryDelay ¶
ConnectionRetryDelay returns the user-provided number of seconds between retry connection attempts or the default value if not provided.
func (Config) ConnectionTimeout ¶
ConnectionTimeout returns the user-provided number of seconds before a connection attempt should be aborted or the default value if not provided.
func (Config) DBQueries ¶
func (c Config) DBQueries() dbqs.SQLQueries
DBQueries returns the user-provided collection of tables and the queries used to read from a source database and write to a SQLite database. If not provided, nil is returned in order to force validation to fail.
func (*Config) ImportConfigFile ¶
ImportConfigFile reads from an io.Reader and unmarshals a configuration file in YAML format into the associated Config struct.
func (*Config) Load ¶
Load attempts to first load the user-specified config file, then falls back to checking for a config file in the directory alongside the executable, then finally a config file from the user's configuration path. An error is returned if the configuration file cannot be loaded.
func (Config) LogDBStats ¶
LogDBStats returns the user-provided choice of whether database connection stats are logged periodically or the default value if not provided.
func (Config) LogFormat ¶
LogFormat returns the user-provided logging format or the default value if not provided. CLI flag values take precedence if provided.
func (Config) LogLevel ¶
LogLevel returns the user-provided logging level or the default value if not provided. CLI flag values take precedence if provided.
func (Config) LogOutput ¶
LogOutput returns the user-provided logging output or the default value if not provided. CLI flag values take precedence if provided.
func (Config) MySQLConnMaxIdleTime ¶
MySQLConnMaxIdleTime returns the user-provided maximum time in seconds that a database connection can remain idle or the default value if not provided. See also https://github.com/go-sql-driver/mysql#important-settings
func (Config) MySQLConnMaxLifetime ¶
MySQLConnMaxLifetime returns the user-provided maximum lifetime in minutes for database connections to the MySQL server ued by this application or the default value if not provided. See also https://github.com/go-sql-driver/mysql#important-settings
func (Config) MySQLDatabase ¶
MySQLDatabase returns the user-provided MySQL database used by this application or the default value if not provided.
func (Config) MySQLEncryption ¶
MySQLEncryption returns the user-provided choice regarding what encryption settings to use when connecting to the user-provided MySQL host used by this application or the default value if not provided.
func (Config) MySQLHost ¶
MySQLHost returns the user-provided IP Address or FQDN for the MySQL server used by this application or the default value if not provided.
func (Config) MySQLMaxIdleConns ¶
MySQLMaxIdleConns returns the user-provided maximum number of idle database connections for the MySQL server used by this application or the default value if not provided. See also https://github.com/go-sql-driver/mysql#important-settings
func (Config) MySQLMaxOpenConns ¶
MySQLMaxOpenConns returns the user-provided maximum number of database connections for the MySQL server used by this application or the default value if not provided. See also https://github.com/go-sql-driver/mysql#important-settings
func (Config) MySQLPassword ¶
MySQLPassword returns the password for the user-provided MySQL username & password pair for this application or the default value if not provided.
func (Config) MySQLPort ¶
MySQLPort returns the user-provided TCP port for the MySQL server used by this application or the default value if not provided.
func (Config) MySQLUsername ¶
MySQLUsername returns the user-provided MySQL username for this application or the default value if not provided.
func (Config) SQLiteBusyTimeout ¶ added in v0.2.0
SQLiteBusyTimeout returns the user-provided choice regarding busy timeout behavior for the connection to the SQLite database file or the default value if not provided.
func (Config) SQLiteCreateIndexes ¶
SQLiteCreateIndexes returns the user-provided choice regarding whether index creation queries will be used when generating the SQLite database file or the default value if not provided.
func (Config) SQLiteDBFile ¶
SQLiteDBFile returns the user-provided SQLite database file created/managed by this application or the default value if not provided.
func (Config) SQLiteDBPath ¶
SQLiteDBPath returns the user-provided directory where the SQLite database file created/managed by this application is stored or the default value if not provided.
func (Config) SQLiteJournalMode ¶ added in v0.2.0
SQLiteJournalMode returns the user-provided choice of journal mode for the database associated with the database connection to the SQLite database file or the default value if not provided.
func (Config) TrimWhitespace ¶
TrimWhitespace returns the user-provided choice regarding whether data retrieved from MySQL should have leading and trailing whitespace removed before inserting into the SQLite database or the default value if not provided.