forked from crowi/go-crowi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
47 lines (38 loc) · 867 Bytes
/
list.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 main
import (
"fmt"
"os"
"time"
"github.com/crowi/go-crowi"
"github.com/k0kubun/pp"
"golang.org/x/net/context"
)
func main() {
config := crowi.Config{
URL: "http://localhost:3000",
Token: os.Getenv("CROWI_ACCESS_TOKEN"),
}
client, err := crowi.NewClient(config)
if err != nil {
panic(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
var (
path = fmt.Sprintf("/user/%s/go-crowi-test-%d", os.Getenv("USER"), time.Now().UnixNano())
body = "# this is a sample\n\ntest"
)
res, err := client.Pages.Create(ctx, path, body)
if err != nil {
panic(err)
}
_, err = client.Attachments.Add(ctx, res.Page.ID, "_example/attachments/sample.png")
if err != nil {
panic(err)
}
res2, err := client.Attachments.List(ctx, res.Page.ID)
if err != nil {
panic(err)
}
pp.Println(res2)
}