molecule-core/workspace-server/internal/envx/envx.go
Hongming Wang 479a027e4b chore: open-source restructure — rename dirs, remove internal files, scrub secrets
Renames:
- platform/ → workspace-server/ (Go module path stays as "platform" for
  external dep compat — will update after plugin module republish)
- workspace-template/ → workspace/

Removed (moved to separate repos or deleted):
- PLAN.md — internal roadmap (move to private project board)
- HANDOFF.md, AGENTS.md — one-time internal session docs
- .claude/ — gitignored entirely (local agent config)
- infra/cloudflare-worker/ → Molecule-AI/molecule-tenant-proxy
- org-templates/molecule-dev/ → standalone template repo
- .mcp-eval/ → molecule-mcp-server repo
- test-results/ — ephemeral, gitignored

Security scrubbing:
- Cloudflare account/zone/KV IDs → placeholders
- Real EC2 IPs → <EC2_IP> in all docs
- CF token prefix, Neon project ID, Fly app names → redacted
- Langfuse dev credentials → parameterized
- Personal runner username/machine name → generic

Community files:
- CONTRIBUTING.md — build, test, branch conventions
- CODE_OF_CONDUCT.md — Contributor Covenant 2.1

All Dockerfiles, CI workflows, docker-compose, railway.toml, render.yaml,
README, CLAUDE.md updated for new directory names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 00:24:44 -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
}