-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
42 lines (36 loc) · 800 Bytes
/
config.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
package jenkins
import (
"encoding/json"
"encoding/xml"
"io"
)
type configXmlItem struct {
XMLName xml.Name
Value string `xml:",innerxml"`
}
type configXml struct {
Items []configXmlItem `xml:",any"`
}
type jobsJson struct {
Jobs []Job `json:"jobs"`
}
func parseConfig(config io.Reader) (map[string]string, error) {
var decoder = xml.NewDecoder(config)
var cfg configXml
if err := decoder.Decode(&cfg); err != nil {
return nil, err
}
result := make(map[string]string)
for _, item := range cfg.Items {
result[item.XMLName.Local] = item.Value
}
return result, nil
}
func parseJobs(jobs io.Reader) ([]Job, error) {
var decoder = json.NewDecoder(jobs)
var jobsjson jobsJson
if err := decoder.Decode(&jobsjson); err != nil {
return nil, err
}
return jobsjson.Jobs, nil
}