forked from crowi/go-crowi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
54 lines (44 loc) · 909 Bytes
/
update.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
48
49
50
51
52
53
54
package main
import (
"fmt"
"log"
"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)
}
if !res.OK {
log.Printf("[ERROR] %s", res.Error)
os.Exit(1)
}
body = "changed"
res, err = client.Pages.Update(ctx, res.Page.ID, body)
if err != nil {
panic(err)
}
if !res.OK {
log.Printf("[ERROR] %s", res.Error)
os.Exit(1)
}
pp.Println(res)
}