Documentation ¶
Overview ¶
Copy from https://github.com/caarlos0/env
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotAStructPtr is returned if you pass something that is not a pointer to a // Struct to Parse ErrNotAStructPtr = errors.New("Expected a pointer to a Struct") // ErrUnsupportedType if the struct field type is not supported by env ErrUnsupportedType = errors.New("Type is not supported") // ErrUnsupportedSliceType if the slice element type is not supported by env ErrUnsupportedSliceType = errors.New("Unsupported slice type") )
Functions ¶
func Parse ¶ added in v1.0.6
func Parse(v interface{}) error
Parse parses a struct containing `env` tags and loads its values from environment variables.
Example ¶
type config struct { Home string `env:"HOME"` Port int `env:"PORT" envDefault:"3000"` IsProduction bool `env:"PRODUCTION"` } os.Setenv("HOME", "/tmp/fakehome") cfg := config{} Parse(&cfg) fmt.Println(cfg)
Output: {/tmp/fakehome 3000 false}
Types ¶
type Config ¶
type Config struct { CraneAddr string `env:"CRANE_ADDR,required"` SwarmManagerIP string `env:"CRANE_SWARM_MANAGER_IP,required"` DockerEntryScheme string `env:"CRANE_DOCKER_ENTRY_SCHEME" envDefault:"http"` DockerEntryPort string `env:"CRANE_DOCKER_ENTRY_PORT" envDefault:"2375"` DockerCertPath string `env:"CRANE_DOCKER_CERT_PATH,required"` DockerApiVersion string `env:"CRANE_DOCKER_API_VERSION"` DbDriver string `env:"CRANE_DB_DRIVER,required"` DbDSN string `env:"CRANE_DB_DSN,required"` FeatureFlags []string `env:"CRANE_FEATURE_FLAGS,required"` DockerTlsVerify bool `env:"CRANE_DOCKER_TLS_VERIFY envDefault:"false"` // registry RegistryPrivateKeyPath string `env:"CRANE_REGISTRY_PRIVATE_KEY_PATH,required"` RegistryAddr string `env:"CRANE_REGISTRY_ADDR,required"` // account AccountAuthenticator string `env:"CRANE_ACCOUNT_AUTHENTICATOR,required"` AccountTokenStore string `env:"CRANE_ACCOUNT_TOKEN_STORE"` AccountEmailDefault string `env:"CRANE_ACCOUNT_EMAIL_DEFAULT"` AccountPasswordDefault string `env:"CRANE_ACCOUNT_PASSWORD_DEFAULT"` CatalogPath string `env:"CRANE_CATALOG_PATH"` SearchLoadDataInterval int `env:"CRANE_SEARCH_LOAD_DATA_INTERVAL"` }
func InitConfig ¶ added in v1.0.6
func InitConfig() *Config
func (*Config) FeatureEnabled ¶
Click to show internal directories.
Click to hide internal directories.