config

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 16 Imported by: 0

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

View Source
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"
)
View Source
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

View Source
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

View Source
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

View Source
const (
	LogOutputStdout string = "stdout"
	LogOutputStderr string = "stderr"
)

Log output targets. The chosen output target is user-configurable.

View Source
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

View Source
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

func Branding

func Branding() string

Branding provides application name, version and origin

func MyBinaryName

func MyBinaryName() string

MyBinaryName returns the name of this binary

func Version

func Version() string

Version emits application version string.

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

func NewConfig() (*Config, error)

NewConfig is a factory function that produces a new Config object based on user provided flag and config file values.

func (Config) ConfigFile

func (c Config) ConfigFile() string

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

func (c Config) ConfigFileUsed() string

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

func (c Config) ConnectionRetries() int

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

func (c Config) ConnectionRetryDelay() time.Duration

ConnectionRetryDelay returns the user-provided number of seconds between retry connection attempts or the default value if not provided.

func (Config) ConnectionTimeout

func (c Config) ConnectionTimeout() time.Duration

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

func (c *Config) ImportConfigFile(fh io.Reader) (bool, error)

ImportConfigFile reads from an io.Reader and unmarshals a configuration file in YAML format into the associated Config struct.

func (*Config) Load

func (c *Config) Load() error

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

func (c Config) LogDBStats() bool

LogDBStats returns the user-provided choice of whether database connection stats are logged periodically or the default value if not provided.

func (Config) LogFormat

func (c Config) LogFormat() string

LogFormat returns the user-provided logging format or the default value if not provided. CLI flag values take precedence if provided.

func (Config) LogLevel

func (c Config) LogLevel() string

LogLevel returns the user-provided logging level or the default value if not provided. CLI flag values take precedence if provided.

func (Config) LogOutput

func (c Config) LogOutput() string

LogOutput returns the user-provided logging output or the default value if not provided. CLI flag values take precedence if provided.

func (Config) MySQLConnMaxIdleTime

func (c Config) MySQLConnMaxIdleTime() time.Duration

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

func (c Config) MySQLConnMaxLifetime() time.Duration

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

func (c Config) MySQLDatabase() string

MySQLDatabase returns the user-provided MySQL database used by this application or the default value if not provided.

func (Config) MySQLEncryption

func (c Config) MySQLEncryption() string

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

func (c Config) MySQLHost() string

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

func (c Config) MySQLMaxIdleConns() int

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

func (c Config) MySQLMaxOpenConns() int

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

func (c Config) MySQLPassword() string

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

func (c Config) MySQLPort() int

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

func (c Config) MySQLUsername() string

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

func (c Config) SQLiteBusyTimeout() int

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

func (c Config) SQLiteCreateIndexes() bool

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

func (c Config) SQLiteDBFile() string

SQLiteDBFile returns the user-provided SQLite database file created/managed by this application or the default value if not provided.

func (Config) SQLiteDBPath

func (c Config) SQLiteDBPath() string

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

func (c Config) SQLiteJournalMode() string

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) String

func (c Config) String() string

func (Config) TrimWhitespace

func (c Config) TrimWhitespace() bool

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.

func (Config) Validate

func (c Config) Validate() error

Validate verifies all struct fields have been provided acceptable values

Jump to

Keyboard shortcuts

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