-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
31 additions
and
0 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,26 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/lerenn/asyncapi-codegen/pkg/log" | ||
) | ||
|
||
// Recovery is a middleware that recovers from panic in middlewares coming after | ||
// it and user code from subscription. | ||
func Recovery(logger log.Interface) Middleware { | ||
return func(ctx context.Context, next Next) context.Context { | ||
// Recover in case of panic | ||
defer func() { | ||
if r := recover(); r != nil { | ||
logger.Error(ctx, fmt.Sprintf("Recovered from panic: %v", r)) | ||
} | ||
}() | ||
|
||
// Call next middleware | ||
next(ctx) | ||
|
||
return ctx | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package utils | ||
|
||
// ToReference returns a pointer to the given value | ||
func ToReference[T any](t T) *T { | ||
return &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