config

package
v0.0.0-...-4aab756 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Any configuration of taskninja belongs here

Index

Constants

View Source
const DefaultLogPath = "/tmp/taskninja.log"

Variables

This section is empty.

Functions

func GetConfig

func GetConfig() (*Config, *ConfigError)

Used to load the configuration from the config file

Types

type Config

type Config struct {
	Connection SqlConnectionConfig `yaml:"connection"` // How to connect to the sqlite database
	Log        Log                 `yaml:"log"`        // How to log
}

Contains the user configuration

func Bootstrap

func Bootstrap() *Config

Bootstrap creates the initial configuration file if it does not exist

func (*Config) InitLogger

func (c *Config) InitLogger()

InitLogger initializes the logger, sets up the handlers, levels, etc.

type ConfigError

type ConfigError struct {
	Variant ConfigErrorVariant // The type of error
	Err     error              // The error that occurred
}

ConfigError is an error that occurs when loading the configuration

func (ConfigError) CanBootstrap

func (e ConfigError) CanBootstrap() bool

CanBootstrap returns true if the error can be resolved by bootstrapping the configuration

func (ConfigError) Error

func (e ConfigError) Error() string

Error returns the error message

type ConfigErrorVariant

type ConfigErrorVariant string
const (
	ConfigErrorNoHomeDir             ConfigErrorVariant = "no-home-dir"               // User home directory not found
	ConfigErrorFileNotFound          ConfigErrorVariant = "file-not-found"            // Config file not found
	ConfigErrorConfigDirDoesNotExist ConfigErrorVariant = "config-dir-does-not-exist" // Config directory does not exist
	ConfigErrorReadFile              ConfigErrorVariant = "read-file"                 // Failed to read config file
	ConfigErrorUnmarshal             ConfigErrorVariant = "unmarshal"                 // Failed to unmarshal config
)

type ConnectionMode

type ConnectionMode string

ConnectionMode is the type of connection to the sqlite database

const (
	ConnectionModeInMemory ConnectionMode = "in-memory" // SQLITE in-memory database
	ConnectionModeFile     ConnectionMode = "file"      // SQLITE file database
)

type Log

type Log struct {
	Level string `yaml:"level"` // log level
	Mode  string `yaml:"mode"`  // log mode
	Path  string `yaml:"path"`  // log path
}

type LogLevel

type LogLevel string // log level
const (
	LogLevelTrace LogLevel = "trace"
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
)

type LogMode

type LogMode string // e.g JSON
const (
	LogModePretty LogMode = "pretty" // pretty print with colours to term
	LogModeJson   LogMode = "json"   // json output
)

type SqlConnectionConfig

type SqlConnectionConfig struct {
	Mode       ConnectionMode `yaml:"mode"`       // in-memory, file, http
	Path       string         `yaml:"connection"` // connection string
	BackupPath string         `yaml:"backupPath"` // Location to backup the database (sqlite disk only)
}

Contains the SQL connection configuration

func (*SqlConnectionConfig) DSN

func (c *SqlConnectionConfig) DSN() string

DSN returns the data source name for the connection e.g "sqlite://:memory:", or "sqlite:///path/to/file.db", Defaults to in-memory if not set

Jump to

Keyboard shortcuts

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