forked from umweltdk/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathproject.go
74 lines (64 loc) · 1.85 KB
/
project.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
66
67
68
69
70
71
72
73
74
package types
import (
"encoding/json"
)
type Project struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Href string `json:"href,omitempty"`
WebUrl string `json:"webUrl,omitempty"`
ParentProjectID ProjectId `json:"parentProject,omitempty"`
BuildConfigurations BuildConfigurations `json:"buildTypes,omitempty"`
Templates BuildConfigurations `json:"templates,omitempty"`
Parameters Parameters `json:"parameters,omitempty"`
Projects Projects `json:"projects,omitempty"`
}
type ProjectId string
type ProjectShort struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
ParentProjectID string `json:"parentProjectId"`
Href string `json:"href"`
WebURL string `json:"webUrl"`
}
func (p ProjectId) MarshalJSON() ([]byte, error) {
pi := &ProjectShort{
ID: string(p),
}
return json.Marshal(pi)
}
func (p *ProjectId) UnmarshalJSON(b []byte) error {
var pi ProjectShort
if err := json.Unmarshal(b, &pi); err != nil {
return err
}
*p = ProjectId(pi.ID)
return nil
}
type Projects map[string]Project
type projectsInput struct {
Project []Project `json:"project"`
}
func (p Projects) MarshalJSON() ([]byte, error) {
pi := &projectsInput{
Project: make([]Project, 0),
}
for _, value := range p {
pi.Project = append(pi.Project, value)
}
return json.Marshal(pi)
}
func (p *Projects) UnmarshalJSON(b []byte) error {
var pi projectsInput
if err := json.Unmarshal(b, &pi); err != nil {
return err
}
m := make(Projects)
for _, proj := range pi.Project {
m[proj.ID] = proj
}
*p = m
return nil
}