1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
17 package index
18
19 import (
20 "go4.org/jsonconfig"
21 "perkeep.org/pkg/blobserver"
22 "perkeep.org/pkg/sorted"
23 )
24
25 func init() {
26 blobserver.RegisterStorageConstructor("memory-only-dev-indexer",
27 blobserver.StorageConstructor(newMemoryIndexFromConfig))
28 }
29
30
31 func NewMemoryIndex() *Index {
32 ix, err := New(sorted.NewMemoryKeyValue())
33 if err != nil {
34
35
36 panic(err)
37 }
38 return ix
39 }
40
41 func newMemoryIndexFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
42 blobPrefix := config.RequiredString("blobSource")
43 if err := config.Validate(); err != nil {
44 return nil, err
45 }
46 sto, err := ld.GetStorage(blobPrefix)
47 if err != nil {
48 return nil, err
49 }
50
51 ix := NewMemoryIndex()
52 ix.InitBlobSource(sto)
53
54 return ix, err
55 }