3d515aa441
- ConfigError y ConfigValidation como tipos producto con sus .md en types/infra/ - config_validate: validacion con tags required/format/min/max/oneof via reflection - config_merge: merge no-mutante de map[string]string con precedencia de override - config_dump: serializacion de structs a map con mascara *** para campos secret - 17 tests unitarios, todos PASS Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1.8 KiB
1.8 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_validate | function | go | infra | 1.0.0 | pure | func ConfigValidate(cfg any) ConfigValidation | Valida una struct de configuracion usando struct tags. Acumula todos los errores (required, format:email, format:url, min, max, oneof) sin detener en el primero. Retorna ConfigValidation con IsValid=true si no hay errores. |
|
|
|
false |
|
|
ConfigValidation con la lista de errores acumulados y el flag IsValid | true |
|
functions/infra/config_validate_test.go | functions/infra/config_validate.go |
Ejemplo
type ServerConfig struct {
Host string `required:"true"`
Port int `required:"true" min:"1" max:"65535"`
Email string `format:"email"`
}
v := ConfigValidate(ServerConfig{Host: "localhost", Port: 8080})
if !v.IsValid {
for _, e := range v.Errors {
log.Printf("[%s] %s: %s", e.Tag, e.Field, e.Message)
}
}
Notas
Funcion pura — usa solo reflect, sin I/O. Soporta tags: required:"true", format:"email", format:"url", min:"N", max:"N", oneof:"a b c". Solo inspecciona campos exportados. No es recursiva — no baja a structs anidados.