-
Notifications
You must be signed in to change notification settings - Fork 0
/
share.go
47 lines (38 loc) · 801 Bytes
/
share.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
package share
import (
"github.com/ap4y/cloud/module"
"github.com/ap4y/cloud/niltime"
)
// Share stores share data.
type Share struct {
Slug string `json:"slug"`
Type module.Type `json:"type"`
Name string `json:"name"`
Items []string `json:"items"`
ExpiresAt niltime.Time `json:"expires_at"`
}
// IsValid returns true if share is valid.
func (s Share) IsValid() bool {
if s.Slug == "" {
return false
}
if s.Name == "" {
return false
}
if s.Items == nil || len(s.Items) == 0 {
return false
}
return true
}
// Includes returns true if share includes provided item.
func (s Share) Includes(name, item string) bool {
if s.Name != name {
return false
}
for _, i := range s.Items {
if item == i {
return true
}
}
return false
}