Go

Load encrypted .env files in Go.

Package

dotenvx-go

Install

Use Go 1.22 or later and a C compiler with cgo enabled. The package includes native builds for macOS and glibc Linux on amd64 and arm64.

go get github.com/dotenvx/dotenvx-go

Usage

With HELLO=World in .env, call dotenvx.Load() before reading your environment variables.

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/dotenvx/dotenvx-go"
)

func main() {
	if err := dotenvx.Load(); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Hello", os.Getenv("HELLO"))
}

See the Go quickstart for the full encryption workflow.

Open page ↗

Side path