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 | |
| 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-- | Makefile | 7 | ||||
| -rw-r--r-- | c_init.go | 25 | ||||
| -rw-r--r-- | c_josh.go | 10 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 4 | 
5 files changed, 42 insertions, 6 deletions
| @@ -18,11 +18,12 @@  .DEFAULT_GOAL	:= run  SHELL			:= /bin/sh +SRC				:= *.go -run: -	@go run *.go +run: ${SRC} +	@go run ${SRC} -all: +josh: ${SRC}  	@go build  clean: @@ -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())  		}  	}  } @@ -50,6 +50,16 @@ package main  import (  ) +// 0: ssh +// 1: rdp +type host struct { +	ID   int64 +	Type int8   `yaml:"type"` +	Host string `yaml:"host"` +	Port uint16 `yaml:"port"` +	User string `yaml:"user"` +} +  func main() {  	var data_dir string @@ -1,3 +1,5 @@  module josh  go 1.18 + +require gopkg.in/yaml.v3 v3.0.1 @@ -0,0 +1,4 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | 
