-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathicon.go
36 lines (28 loc) · 820 Bytes
/
icon.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
package notion
import "errors"
type IconType string
const (
IconTypeEmoji IconType = "emoji"
IconTypeFile IconType = "file"
IconTypeExternal IconType = "external"
)
// Icon has one non-nil Emoji or External field, denoted by the corresponding
// IconType.
type Icon struct {
Type IconType `json:"type"`
Emoji *string `json:"emoji,omitempty"`
File *FileFile `json:"file,omitempty"`
External *FileExternal `json:"external,omitempty"`
}
func (icon Icon) Validate() error {
if icon.Type == "" {
return errors.New("icon type cannot be empty")
}
if icon.Type == IconTypeEmoji && icon.Emoji == nil {
return errors.New("icon emoji cannot be empty")
}
if icon.Type == IconTypeExternal && icon.External == nil {
return errors.New("icon external cannot be empty")
}
return nil
}