env

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 2 Imported by: 0

README

env

Auto-tagged env access: !wasm reads os.Getenv (+ .env fallback), wasm reads Cloudflare context.env via syscall/js. No injection — the build tag selects the implementation. tinywasm/fmt is the only dep, os never leaks into wasm.

import "github.com/tinywasm/env"

port := env.Get("PORT")                 // "" if unset
dsn, err := env.Require("DATABASE_URL") // error if unset
host := env.GetOr("HOST", "localhost")
if v, ok := env.Lookup("KEY"); ok { ... }
env.Set("KEY", "value") // !wasm only
flag := env.Arg("port") // !wasm only, -port=8080 / -port 8080

Low-level .env path override: env.LookupAt("KEY", "/path/to/.env").

Wasm target is Cloudflare Workers (context.env); other wasm targets get "".

Documentation

Overview

Package env provides auto-tagged environment access: on !wasm it reads the process environment (os.Getenv + .env fallback), on wasm it reads Cloudflare's context.env via syscall/js. No injection, no Reader — the build tag selects the implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arg added in v0.0.2

func Arg(key string) string

Arg returns the value for -key=value or -key value in os.Args (skipping argv[0]). Only available on !wasm; wasm has no argv.

func Get added in v0.0.2

func Get(key string) string

Get returns the value of key or "" if unset.

func GetOr added in v0.0.8

func GetOr(key, fallback string) string

GetOr returns the value of key or fallback if unset.

func Lookup added in v0.0.8

func Lookup(key string) (string, bool)

Lookup returns the value of key from the process environment, falling back to a .env file in the working directory. The bool indicates if the key was found.

func LookupAt added in v0.0.8

func LookupAt(key, path string) (string, bool)

LookupAt is Lookup with an explicit .env path, for callers not running from the project root.

func Require added in v0.0.8

func Require(key string) (string, error)

Require returns the value of key or an error if unset.

func Set added in v0.0.8

func Set(key, value string) error

Set sets key to value in the process environment. Only available on !wasm.

Types

This section is empty.

Jump to

Keyboard shortcuts

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