1// Copyright (c) 2015 Couchbase, Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package registry 16 17import ( 18 "fmt" 19 20 "github.com/blevesearch/bleve/index" 21) 22 23func RegisterIndexType(name string, constructor IndexTypeConstructor) { 24 _, exists := indexTypes[name] 25 if exists { 26 panic(fmt.Errorf("attempted to register duplicate index encoding named '%s'", name)) 27 } 28 indexTypes[name] = constructor 29} 30 31type IndexTypeConstructor func(storeName string, storeConfig map[string]interface{}, analysisQueue *index.AnalysisQueue) (index.Index, error) 32type IndexTypeRegistry map[string]IndexTypeConstructor 33 34func IndexTypeConstructorByName(name string) IndexTypeConstructor { 35 return indexTypes[name] 36} 37 38func IndexTypesAndInstances() ([]string, []string) { 39 var types []string 40 var instances []string 41 for name := range stores { 42 types = append(types, name) 43 } 44 return types, instances 45} 46