Last active
August 10, 2016 14:21
-
-
Save raphink/ce3cbf1c644b14945d1104eb880dd8aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"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