github.com/turingchain2020/turingchain@v1.1.21/system/store/store.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package store store the world - state data 6 package store 7 8 import ( 9 "github.com/turingchain2020/turingchain/queue" 10 "github.com/turingchain2020/turingchain/types" 11 ) 12 13 // Storecreate store queue module 14 type Storecreate func(cfg *types.Store, sub []byte, turingchaincfg *types.TuringchainConfig) queue.Module 15 16 var regStore = make(map[string]Storecreate) 17 18 // Reg 注册 store driver 19 func Reg(name string, create Storecreate) { 20 if create == nil { 21 panic("Store: Register driver is nil") 22 } 23 if _, dup := regStore[name]; dup { 24 panic("Store: Register called twice for driver " + name) 25 } 26 regStore[name] = create 27 } 28 29 // Load load StoreCreate by name 30 func Load(name string) (create Storecreate, err error) { 31 if driver, ok := regStore[name]; ok { 32 return driver, nil 33 } 34 return nil, types.ErrNotFound 35 }