env

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 3 Imported by: 0

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):

  1. HEX_ENV / APP_ENV environment variables
  2. testing.Testing() — Test when running under `go test`
  3. 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) IsDev

func (e Environment) IsDev() bool

IsDev reports Development.

func (Environment) IsProduction

func (e Environment) IsProduction() bool

IsProduction reports Production.

func (Environment) IsTest

func (e Environment) IsTest() bool

IsTest reports Test.

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

Directories

Path Synopsis
Package lua exposes hex/env to Lua scripts as the "env" module.
Package lua exposes hex/env to Lua scripts as the "env" module.

Jump to

Keyboard shortcuts

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