-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenvironment.go
60 lines (50 loc) · 996 Bytes
/
environment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"crypto/md5"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"strings"
)
type Env struct {
Version string
Container []Container
Vm []Vm
}
type Container struct {
Name string
Disksize string
}
type Vm struct {
Name string
Cpu string
Ram string
Disksize string
Image string
}
func readKey(keypath string) []byte {
mykey, err := ioutil.ReadFile(keypath) // just pass the file name
if err != nil {
fmt.Print(err)
}
keystr := string(mykey)
//fmt.Printf(keystr)
mykey = []byte(strings.TrimSuffix(keystr, "\n"))
return mykey
}
func getToken(keypath string) string {
mykey := readKey(keypath)
result := fmt.Sprintf("%x", md5.Sum(mykey))
return result
}
func readCloudConfig() Env {
environment := Env{}
yamlFile, err := ioutil.ReadFile("cloud.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, &environment)
fmt.Printf("%+v\n", environment)
return environment
}