diff --git a/example/channel.go b/example/channel.go index fd30dc4..899d1d1 100644 --- a/example/channel.go +++ b/example/channel.go @@ -35,10 +35,10 @@ var channelRegistry = messageRelayer.NewChannelRegistry[ExampleTxContext]() func init() { var err error - err = channelRegistry.RegisterChannel(ExampleSuccessChannel) - err = channelRegistry.RegisterChannel(ExampleFailureChannel) - err = channelRegistry.RegisterChannel(ExampleCommandChannel) - err = channelRegistry.RegisterChannel(AlwaysFailCommandChannel) + err = channelRegistry.Register(ExampleSuccessChannel) + err = channelRegistry.Register(ExampleFailureChannel) + err = channelRegistry.Register(ExampleCommandChannel) + err = channelRegistry.Register(AlwaysFailCommandChannel) if err != nil { panic(err) diff --git a/messageRelayer/channel.go b/messageRelayer/channel.go index 100bcfb..89452e6 100644 --- a/messageRelayer/channel.go +++ b/messageRelayer/channel.go @@ -1,13 +1,12 @@ package messageRelayer import ( - "errors" "github.com/violetpay-org/go-saga" "sync" ) type ChannelRegistry[Tx saga.TxContext] interface { - RegisterChannel(channel Channel[Tx]) error + Register(channel Channel[Tx]) error // Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration. Range(func(name saga.ChannelName, channel Channel[Tx]) bool) @@ -56,9 +55,9 @@ func NewChannelRegistry[Tx saga.TxContext]() ChannelRegistry[Tx] { return &channelRegistry[Tx]{} } -func (r *channelRegistry[Tx]) RegisterChannel(channel Channel[Tx]) error { +func (r *channelRegistry[Tx]) Register(channel Channel[Tx]) error { if _, ok := r.channels.Load(channel.Name()); ok { - return errors.New("channel already exists") + return saga.ErrChannelAlreadyRegistered } r.channels.Store(channel.Name(), channel) return nil