Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created September 4, 2014 19:21
Show Gist options
  • Save mlafeldt/fc1eacb6d6754c2ac946 to your computer and use it in GitHub Desktop.
Save mlafeldt/fc1eacb6d6754c2ac946 to your computer and use it in GitHub Desktop.
Go YAML
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v1"
)
var data = `
---
hostname: 127.0.0.1
username: vagrant
ssh_key: "/Users/mlafeldt/.vagrant.d/insecure_private_key"
port: '2222'
last_action: create
`
type T struct {
Hostname string `yaml:"hostname"`
Username string `yaml:"username"`
SSHKey string `yaml:"ssh_key"`
Port string `yaml:"port"`
LastAction string `yaml:"last_action"`
}
func main() {
t := T{}
err := yaml.Unmarshal([]byte(data), &t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t:\n%+v\n\n", t)
fmt.Printf("ssh -i %s -p %s %s@%s\n", t.SSHKey, t.Port, t.Username, t.Hostname)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment