47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.7 KiB
Markdown
52 lines
1.7 KiB
Markdown
---
|
|
name: config_from_file
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func ConfigFromFile(path string, target any) error"
|
|
description: "Carga configuracion desde un archivo en target. Soporta JSON (encoding/json stdlib). YAML es stub: retorna 'not implemented'. Extension determina el formato."
|
|
tags: [config, file, json, yaml, infra, pendiente-usar]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [encoding/json, fmt, os, strings]
|
|
params:
|
|
- name: path
|
|
desc: "ruta al archivo de configuracion (.json, .yaml, .yml)"
|
|
- name: target
|
|
desc: "puntero a struct o mapa donde se va a deserializar la configuracion"
|
|
output: "nil si el archivo se cargo y parseo correctamente, error si el archivo no existe, tiene formato invalido, o la extension no esta soportada"
|
|
tested: true
|
|
tests:
|
|
- "carga JSON valido en struct"
|
|
- "JSON invalido retorna error"
|
|
- "archivo inexistente retorna error"
|
|
- "extension YAML retorna not implemented"
|
|
- "extension desconocida retorna error"
|
|
test_file_path: "functions/infra/config_from_file_test.go"
|
|
file_path: "functions/infra/config_from_file.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
type DBConfig struct {
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
Database string `json:"database"`
|
|
}
|
|
|
|
var cfg DBConfig
|
|
if err := ConfigFromFile("config/database.json", &cfg); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
JSON: implementacion completa via encoding/json de stdlib. YAML: stub que retorna error "not implemented" — para YAML real agregar gopkg.in/yaml.v3. El formato se determina por la extension del archivo (case-insensitive). Se puede combinar con ConfigFromEnv: cargar defaults del archivo y luego sobreescribir con env vars.
|