env

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 4 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. webtyp/fmt is the only dep, os never leaks into wasm.

import "webtyp.com/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 "".

A value of exactly keyring:// (webtyp.com/keyring's Scheme) is a marker, not a literal: !wasm Lookup/LookupAt resolve it through keyring/auto.OpenForModule(".") — the current module's own go.mod path is the keyring namespace, so two projects never collide on the same key name. Nothing to store it yet → ok=false, same as the key being absent from .env altogether. wasm never resolves it (there is no OS keyring in a Worker) — a Worker secret whose value literally is "keyring://" is treated as not found rather than served as-is. Filling in a missing one is webtyp/app's job (webtyp -tui's SECRETS section), not this package's.

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

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

func Get(key string) string

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

func GetOr

func GetOr(key, fallback string) string

GetOr returns the value of key or fallback if unset.

func Lookup

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

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

func Require(key string) (string, error)

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

func Set

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