molecule-core/platform/internal/envx/envx.go
Hongming Wang 24fec62d7f initial commit — Molecule AI platform
Forked clean from public hackathon repo (Starfire-AgentTeam, BSL 1.1)
with full rebrand to Molecule AI under github.com/Molecule-AI/molecule-monorepo.

Brand: Starfire → Molecule AI.
Slug: starfire / agent-molecule → molecule.
Env vars: STARFIRE_* → MOLECULE_*.
Go module: github.com/agent-molecule/platform → github.com/Molecule-AI/molecule-monorepo/platform.
Python packages: starfire_plugin → molecule_plugin, starfire_agent → molecule_agent.
DB: agentmolecule → molecule.

History truncated; see public repo for prior commits and contributor
attribution. Verified green: go test -race ./... (platform), pytest
(workspace-template 1129 + sdk 132), vitest (canvas 352), build (mcp).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:55:37 -07:00

40 lines
1.1 KiB
Go

// Package envx holds tiny helpers for reading tunable values from
// environment variables with a safe default. Named `envx` rather than
// `env` to avoid collision with Go's net/http and common third-party
// packages that use `env` as a var/import name.
//
// Rules of thumb for the helpers:
// - Unset variable → default
// - Unparseable → default (never crash startup)
// - Parsed but ≤ 0 → default (a "disabled" override is almost always
// a misconfiguration; use a feature flag instead)
package envx
import (
"os"
"strconv"
"time"
)
// Duration reads `name` as a time.Duration string (e.g. "30s", "5m").
// Returns `def` when unset, unparseable, or non-positive.
func Duration(name string, def time.Duration) time.Duration {
if v := os.Getenv(name); v != "" {
if d, err := time.ParseDuration(v); err == nil && d > 0 {
return d
}
}
return def
}
// Int64 reads `name` as a base-10 int64. Returns `def` when unset,
// unparseable, or non-positive.
func Int64(name string, def int64) int64 {
if v := os.Getenv(name); v != "" {
if n, err := strconv.ParseInt(v, 10, 64); err == nil && n > 0 {
return n
}
}
return def
}