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>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// EnvRequire returns the value of the environment variable named key.
|
||||
// If the variable is unset or empty it returns an error with a descriptive message.
|
||||
func EnvRequire(key string) (string, error) {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
return "", fmt.Errorf("env_require: environment variable %q is not set or empty", key)
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
Reference in New Issue
Block a user