env

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 1 Imported by: 0

README

env

Agnostic config reads/writes: Get/GetRequired take an injected Reader, so this package never imports os and stays wasm-safe. A server binary injects osenv.Reader() (process env vars, falling back to a .env file); an edge binary injects a Reader over its own platform binding — the same call works against either.

import (
    "github.com/tinywasm/env"
    "github.com/tinywasm/env/osenv"
)

dsn, err := env.GetRequired(osenv.Reader(), "DATABASE_URL")

osenv also carries Arg(key) (CLI flag lookup via os.Args) and Writer() (sets a value in the current process's own environment) — both process-only, with no edge equivalent.

Documentation

Overview

Package env reads and writes configuration through an injected source, agnostic of where that source lives. This keeps the package wasm-safe (no "os" import): a server binary injects a Reader/Writer backed by the process environment (see the osenv subpackage), while an edge binary injects one backed by its own platform binding (e.g. Cloudflare env vars) — the same Get/GetRequired call works against either.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get added in v0.0.2

func Get(read Reader, key string) string

Get returns the value of key from read, or "" if unset there.

func GetRequired added in v0.0.2

func GetRequired(read Reader, key string, fallbacks ...Reader) (string, error)

GetRequired tries read first, then each fallback Reader in order. Returns an error if key is not found anywhere.

Types

type Reader added in v0.0.7

type Reader func(key string) string

Reader returns the value of key from whatever source it wraps, or "" if key is unset there. "" always means "not found" — no separate ok bool, matching the rest of the ecosystem's convention.

type Writer added in v0.0.7

type Writer func(key, value string) error

Writer sets key to value in whatever source it wraps. Not every source can persist a write (e.g. platform env vars configured outside the running process); such a Writer returns a descriptive error rather than silently discarding the value.

Directories

Path Synopsis
Package osenv provides the process-backed env.Reader/env.Writer: real environment variables, falling back to a .env file, plus CLI argument lookup.
Package osenv provides the process-backed env.Reader/env.Writer: real environment variables, falling back to a .env file, plus CLI argument lookup.

Jump to

Keyboard shortcuts

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