Documentation
¶
Overview ¶
Package config provides the configuration for the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Version string Commit string BuildTime = time.Now().Format("2006-01-02T15:04:05.000") BuiltBy = "local" BuiltWith = runtime.Version() )
These variables are set at build time and describe the version and build of the application
var ( // ErrFieldNotFound is returned when a field is not found. ErrFieldNotFound = errors.New("field not found") // ErrMsgTypeMismatch is returned when the type of the default value, example value, or flag type does not match. ErrMsgTypeMismatch = "type mismatch for config field %s, flag type is '%s', default value type is '%s', example value type is '%s'" // ErrMsgUnsupportedType is returned when a type is not supported. ErrMsgUnsupportedType = "unsupported type %s for config flag %s, need to add support for this type in bindFlag" // ErrMsgDefaultNil is returned when a required field has no default value. ErrMsgDefaultNil = "default value is nil for required config field %s, need to set a default value" // ErrMsgFlagEmpty is returned when a field has no flag. ErrMsgFlagEmpty = "flag is empty for config field %s, need to set a flag" // ErrMsgEnvVarEmpty is returned when a field has no env var. ErrMsgEnvVarEmpty = "env var is empty for config field %s, need to set an env var" // ErrMsgTypeEmpty is returned when a field has no type. ErrMsgTypeEmpty = "type is empty for config field %s, need to set a type" )
var ( // Fields is a list of all configuration fields. Fields = append(coreFields, append(githubFields, append(trunkFields, jiraFields...)...)...) )
Functions ¶
func BindConfig ¶
BindConfig binds the configuration to command flags and viper env vars.
func GetDefault ¶
GetDefault returns the default value for a configuration field by name.
func MustBindConfig ¶
MustBindConfig is BindConfig but panics if there is an error.
func VersionString ¶
func VersionString() string
VersionString gives a full string of the version of the application.
Types ¶
type Config ¶
type Config struct {
LogLevel string `mapstructure:"LOG_LEVEL"`
LogPath string `mapstructure:"LOG_PATH"`
Port int `mapstructure:"PORT"`
// Secrets
GitHub GitHub `mapstructure:",squash"`
Trunk Trunk `mapstructure:",squash"`
Jira Jira `mapstructure:",squash"`
}
Config is the application configuration, set by flags, then by environment variables.
type Field ¶
type Field struct {
// EnvVar is the environment variable name. It is also the key in viper.
EnvVar string
Description string
Flag string
ShortFlag string
Type reflect.Type
Default any
Example any
Persistent bool
Required bool
}
Field represents a configuration field.
type GitHub ¶
type GitHub struct {
Token string `mapstructure:"GITHUB_TOKEN"`
BaseURL string `mapstructure:"GITHUB_BASE_URL"`
// GitHub App configuration
AppID string `mapstructure:"GITHUB_APP_ID"`
PrivateKey string `mapstructure:"GITHUB_PRIVATE_KEY"`
PrivateKeyFile string `mapstructure:"GITHUB_PRIVATE_KEY_FILE"`
InstallationID string `mapstructure:"GITHUB_INSTALLATION_ID"`
}
GitHub configures authentication to the GitHub API.
type Jira ¶
type Jira struct {
BaseDomain string `mapstructure:"JIRA_BASE_DOMAIN"`
ProjectKey string `mapstructure:"JIRA_PROJECT_KEY"`
OAuthClientID string `mapstructure:"JIRA_OAUTH_CLIENT_ID"`
OAuthClientSecret string `mapstructure:"JIRA_OAUTH_CLIENT_SECRET"`
OAuthAccessToken string `mapstructure:"JIRA_OAUTH_ACCESS_TOKEN"`
OAuthRefreshToken string `mapstructure:"JIRA_OAUTH_REFRESH_TOKEN"`
Username string `mapstructure:"JIRA_USERNAME"`
Token string `mapstructure:"JIRA_TOKEN"`
}
Jira configures authentication to the Jira API.
type Option ¶
type Option func(*configOptions)
Option is a function that can be used to configure loading the config.
func WithCommand ¶
WithCommand sets the command to use for binding flags to config values.
func WithConfigFile ¶
WithConfigFile sets the exact config file to load.