From dbde9b3cabf983d3b3653e3ec6e760d3a034fcae Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sun, 29 Sep 2019 13:38:58 -0400 Subject: [PATCH] Finished generate.go, modified main.go I completed the process of generating the configuration file for idiots like me who like to delete configuration files. Don't worry, it's only by accident ;) I also modified main.go so that the generating process actually becomes useful. What happens is that the program checks if the configuration file exists (which will have to change to become more modular as I have it set to look in the current directory you're in) and if it doesn't, it goes ahead creates it and inputs some random junk in there that is actually supposed to help with your own configuration. --- generate.go | 25 +++++++++++++++++-------- main.go | 7 +++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/generate.go b/generate.go index c6e7ec9..bba50b1 100644 --- a/generate.go +++ b/generate.go @@ -19,29 +19,38 @@ func doesConfigExist() bool { if err != nil { return false - } else { - return true } + + return true } func createTemplateConfig(result bool) { if result == false { os.Create(config) } else { - fmt.Println() + fmt.Println("Configuration file already created") } } func writeTemplateConfig(filename string) { - file := []byte(filename) - _ = ioutil.WriteFile("config.yaml", file, 0600) + hosts := make([]string, 1) + logs := make([]string, 1) - config := Configuration{} + config := Configuration{ + "jbob", + "jbobisawesome", + 22, + hosts, + logs, + } - _, err := yaml.Marshal(config) + data, err := yaml.Marshal(&config) + + fmt.Printf(string(data)) + _ = ioutil.WriteFile(filename, data, 0600) if err != nil { - panic(err) + fmt.Errorf("Couldn't create the configuration file", err) } fmt.Println("Template for logman's configuration complete!") diff --git a/main.go b/main.go index eeca9d1..f5cdbdd 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,13 @@ package main import "log" func main() { + isCreated := doesConfigExist() + + if isCreated == false { + createTemplateConfig(isCreated) + writeTemplateConfig("config.yaml") + } + config := initializeConfig("config.yaml") sshConn, sshConfig := initializeConnection(config) clientConns := sshConn.dialConnection(sshConfig)