-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.go
65 lines (55 loc) · 1.72 KB
/
repository.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
61
62
63
64
65
package nexus
import "encoding/xml"
// Repository is a non-group Nexus repository. Nexus actually provides a bit
// more data, but this should be enough for most uses. Groups aren't considered
// repositories by Nexus' API; there's a separate call for them.
type Repository struct {
ID string // e.g. releases
Name string // e.g. Releases
Type string // e.g. hosted, proxy, virtual...
Format string // e.g. maven2, maven1...
Policy string // e.g. RELEASE, SNAPSHOT
RemoteURI string // e.g. http://repo1.maven.org/maven2/
}
// String implements the fmt.Stringer interface.
func (repo Repository) String() string {
var uri string
if repo.RemoteURI != "" {
uri = ", points to " + repo.RemoteURI
} else {
uri = ""
}
return repo.ID + " ('" + repo.Name + "'){ " +
repo.Type + ", " + repo.Format + " format, " +
repo.Policy + " policy" + uri + " }"
}
// repos is here to help unmarshal Nexus' responses about repositories.
type repos []*Repository
// UnmarshalXML implements the xml.Unmarshaler interface.
func (r *repos) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var payload struct {
Data []struct {
ID string `xml:"id"`
Name string `xml:"name"`
Type string `xml:"repoType"`
Policy string `xml:"repoPolicy"`
Format string `xml:"format"`
RemoteURI string `xml:"remoteUri"`
} `xml:"data>repositories-item"`
}
if err := d.DecodeElement(&payload, &start); err != nil {
return err
}
for _, repo := range payload.Data {
newRepo := &Repository{
ID: repo.ID,
Name: repo.Name,
Type: repo.Type,
Format: repo.Format,
Policy: repo.Policy,
RemoteURI: repo.RemoteURI,
}
*r = append(*r, newRepo)
}
return nil
}