yaml unmarshalling works

This commit is contained in:
Wyatt Miller 2019-08-13 11:01:26 -04:00
parent d315337e8f
commit 3c6953de6b
3 changed files with 30 additions and 5 deletions

View File

@ -1,12 +1,31 @@
package main package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Configuration struct { type Configuration struct {
Username string Username string
Password string Password string
Port int Port string
Hosts []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
} }

View File

@ -3,5 +3,11 @@ package main
import "fmt" import "fmt"
func main() { func main() {
fmt.Println("Hello!") //fmt.Println("Hello!")
//var config Configuration
config := initializeConfig("config.yaml")
fmt.Println(config.Username)
} }

4
ssh.go
View File

@ -1,6 +1,6 @@
package main package main
type sshConnection struct { type sshConnection struct {
Username string Username Configuration
Password []string Password Configuration
} }