-
Notifications
You must be signed in to change notification settings - Fork 1
/
group.go
79 lines (72 loc) · 1.98 KB
/
group.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
package gcloudcx
import (
"time"
"github.com/gildas/go-logger"
"github.com/google/uuid"
)
// Group describe a Group of users
type Group struct {
ID uuid.UUID `json:"id"`
SelfURI URI `json:"selfUri"`
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
State string `json:"state"`
MemberCount int `json:"memberCount"`
Owners []*User `json:"owners"`
Images []*UserImage `json:"images"`
Addresses []*Contact `json:"addresses"`
RulesVisible bool `json:"rulesVisible"`
Visibility string `json:"visibility"`
DateModified time.Time `json:"dateModified"`
Version int `json:"version"`
client *Client `json:"-"`
logger *logger.Logger `json:"-"`
}
// Initialize initializes the object
//
// accepted parameters: *gcloudcx.Client, *logger.Logger
//
// implements Initializable
func (group *Group) Initialize(parameters ...interface{}) {
for _, raw := range parameters {
switch parameter := raw.(type) {
case uuid.UUID:
group.ID = parameter
case *Client:
group.client = parameter
case *logger.Logger:
group.logger = parameter.Child("group", "group", "id", group.ID)
}
}
if group.logger == nil {
group.logger = logger.Create("gcloudcx", &logger.NilStream{})
}
}
// GetID gets the identifier of this
//
// implements Identifiable
func (group Group) GetID() uuid.UUID {
return group.ID
}
// GetURI gets the URI of this
//
// implements Addressable
func (group Group) GetURI(ids ...uuid.UUID) URI {
if len(ids) > 0 {
return NewURI("/api/v2/groups/%s", ids[0])
}
if group.ID != uuid.Nil {
return NewURI("/api/v2/groups/%s", group.ID)
}
return URI("/api/v2/groups/")
}
// String gets a string version
//
// implements the fmt.Stringer interface
func (group Group) String() string {
if len(group.Name) > 0 {
return group.Name
}
return group.ID.String()
}