Start with go version

This commit is contained in:
2024-09-10 10:08:12 +02:00
parent af8b4db718
commit ea9c650f82
47 changed files with 272 additions and 1182 deletions

62
src/util/notion/notion.go Normal file
View 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
}