Skip to content

Commit

Permalink
refactor: update naming convention for mediator interfaces and structs
Browse files Browse the repository at this point in the history
- Change `handle` method to `Handle` in `iPipelineBehavior`, `iRequestHandler`, and `iNotificationHandler` interfaces
- Change `handle` method to `Handle` in all corresponding structs
- Update all method calls to use the new `Handle` method
- No changes were made to `mediatr_test.go`

Signed-off-by: ehsandavari <[email protected]>
  • Loading branch information
ehsandavari committed Mar 25, 2023
1 parent c154b41 commit ae8194b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
19 changes: 8 additions & 11 deletions mediatr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type requestHandlerFunc func() (any, IError)

// iPipelineBehavior is a Pipeline behavior for wrapping the inner handler.
type iPipelineBehavior interface {
handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError)
Handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError)
}

type iRequestHandler[TRequest any, TResponse any] interface {
handle(ctx context.Context, request TRequest) (TResponse, IError)
Handle(ctx context.Context, request TRequest) (TResponse, IError)
}

type iNotificationHandler[TNotification any] interface {
handle(ctx context.Context, notification TNotification) IError
Handle(ctx context.Context, notification TNotification) IError
}

var requestHandlersRegistrations = map[reflect.Type]any{}
Expand Down Expand Up @@ -105,17 +105,14 @@ func Send[TRequest any, TResponse any](ctx context.Context, request TRequest) (T
var reversPipes = reversOrder(pipelineBehaviours)

var lastHandler requestHandlerFunc = func() (any, IError) {
return requestHandler.handle(ctx, request)
return requestHandler.Handle(ctx, request)
}

aggregateResult := linq.From(reversPipes).AggregateWithSeedT(lastHandler, func(next requestHandlerFunc, pipe iPipelineBehavior) requestHandlerFunc {
pipeValue := pipe
aggregateResult := linq.From(reversPipes).AggregateWithSeedT(lastHandler, func(next requestHandlerFunc, pipelineBehavior iPipelineBehavior) requestHandlerFunc {
nexValue := next

var handlerFunc requestHandlerFunc = func() (any, IError) {
return pipeValue.handle(ctx, request, nexValue)
return pipelineBehavior.Handle(ctx, request, nexValue)
}

return handlerFunc
})

Expand All @@ -129,7 +126,7 @@ func Send[TRequest any, TResponse any](ctx context.Context, request TRequest) (T

return response.(TResponse), nil
} else {
res, err := requestHandler.handle(ctx, request)
res, err := requestHandler.Handle(ctx, request)
if err != nil {
// error handling request
return *new(TResponse), err
Expand All @@ -156,7 +153,7 @@ func Publish[TNotification any](ctx context.Context, notification TNotification)
if !ok {
return ErrorNotificationHandlerNotValid
}
if err := notificationHandler.handle(ctx, notification); err != nil {
if err := notificationHandler.Handle(ctx, notification); err != nil {
return err
}
}
Expand Down
18 changes: 9 additions & 9 deletions mediatr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ type ResponseTest struct {
type RequestTestHandler struct {
}

func (c *RequestTestHandler) handle(ctx context.Context, request *RequestTest) (*ResponseTest, IError) {
func (c *RequestTestHandler) Handle(ctx context.Context, request *RequestTest) (*ResponseTest, IError) {
fmt.Println("RequestTestHandler.Handled")
testData = append(testData, "RequestTestHandler")

Expand All @@ -263,7 +263,7 @@ type ResponseTest2 struct {
type RequestTestHandler2 struct {
}

func (c *RequestTestHandler2) handle(ctx context.Context, request *RequestTest2) (*ResponseTest2, IError) {
func (c *RequestTestHandler2) Handle(ctx context.Context, request *RequestTest2) (*ResponseTest2, IError) {
fmt.Println("RequestTestHandler2.Handled")
testData = append(testData, "RequestTestHandler2")

Expand All @@ -274,7 +274,7 @@ func (c *RequestTestHandler2) handle(ctx context.Context, request *RequestTest2)
type RequestTestHandler3 struct {
}

func (c *RequestTestHandler3) handle(ctx context.Context, request *RequestTest2) (*ResponseTest2, IError) {
func (c *RequestTestHandler3) Handle(ctx context.Context, request *RequestTest2) (*ResponseTest2, IError) {
return nil, ErrorRequestHandlerAlreadyExists
}

Expand All @@ -287,7 +287,7 @@ type NotificationTest struct {
type NotificationTestHandler struct {
}

func (c *NotificationTestHandler) handle(ctx context.Context, notification *NotificationTest) IError {
func (c *NotificationTestHandler) Handle(ctx context.Context, notification *NotificationTest) IError {
notification.Processed = true
fmt.Println("NotificationTestHandler.Handled")
testData = append(testData, "NotificationTestHandler")
Expand All @@ -304,7 +304,7 @@ type NotificationTest2 struct {
type NotificationTestHandler2 struct {
}

func (c *NotificationTestHandler2) handle(ctx context.Context, notification *NotificationTest2) IError {
func (c *NotificationTestHandler2) Handle(ctx context.Context, notification *NotificationTest2) IError {
notification.Processed = true
fmt.Println("NotificationTestHandler2.Handled")
testData = append(testData, "NotificationTestHandler2")
Expand All @@ -317,15 +317,15 @@ func (c *NotificationTestHandler2) handle(ctx context.Context, notification *Not
type NotificationTestHandler3 struct {
}

func (c *NotificationTestHandler3) handle(ctx context.Context, notification *NotificationTest) IError {
func (c *NotificationTestHandler3) Handle(ctx context.Context, notification *NotificationTest) IError {
return ErrorRequestHandlerAlreadyExists
}

// /////////////////////////////////////////////////////////////////////////////////////////////
type NotificationTestHandler4 struct {
}

func (c *NotificationTestHandler4) handle(ctx context.Context, notification *NotificationTest) IError {
func (c *NotificationTestHandler4) Handle(ctx context.Context, notification *NotificationTest) IError {
notification.Processed = true
fmt.Println("NotificationTestHandler4.Handled")
testData = append(testData, "NotificationTestHandler4")
Expand All @@ -337,7 +337,7 @@ func (c *NotificationTestHandler4) handle(ctx context.Context, notification *Not
type PipelineBehaviourTest struct {
}

func (c *PipelineBehaviourTest) handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError) {
func (c *PipelineBehaviourTest) Handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError) {
fmt.Println("PipelineBehaviourTest.Handled")
testData = append(testData, "PipelineBehaviourTest")

Expand All @@ -353,7 +353,7 @@ func (c *PipelineBehaviourTest) handle(ctx context.Context, request any, next re
type PipelineBehaviourTest2 struct {
}

func (c *PipelineBehaviourTest2) handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError) {
func (c *PipelineBehaviourTest2) Handle(ctx context.Context, request any, next requestHandlerFunc) (any, IError) {
fmt.Println("PipelineBehaviourTest2.Handled")
testData = append(testData, "PipelineBehaviourTest2")

Expand Down

0 comments on commit ae8194b

Please sign in to comment.