-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OS-2728] middleware: adding to subscriptions (#104)
* middleware: adding to subscriptions * middleware: adding space * middleware: camunda rename * middleware: file name change * middleware: update readme Co-authored-by: shane <[email protected]>
- Loading branch information
1 parent
238c650
commit 2a2c9f4
Showing
5 changed files
with
74 additions
and
1 deletion.
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,27 @@ | ||
package middleware_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/blacklane/go-libs/camunda/v2" | ||
"github.com/blacklane/go-libs/logger" | ||
"github.com/blacklane/go-libs/middleware" | ||
) | ||
|
||
func ExamplesSubscriptions() { | ||
log := logger.New(prettyJSONWriter{}, "ExampleEvents") | ||
|
||
handler := camunda.TaskHandlerFunc(func(ctx context.Context, completeFunc camunda.TaskCompleteFunc, t camunda.Task) { | ||
l := logger.FromContext(ctx) | ||
l.Info().Msg("always logged") | ||
}) | ||
|
||
h := middleware.CamundaSubscriptionsAddLogger(log)(handler) | ||
|
||
completeHandler := camunda.TaskCompleteFunc(func(ctx context.Context, taskID string) error { | ||
return nil | ||
}) | ||
t := camunda.Task{} | ||
|
||
h.Handle(context.Background(), completeHandler, t) | ||
} |
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,18 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/blacklane/go-libs/camunda/v2" | ||
"github.com/blacklane/go-libs/logger" | ||
) | ||
|
||
func CamundaSubscriptionsAddLogger(log logger.Logger) func(camunda.TaskHandler) camunda.TaskHandler { | ||
return func(next camunda.TaskHandler) camunda.TaskHandler { | ||
return camunda.TaskHandlerFunc(func(ctx context.Context, completeFunc camunda.TaskCompleteFunc, t camunda.Task) { | ||
log = log.With().Logger() | ||
context := log.WithContext(ctx) | ||
next.Handle(context, completeFunc, t) | ||
}) | ||
} | ||
} |
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