Home

Awesome

<p align="center"> <img alt="GoReleaser Logo" src="https://becker.software/env.png" height="140" /> <p align="center">A simple, zero-dependencies library to parse environment variables into structs.</p> </p>
Installation
go get github.com/caarlos0/env/v11
Getting started
type config struct {
  Home string `env:"HOME"`
}

// parse
var cfg config
err := env.Parse(&cfg)

// parse with generics
cfg, err := env.ParseAs[config]()

You can see the full documentation and list of examples at pkg.go.dev.


Used and supported by

<p> <a href="https://encore.dev"> <img src="https://user-images.githubusercontent.com/78424526/214602214-52e0483a-b5fc-4d4c-b03e-0b7b23e012df.svg" width="120px" alt="encore icon" /> </a> <br/> <br/> <b>Encore – the platform for building Go-based cloud backends.</b> <br/> </p>

Usage

Caveats

[!CAUTION]

Unexported fields will be ignored by env. This is by design and will not change.

Functions

Supported types

Out of the box all built-in types are supported, plus a few others that are commonly used.

Complete list:

Pointers, slices and slices of pointers, and maps of those types are also supported.

You may also add custom parsers for your types.

Tags

The following tags are provided:

env tag options

Here are all the options available for the env tag:

Parse Options

There are a few options available in the functions that end with WithOptions:

Documentation and examples

Examples are live in pkg.go.dev, and also in the example test file.

Current state

env is considered feature-complete.

I do not intent to add any new features unless they really make sense, and are requested by many people.

Eventual bug fixes will keep being merged.

Badges

Release Software License Build status Codecov branch Go docs Powered By: GoReleaser Conventional Commits

Related projects

Stargazers over time

Stargazers over time