ebf246beb0
- 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>
2.1 KiB
2.1 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| config_from_env | function | go | infra | 1.0.0 | impure | func ConfigFromEnv(target any) error | Puebla una struct de configuracion desde variables de entorno usando reflection y struct tags (env, default, required, secret). Soporta string, int, int64, bool, float64 y []string (comma-separated). Acumula todos los errores antes de retornar. |
|
false | error_go_core |
|
|
nil si la struct se poblo correctamente, error si falta una variable required o hay un tipo incompatible | true |
|
functions/infra/config_from_env_test.go | functions/infra/config_from_env.go |
Ejemplo
type AppConfig struct {
Host string `env:"HOST" default:"localhost"`
Port int `env:"PORT" default:"8080" required:"true"`
APIKey string `env:"API_KEY" required:"true" secret:"true"`
Tags []string `env:"TAGS" default:"prod,stable"`
Debug bool `env:"DEBUG" default:"false"`
Timeout float64 `env:"TIMEOUT" default:"30.0"`
}
var cfg AppConfig
if err := ConfigFromEnv(&cfg); err != nil {
log.Fatal(err)
}
Notas
Sin dependencias externas — solo stdlib. Tipos soportados: string, int/int64, uint/uint64, bool, float32/float64, []string. Los []string se parsean splitteando por coma y trimeando espacios. El tag secret:"true" no tiene efecto en runtime (solo documentacion — ver ConfigDump para ocultar al loggear).