Start with go version
This commit is contained in:
62
src/util/notion/notion.go
Normal file
62
src/util/notion/notion.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package notion
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jomei/notionapi"
|
||||
)
|
||||
|
||||
var client *notionapi.Client
|
||||
var authToken string
|
||||
|
||||
func Init(token string) {
|
||||
authToken = token
|
||||
client = notionapi.NewClient(notionapi.Token(token))
|
||||
}
|
||||
|
||||
func GetClient() *notionapi.Client {
|
||||
return client
|
||||
}
|
||||
|
||||
func AGetBlock(blockId string) chan struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
} {
|
||||
retval := make(chan struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
})
|
||||
go func() {
|
||||
block, err := client.Block.Get(context.Background(), notionapi.BlockID(blockId))
|
||||
retval <- struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
}{block, err}
|
||||
}()
|
||||
return retval
|
||||
}
|
||||
|
||||
func AGetBlockChildren(blockId string, startCursor string, pageSize int) chan struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
} {
|
||||
retval := make(chan struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
})
|
||||
pagination := notionapi.Pagination{StartCursor: notionapi.Cursor(startCursor), PageSize: pageSize}
|
||||
go func() {
|
||||
children, err := client.Block.GetChildren(context.Background(), notionapi.BlockID(blockId), &pagination)
|
||||
retval <- struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
}{children.Results, children.NextCursor, children.HasMore, err}
|
||||
}()
|
||||
return retval
|
||||
}
|
||||
Reference in New Issue
Block a user