Line data Source code
1 : // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package remote 6 : 7 : import "github.com/pkg/errors" 8 : 9 : // MakeSimpleFactory returns a StorageFactory implementation that produces the given 10 : // Storage objects. 11 2 : func MakeSimpleFactory(m map[Locator]Storage) StorageFactory { 12 2 : return simpleFactory(m) 13 2 : } 14 : 15 : type simpleFactory map[Locator]Storage 16 : 17 : var _ StorageFactory = simpleFactory{} 18 : 19 : // CreateStorage is part of the StorageFactory interface. 20 2 : func (sf simpleFactory) CreateStorage(locator Locator) (Storage, error) { 21 2 : if s, ok := sf[locator]; ok { 22 2 : return s, nil 23 2 : } 24 1 : return nil, errors.Errorf("unknown locator '%s'", locator) 25 : }