From 3c6953de6b49dc07f14859d7c5069428790ab547 Mon Sep 17 00:00:00 2001 From: Wyatt Miller Date: Tue, 13 Aug 2019 11:01:26 -0400 Subject: [PATCH] yaml unmarshalling works --- config.go | 23 +++++++++++++++++++++-- main.go | 8 +++++++- ssh.go | 4 ++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 43d9ca8..9077636 100644 --- a/config.go +++ b/config.go @@ -1,12 +1,31 @@ package main +import ( + "io/ioutil" + + "gopkg.in/yaml.v2" +) + type Configuration struct { Username string Password string - Port int + Port string Hosts []string } -func initializeConfig() { +func initializeConfig(filename string) Configuration { + var config Configuration + source, err := ioutil.ReadFile(filename) + if err != nil { + panic(err) + } + + err = yaml.Unmarshal(source, &config) + + if err != nil { + panic(err) + } + + return config } diff --git a/main.go b/main.go index 44ee7ea..0011fa9 100644 --- a/main.go +++ b/main.go @@ -3,5 +3,11 @@ package main import "fmt" func main() { - fmt.Println("Hello!") + //fmt.Println("Hello!") + + //var config Configuration + + config := initializeConfig("config.yaml") + fmt.Println(config.Username) + } diff --git a/ssh.go b/ssh.go index a9dd39b..56bdd73 100644 --- a/ssh.go +++ b/ssh.go @@ -1,6 +1,6 @@ package main type sshConnection struct { - Username string - Password []string + Username Configuration + Password Configuration }