-
Notifications
You must be signed in to change notification settings - Fork 837
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
53 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
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
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 streamx | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cloudwego/kitex/pkg/stats" | ||
) | ||
|
||
func NewStreamRecvStatMiddleware(ehandler EventHandler) StreamRecvMiddleware { | ||
return func(next StreamRecvEndpoint) StreamRecvEndpoint { | ||
return func(ctx context.Context, stream Stream, res any) (err error) { | ||
err = next(ctx, stream, res) | ||
ehandler(ctx, stats.StreamRecv, err) | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func NewStreamSendStatMiddleware(ehandler EventHandler) StreamSendMiddleware { | ||
return func(next StreamSendEndpoint) StreamSendEndpoint { | ||
return func(ctx context.Context, stream Stream, res any) (err error) { | ||
err = next(ctx, stream, res) | ||
ehandler(ctx, stats.StreamSend, err) | ||
return err | ||
} | ||
} | ||
} |
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