aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2023-12-14 20:20:20 +0100
committerJoe <rbo@gmx.us>2023-12-14 20:20:20 +0100
commit34921eae2dac9f320c446c81991d2e3fe538923c (patch)
tree9a3f049fa0fe7aacbcd847967011ea36cd6ae397
parentdates (diff)
downloadhardflip-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--Makefile7
-rw-r--r--c_init.go25
-rw-r--r--c_josh.go10
-rw-r--r--go.mod2
-rw-r--r--go.sum4
5 files changed, 42 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 4560bb8..dbcdd1e 100644
--- a/Makefile
+++ b/Makefile
@@ -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:
diff --git a/c_init.go b/c_init.go
index 772b3ee..057d741 100644
--- a/c_init.go
+++ b/c_init.go
@@ -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())
}
}
}
diff --git a/c_josh.go b/c_josh.go
index bb82f2b..838faf2 100644
--- a/c_josh.go
+++ b/c_josh.go
@@ -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
diff --git a/go.mod b/go.mod
index 4ae369e..25ebf11 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
module josh
go 1.18
+
+require gopkg.in/yaml.v3 v3.0.1
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..a62c313
--- /dev/null
+++ b/go.sum
@@ -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=