Skip to content

Instantly share code, notes, and snippets.

@raphink
Last active August 10, 2016 14:21
Show Gist options
  • Save raphink/ce3cbf1c644b14945d1104eb880dd8aa to your computer and use it in GitHub Desktop.
Save raphink/ce3cbf1c644b14945d1104eb880dd8aa to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
type Clouds struct {
Clouds map[string]struct {
Profile string `yaml:"profile,omitempty"`
RegionName string `yaml:"region_name,omitempty"`
Regions []string `yaml:"regions,omitempty"`
DNSAPIVersion int `yaml:"dns_api_version,omitempty"`
Auth struct {
AuthURL string `yaml:"auth_url,omitempty"`
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
ProjectName string `yaml:"project_name,omitempty"`
ProjectID int `yaml:"project_id,omitempty"`
} `yaml:"auth,omitempty"`
}
}
type CloudAuth struct {
}
func main() {
clouds, err := parseCloudsYaml("/home/raphink/bas/go/yaml")
if err != nil {
log.Fatal(err)
}
y, _ := yaml.Marshal(clouds)
fmt.Println(string(y))
}
func parseCloudsYaml(dirname string) (clouds *Clouds, err error) {
clouds = &Clouds{}
filename := fmt.Sprintf("%s/clouds.yaml", dirname)
if f, err := os.Stat(filename); err != nil || !f.Mode().IsRegular() {
return nil, nil
}
fileContent, err := ioutil.ReadFile(filename)
err = yaml.Unmarshal(fileContent, clouds)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment