Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/orsinium-labs/configenv"
)
type Config struct {
Debug bool
Env string
}
func main() {
env := []string{
"BE_DEBUG=true",
"BE_ENV=prod",
"ENV=fake",
}
config := Config{}
vars := configenv.Vars{
"DEBUG": configenv.Required(configenv.Bool(&config.Debug)),
"ENV": configenv.String(&config.Env),
}
err := vars.Parse(configenv.Config{
Environ: env,
Prefix: "BE_",
})
if err != nil {
panic(err)
}
fmt.Println(config.Env)
}
Output: prod
Index ¶
- Variables
- func Bool[T ~bool](target *T) parser
- func Float32[T ~float32](target *T) parser
- func Float64[T ~float64](target *T) parser
- func Int[T ~int](target *T) parser
- func Int8[T ~int8](target *T) parser
- func Int16[T ~int16](target *T) parser
- func Int32[T ~int32](target *T) parser
- func Int64[T ~int64](target *T) parser
- func JSON[T any](target *T) parser
- func Map(p parser, f func(string) string) parser
- func PrefixMap[M ~map[K]V, K ~string, V any](target *M, p Parser[V]) parser
- func PrefixSlice[A ~[]V, V any](target *A, p Parser[V]) parser
- func Required(p parser) parser
- func Slice[A ~[]V, V any](target *A, sep string, p Parser[V]) parser
- func String[T ~string](target *T) parser
- func Strings[A ~[]V, V ~string](target *A, sep string) parser
- func Uint[T ~uint](target *T) parser
- func Uint8[T ~uint8](target *T) parser
- func Uint16[T ~uint16](target *T) parser
- func Uint32[T ~uint32](target *T) parser
- func Uint64[T ~uint64](target *T) parser
- type C
- type Config
- type Parser
- type V
- type Vars
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( R = Required S = String[string] I = Int[int] U = Uint[uint] B = Bool[bool] F = Float64[float64] )
One-letter aliases for people living on the edge.
Functions ¶
func PrefixSlice ¶ added in v1.1.0
Types ¶
type Config ¶
type Config struct {
// Pairs of name=value env vars. If not provided, [os.Environ] will be used.
Environ []string
// The prefix to add to all env var names.
//
// The prefix ensures that env vars between services don't conflict
Prefix string
// If true, will not return an error for unknown env vars with the given prefix.
//
// By default, extra env vars are forbidden which prevents typos in env var names.
// For example, if you write `BE_DEUG=false` instead of `BE_DEBUG=false`.
AllowExtra bool
// Require all env vars to be present and non-empty, even if not wrapped in [Required].
//
// It's a good idea to set it on the production to ensure no env var is forgotten.
RequireAll bool
}
Click to show internal directories.
Click to hide internal directories.