-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexMaps.go
48 lines (42 loc) · 1.02 KB
/
indexMaps.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
package main
import (
"encoding/json"
"fmt"
"github.com/boltdb/bolt"
)
func newAuthorMap(db *bolt.DB) (map[string]interface{}, error) {
m := map[string]interface{}{}
err := db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
bkt := tx.Bucket([]byte("books"))
bkt.ForEach(func(k, v []byte) error {
b := book{}
err := json.Unmarshal(v, &b)
if err != nil {
fmt.Println("Error unmarshalling json", err) // to log once implemented
}
m[b.Author] = struct{}{}
return nil
})
return nil
})
return m, err
}
func newISBN13Map(db *bolt.DB) (map[string]interface{}, error) {
m := map[string]interface{}{}
err := db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
bkt := tx.Bucket([]byte("books"))
bkt.ForEach(func(k, v []byte) error {
b := book{}
err := json.Unmarshal(v, &b)
if err != nil {
fmt.Println("Error unmarshalling json", err) // to log once implemented
}
m[b.ISBN13] = struct{}{}
return nil
})
return nil
})
return m, err
}