yaml unmarshalling works
This commit is contained in:
parent
d315337e8f
commit
3c6953de6b
23
config.go
23
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
|
||||
}
|
||||
|
8
main.go
8
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)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user