1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2025-06-15 00:05:04 +02:00

Add support for Page's Icon retrieval and updates (#21)

* Add support for Page's Icon retrieval and updates

* Add support for creating a page with an icon

* Fix tests, add icon validation

* Remove unknown icon type `file`

* Add icon support for "create database" endpoint

Co-authored-by: David Stotijn <dstotijn@gmail.com>
This commit is contained in:
Lucas
2021-12-09 17:57:08 +01:00
committed by GitHub
parent 135ef8c421
commit a0926892c2
4 changed files with 189 additions and 6 deletions

38
icon.go Normal file
View File

@ -0,0 +1,38 @@
package notion
import "errors"
type IconType string
const (
IconTypeEmoji IconType = "emoji"
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"`
External *IconExternal `json:"external,omitempty"`
}
type IconExternal struct {
URL string `json:"url"`
}
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
}