-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
186 lines (173 loc) · 4.81 KB
/
logging.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// This file was auto-generated by Fern from our API Definition.
package generatorexec
import (
json "encoding/json"
fmt "fmt"
)
type GeneratorUpdate struct {
Type string
Init *InitUpdate
InitV2 *InitUpdateV2
Log *LogUpdate
Publishing *PackageCoordinate
Published *PackageCoordinate
ExitStatusUpdate *ExitStatusUpdate
}
func NewGeneratorUpdateFromInit(value *InitUpdate) *GeneratorUpdate {
return &GeneratorUpdate{Type: "init", Init: value}
}
func NewGeneratorUpdateFromInitV2(value *InitUpdateV2) *GeneratorUpdate {
return &GeneratorUpdate{Type: "initV2", InitV2: value}
}
func NewGeneratorUpdateFromLog(value *LogUpdate) *GeneratorUpdate {
return &GeneratorUpdate{Type: "log", Log: value}
}
func NewGeneratorUpdateFromPublishing(value *PackageCoordinate) *GeneratorUpdate {
return &GeneratorUpdate{Type: "publishing", Publishing: value}
}
func NewGeneratorUpdateFromPublished(value *PackageCoordinate) *GeneratorUpdate {
return &GeneratorUpdate{Type: "published", Published: value}
}
func NewGeneratorUpdateFromExitStatusUpdate(value *ExitStatusUpdate) *GeneratorUpdate {
return &GeneratorUpdate{Type: "exitStatusUpdate", ExitStatusUpdate: value}
}
func (g *GeneratorUpdate) UnmarshalJSON(data []byte) error {
var unmarshaler struct {
Type string `json:"_type"`
}
if err := json.Unmarshal(data, &unmarshaler); err != nil {
return err
}
g.Type = unmarshaler.Type
switch unmarshaler.Type {
case "init":
value := new(InitUpdate)
if err := json.Unmarshal(data, &value); err != nil {
return err
}
g.Init = value
case "initV2":
value := new(InitUpdateV2)
if err := json.Unmarshal(data, &value); err != nil {
return err
}
g.InitV2 = value
case "log":
value := new(LogUpdate)
if err := json.Unmarshal(data, &value); err != nil {
return err
}
g.Log = value
case "publishing":
var valueUnmarshaler struct {
Publishing *PackageCoordinate `json:"publishing,omitempty"`
}
if err := json.Unmarshal(data, &valueUnmarshaler); err != nil {
return err
}
g.Publishing = valueUnmarshaler.Publishing
case "published":
var valueUnmarshaler struct {
Published *PackageCoordinate `json:"published,omitempty"`
}
if err := json.Unmarshal(data, &valueUnmarshaler); err != nil {
return err
}
g.Published = valueUnmarshaler.Published
case "exitStatusUpdate":
var valueUnmarshaler struct {
ExitStatusUpdate *ExitStatusUpdate `json:"exitStatusUpdate,omitempty"`
}
if err := json.Unmarshal(data, &valueUnmarshaler); err != nil {
return err
}
g.ExitStatusUpdate = valueUnmarshaler.ExitStatusUpdate
}
return nil
}
func (g GeneratorUpdate) MarshalJSON() ([]byte, error) {
switch g.Type {
default:
return nil, fmt.Errorf("invalid type %s in %T", g.Type, g)
case "init":
var marshaler = struct {
Type string `json:"_type"`
*InitUpdate
}{
Type: g.Type,
InitUpdate: g.Init,
}
return json.Marshal(marshaler)
case "initV2":
var marshaler = struct {
Type string `json:"_type"`
*InitUpdateV2
}{
Type: g.Type,
InitUpdateV2: g.InitV2,
}
return json.Marshal(marshaler)
case "log":
var marshaler = struct {
Type string `json:"_type"`
*LogUpdate
}{
Type: g.Type,
LogUpdate: g.Log,
}
return json.Marshal(marshaler)
case "publishing":
var marshaler = struct {
Type string `json:"_type"`
Publishing *PackageCoordinate `json:"publishing,omitempty"`
}{
Type: g.Type,
Publishing: g.Publishing,
}
return json.Marshal(marshaler)
case "published":
var marshaler = struct {
Type string `json:"_type"`
Published *PackageCoordinate `json:"published,omitempty"`
}{
Type: g.Type,
Published: g.Published,
}
return json.Marshal(marshaler)
case "exitStatusUpdate":
var marshaler = struct {
Type string `json:"_type"`
ExitStatusUpdate *ExitStatusUpdate `json:"exitStatusUpdate,omitempty"`
}{
Type: g.Type,
ExitStatusUpdate: g.ExitStatusUpdate,
}
return json.Marshal(marshaler)
}
}
type GeneratorUpdateVisitor interface {
VisitInit(*InitUpdate) error
VisitInitV2(*InitUpdateV2) error
VisitLog(*LogUpdate) error
VisitPublishing(*PackageCoordinate) error
VisitPublished(*PackageCoordinate) error
VisitExitStatusUpdate(*ExitStatusUpdate) error
}
func (g *GeneratorUpdate) Accept(visitor GeneratorUpdateVisitor) error {
switch g.Type {
default:
return fmt.Errorf("invalid type %s in %T", g.Type, g)
case "init":
return visitor.VisitInit(g.Init)
case "initV2":
return visitor.VisitInitV2(g.InitV2)
case "log":
return visitor.VisitLog(g.Log)
case "publishing":
return visitor.VisitPublishing(g.Publishing)
case "published":
return visitor.VisitPublished(g.Published)
case "exitStatusUpdate":
return visitor.VisitExitStatusUpdate(g.ExitStatusUpdate)
}
}