Documentation
¶
Overview ¶
Package env names the runtime environment a hex application is running in and provides detection helpers.
hex ships three canonical environments:
Development running the app locally while working on it (go run .)
Test go test ..., CI/CD
Production released binaries in staging, production, anywhere
the app is deployed for real work
The set is deliberately small. If you need to distinguish staging from production, that is a deployment concern — read a separate config key like `deploy.tier` instead of adding an environment.
Detection order (see Detect):
- HEX_ENV / APP_ENV environment variables
- testing.Testing() — Test when running under `go test`
- Development as the default
Explicit overrides via hex.WithEnvironment take precedence over all of the above.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Environment ¶
type Environment string
Environment is a strict enum: only Development, Test, and Production are valid values. Parse accepts a small set of aliases; otherwise it returns an error so misspelled overrides fail loudly.
const ( // Development is the local-development environment. Development Environment = "development" // Test is the test / CI environment. Test Environment = "test" // Production is the deployed / released environment. Production Environment = "production" )
func All ¶
func All() []Environment
All returns every recognised environment in a stable order. Useful for CLI help text and validation.
func Detect ¶
func Detect() Environment
Detect returns the environment inferred from the process, using the order documented on the package.
func Parse ¶
func Parse(s string) (Environment, error)
Parse accepts case-insensitive names and common aliases. Returns an error for unknown strings so config validation catches typos rather than silently defaulting.
func (Environment) IsProduction ¶
func (e Environment) IsProduction() bool
IsProduction reports Production.
func (Environment) String ¶
func (e Environment) String() string
String returns the environment's canonical name.
type UnknownError ¶
type UnknownError struct {
Value string
}
UnknownError is returned by Parse when the input does not name a recognised environment.
func (*UnknownError) Error ¶
func (e *UnknownError) Error() string