Created
September 4, 2014 19:21
-
-
Save mlafeldt/fc1eacb6d6754c2ac946 to your computer and use it in GitHub Desktop.
Go YAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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