26 lines
537 B
Go
26 lines
537 B
Go
|
// utils/file_reader.go
|
||
|
package utils
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
|
||
|
"gopkg.in/yaml.v3"
|
||
|
)
|
||
|
|
||
|
// Función para leer el archivo YAML
|
||
|
func ReadYMLFile(filePath string, out interface{}) error {
|
||
|
data, err := ioutil.ReadFile(filePath)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("error al leer el archivo %s: %v", filePath, err)
|
||
|
}
|
||
|
|
||
|
// Deserializar el contenido YAML en la estructura Go pasada en "out"
|
||
|
err = yaml.Unmarshal(data, out)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("error al deserializar el archivo %s: %v", filePath, err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|