-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.go
47 lines (36 loc) · 940 Bytes
/
core.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 (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/pkg/errors"
)
/** snapshots **/
type dnoteV0_4_0V0_4_4 map[string]bookV0_4_0V0_4_4
type bookV0_4_0V0_4_4 struct {
Name string `json:"name"`
Notes []noteV0_4_0V0_4_4 `json:"notes"`
}
type noteV0_4_0V0_4_4 struct {
UUID string `json:"uuid"`
Content string `json:"content"`
AddedOn int64 `json:"added_on"`
EditedOn int64 `json:"edited_on"`
Public bool `json:"public"`
}
func getJSONDnotePath(ctx Ctx) string {
return fmt.Sprintf("%s/dnote", ctx.dnoteDirPath)
}
func readJSONDnote(ctx Ctx) (json.RawMessage, error) {
var books json.RawMessage
notePath := getJSONDnotePath(ctx)
b, err := ioutil.ReadFile(notePath)
if err != nil {
return nil, errors.Wrap(err, "reading note content")
}
err = json.Unmarshal(b, &books)
if err != nil {
return books, errors.Wrap(err, "unmarshalling note content")
}
return books, nil
}