github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/extensions/extensions.go (about) 1 package extensions 2 3 import "sync/atomic" 4 5 type ExtensionID int32 6 7 var currentID int32 //nolint:gochecknoglobals 8 9 type Extension interface { 10 ExtensionID() ExtensionID 11 } 12 13 type Extensions struct { 14 extensions []Extension 15 } 16 17 func NewExtensions() *Extensions { 18 ex := &Extensions{ 19 extensions: make([]Extension, 100), 20 } 21 22 return ex 23 } 24 25 func NextExtensionID() ExtensionID { 26 id := atomic.AddInt32(¤tID, 1) 27 28 return ExtensionID(id) 29 } 30 31 func (ex *Extensions) Get(id ExtensionID) Extension { 32 return ex.extensions[id] 33 } 34 35 func (ex *Extensions) Register(extension Extension) { 36 id := extension.ExtensionID() 37 ex.extensions[id] = extension 38 }