-
Notifications
You must be signed in to change notification settings - Fork 1
/
flow.go
72 lines (64 loc) · 1.51 KB
/
flow.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
package gcloudcx
import (
"encoding/json"
"github.com/gildas/go-errors"
"github.com/google/uuid"
)
type Flow struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Division *Division `json:"division,omitempty"`
IsActive bool `json:"active"`
IsSystem bool `json:"system"`
IsDeleted bool `json:"deleted"`
}
// Initialize initializes the object
//
// implements Initializable
func (flow *Flow) Initialize(parameters ...interface{}) {
for _, raw := range parameters {
switch parameter := raw.(type) {
case uuid.UUID:
flow.ID = parameter
}
}
}
// GetID gets the identifier of this
//
// implements Identifiable
func (flow Flow) GetID() uuid.UUID {
return flow.ID
}
// GetURI gets the URI of this
//
// implements Addressable
func (flow Flow) GetURI(ids ...uuid.UUID) URI {
if len(ids) > 0 {
return NewURI("/api/v2/flows/%s", ids[0])
}
if flow.ID != uuid.Nil {
return NewURI("/api/v2/flows/%s", flow.ID)
}
return URI("/api/v2/flows/")
}
// String gets a string representation of this
//
// implements fmt.Stringer
func (flow Flow) String() string {
return flow.Name
}
// MarshalJSON marshals this into JSON
//
// implements json.Marshaler
func (flow Flow) MarshalJSON() ([]byte, error) {
type surrogate Flow
data, err := json.Marshal(&struct {
surrogate
SelfURI URI `json:"selfUri"`
}{
surrogate: surrogate(flow),
SelfURI: flow.GetURI(),
})
return data, errors.JSONMarshalError.Wrap(err)
}