-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadxml.go
49 lines (35 loc) · 876 Bytes
/
readxml.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
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io/ioutil"
)
type Conf struct {
Apikey string `xml:"apikey"`
Secretkey string `xml:"secretkey"`
Ipaddress string `xml:"ipaddress"`
Port string `xml:"port"`
}
func main() {
b, err := ioutil.ReadFile("conf.xml")
if err != nil{
fmt.Print(err)
}
data := string(b)
buf := bytes.NewBufferString(data)
conf := new(Conf)
decoded := xml.NewDecoder(buf)
err1 := decoded.Decode(conf)
if err1 != nil {
fmt.Printf("Error: %v\n", err1)
}
apikey := conf.Apikey
secretkey := conf.Secretkey
ipaddress := conf.Ipaddress
port := conf.Port
fmt.Printf("apikey: %s\n", apikey)
fmt.Printf("secretkey: %s\n", secretkey)
fmt.Printf("ipaddress: %s\n", ipaddress)
fmt.Printf("port: %s\n", port)
}