-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from gothunder/feature/add-named-handlers
Adds v0 of namedHandelers. This can be improved in the future
- Loading branch information
Showing
3 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package events | ||
|
||
import "go.uber.org/fx" | ||
|
||
// NamedHandler is a handler that has a queue name associated with it. | ||
type NamedHandler interface { | ||
QueuePosfix() string | ||
Handler | ||
} | ||
|
||
type namedHandler struct { | ||
Handler | ||
queuePosfix string | ||
} | ||
|
||
func (n *namedHandler) QueuePosfix() string { | ||
return n.queuePosfix | ||
} | ||
|
||
// NewNamedHandlerFromHandler creates a new NamedHandler from a Handler. | ||
func NewNamedHandlerFromHandler(handler Handler, queuePosfix string) NamedHandler { | ||
return &namedHandler{ | ||
Handler: handler, | ||
queuePosfix: queuePosfix, | ||
} | ||
} | ||
|
||
// FxAnnotateNamedHandler provides a named handler with group tags. | ||
// This is used to provide named handlers with the group tag `group:"named_handlers"`. | ||
// It's not a type safe function, so it's up to the caller to provide the correct type. | ||
func FxAnnotateNamedHandler(namedHandlerFunc interface{}) fx.Option { | ||
return fx.Provide( | ||
fx.Annotate(namedHandlerFunc, fx.As(new(NamedHandler)), fx.ResultTags(`group:"named_handlers"`)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters