Documentation ¶
Index ¶
Constants ¶
View Source
const ( ContextKeyEnvironment ContextKey = "srvc:environment" EnvProduction string = "production" EnvDevelopment string = "development" EnvTest string = "test" DefaultConfigAddress string = ":8000" DefaultConfigPIDFile string = "tmp/server.pid" DefaultConfigReadTimeout string = "30s" DefaultConfigWriteTimeout string = "30s" ConfigValueExternalPrefix string = "ext:" )
Variables ¶
View Source
var (
ErrNotInitialized = errors.New(
"it seems like you haven't initialized your service. Please use " +
"`srvc init` before running this command",
)
)
Functions ¶
func DefaultRunner ¶
DefaultRunner prints out a message prompting how to get started with srvc.
Types ¶
type App ¶
type App struct { // Runner is your application code. You are provided the context as well as // the configuration for the application. // // `srvc` handles loading your configuration when the app is run for you. // You can specify how to load configuration values you can't hardcode in // your configuration files. // // By default, it will use app.DefaultRunner() as the application runner. Runner func(Context, *Config) error // LoadVariable allows the application to load a variable via a user-defined // function. // // By default, it will use app.LoadVariableFromEnv() to load variables via // the environment. // // Config files with variable values in the "ext:XXX" format will be loaded // via this func, providing "XXX" as the string. // // If the configuration value is missing from the configuration file, then // that variable is also passed to this function. LoadVariable LoadVariableFunc }
App is the structure that lets users define their application.
Any struct values that aren't provided by the user will be defaulted.
func (*App) InitializeDefaults ¶
func (a *App) InitializeDefaults()
InitializeDefaults initializes the app for any fields that are not provided by the user.
type Config ¶
type Config struct { // Address is the address to operate a server at, in the format ":####". // Default: ":8000" Address string `yaml:"address"` // PIDFile is the file name to store the PID of the running app. // Default: "tmp/server.pid" PIDFile string `yaml:"pid_file"` // Environment is the environment the app is running in. Environment string `yaml:"env"` // ReadTimeout is the read timeout, if running a server, in time.Duration // format. // Default: "30s" ReadTimeout string `yaml:"read_timeout"` // WriteTimeout is the write timeout, if running a server, in time.Duration // format. // Default: "30s" WriteTimeout string `yaml:"write_timeout"` // X contains any additinal custom key/vals you want available in your // configuration. X map[string]string `yaml:"x"` }
Config is a struct that defines common fields used in Go applications.
type ConfigFile ¶
type ConfigFile struct { Default Config `yaml:"default"` Test Config `yaml:"test"` Development Config `yaml:"development"` Production Config `yaml:"production"` }
ConfigFile defines the file format of the config file
func LoadConfigFile ¶
func LoadConfigFile(file fs.File) (*ConfigFile, error)
LoadConfigFile loads the contents of the config file into the ConfigFile struct.
type ContextKey ¶
type ContextKey string
type DefaultContext ¶ added in v0.0.2
func (*DefaultContext) Version ¶ added in v0.0.2
func (c *DefaultContext) Version() string
type ErrVariableNotFound ¶
func (*ErrVariableNotFound) Error ¶
func (e *ErrVariableNotFound) Error() string
Click to show internal directories.
Click to hide internal directories.