github.com/turingchain2020/turingchain@v1.1.21/system/consensus/consensus.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 consensus 系统基础共识包 6 package consensus 7 8 import ( 9 "github.com/turingchain2020/turingchain/queue" 10 "github.com/turingchain2020/turingchain/types" 11 ) 12 13 //Create 创建共识 14 type Create func(cfg *types.Consensus, sub []byte) queue.Module 15 16 var regConsensus = make(map[string]Create) 17 18 //QueryData 检索数据 19 var QueryData = types.NewQueryData("Query_") 20 21 //Reg ... 22 func Reg(name string, create Create) { 23 if create == nil { 24 panic("Consensus: Register driver is nil") 25 } 26 if _, dup := regConsensus[name]; dup { 27 panic("Consensus: Register called twice for driver " + name) 28 } 29 regConsensus[name] = create 30 } 31 32 //Load 加载 33 func Load(name string) (create Create, err error) { 34 if driver, ok := regConsensus[name]; ok { 35 return driver, nil 36 } 37 return nil, types.ErrNotFound 38 }