Files
fn_registry/functions/infra/env_require_all.go
T
egutierrez ebf246beb0 feat(infra): funciones impuras Go para carga de env/config (dotenv, env_require, config_from_env, config_from_file)
- dotenv_load: parser .env con no-sobreescritura y soporte de comillas
- env_require: os.Getenv con error descriptivo fail-fast
- env_require_all: verifica multiples vars y lista todas las faltantes
- config_from_env: reflection sobre struct tags env/default/required/secret, 5 tipos soportados
- config_from_file: JSON via stdlib, YAML stub con not-implemented
- 25 tests unitarios, todos PASS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 02:01:50 +02:00

32 lines
775 B
Go

package infra
import (
"fmt"
"os"
"strings"
)
// EnvRequireAll returns a map of all requested environment variables.
// All keys are checked even if some are missing. If any variable is unset or
// empty, a single error listing all missing variables is returned.
// On success, the returned map contains every key with its current value.
func EnvRequireAll(keys []string) (map[string]string, error) {
result := make(map[string]string, len(keys))
var missing []string
for _, key := range keys {
val := os.Getenv(key)
if val == "" {
missing = append(missing, key)
} else {
result[key] = val
}
}
if len(missing) > 0 {
return nil, fmt.Errorf("env_require_all: missing environment variables: %s", strings.Join(missing, ", "))
}
return result, nil
}