Home Download Docs Code Community
     1	/*
     2	Copyright 2011 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    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	// NewMemoryIndex returns an Index backed only by memory, for use in tests.
    31	func NewMemoryIndex() *Index {
    32		ix, err := New(sorted.NewMemoryKeyValue())
    33		if err != nil {
    34			// Nothing to fail in memory, so worth panicking about
    35			// if we ever see something.
    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	}
Website layout inspired by memcached.
Content by the authors.