diff options
author | Joe <rbo@gmx.us> | 2023-12-14 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2023-12-14 20:20:20 +0100 |
commit | 34921eae2dac9f320c446c81991d2e3fe538923c (patch) | |
tree | 9a3f049fa0fe7aacbcd847967011ea36cd6ae397 /c_init.go | |
parent | dates (diff) | |
download | hardflip-34921eae2dac9f320c446c81991d2e3fe538923c.tar.gz hardflip-34921eae2dac9f320c446c81991d2e3fe538923c.tar.bz2 hardflip-34921eae2dac9f320c446c81991d2e3fe538923c.tar.xz hardflip-34921eae2dac9f320c446c81991d2e3fe538923c.tar.zst hardflip-34921eae2dac9f320c446c81991d2e3fe538923c.zip |
up
Diffstat (limited to '')
-rw-r--r-- | c_init.go | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -49,8 +49,10 @@ package main import ( "fmt" - "os" "io/ioutil" + "os" + "path/filepath" + "gopkg.in/yaml.v3" ) // This function will go get the data folder and try to create it if it does @@ -80,6 +82,22 @@ func c_get_data_dir() string { return *ptr } +func c_read_yaml_file(file string) { + var host host + yaml_file, err := ioutil.ReadFile(file) + + if err != nil { + c_die("error reading file " + file, err) + } + if err = yaml.Unmarshal(yaml_file, &host); err != nil { + c_die("error reading yaml file " + file, err) + } + fmt.Println(host) + os.Exit(0) +} + +// This function recurses into the specified root directory in order to load +// every yaml file into memory. func c_recurse_data_dir(dir string, root string) { files, err := ioutil.ReadDir(root + dir) if err != nil { @@ -88,8 +106,9 @@ func c_recurse_data_dir(dir string, root string) { for _, file := range files { if file.IsDir() == true { c_recurse_data_dir(dir + file.Name() + "/", root) - } else { - fmt.Println(dir + file.Name()) + } else if filepath.Ext(file.Name()) == ".yml" { + fmt.Println(root + dir + file.Name()) + c_read_yaml_file(root + dir + file.Name()) } } } |