Source File
midgen.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub
package pubsubimport (pb)// msgIDGenerator handles computing IDs for msgs// It allows setting custom generators(MsgIdFunction) per topictype msgIDGenerator struct {Default MsgIdFunctiontopicGensLk sync.RWMutextopicGens map[string]MsgIdFunction}func newMsgIdGenerator() *msgIDGenerator {return &msgIDGenerator{Default: DefaultMsgIdFn,topicGens: make(map[string]MsgIdFunction),}}// Set sets custom id generator(MsgIdFunction) for topic.func ( *msgIDGenerator) ( string, MsgIdFunction) {.topicGensLk.Lock().topicGens[] =.topicGensLk.Unlock()}// ID computes ID for the msg or short-circuits with the cached value.func ( *msgIDGenerator) ( *Message) string {if .ID != "" {return .ID}.ID = .RawID(.Message)return .ID}// RawID computes ID for the proto 'msg'.func ( *msgIDGenerator) ( *pb.Message) string {.topicGensLk.RLock(), := .topicGens[.GetTopic()].topicGensLk.RUnlock()if ! {= .Default}return ()}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |