-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option and mdws for localsession
- Loading branch information
1 parent
bf39157
commit ae937ec
Showing
9 changed files
with
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package localsession | ||
|
||
import ( | ||
"context" | ||
"github.com/cloudwego/hertz/pkg/app/client" | ||
"github.com/cloudwego/hertz/pkg/protocol" | ||
"github.com/cloudwego/localsession/backup" | ||
) | ||
|
||
// CtxRecover will merge backup context if no metainfo found in ctx | ||
func CtxRecover(hdl backup.BackupHandler) client.Middleware { | ||
return func(next client.Endpoint) client.Endpoint { | ||
return func(ctx context.Context, req *protocol.Request, resp *protocol.Response) (err error) { | ||
ctx = backup.RecoverCtxOnDemands(ctx, hdl) | ||
return next(ctx, req, resp) | ||
} | ||
} | ||
} |
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,17 @@ | ||
package localsession | ||
|
||
import ( | ||
"context" | ||
Check failure on line 4 in pkg/app/middlewares/server/localsession/localsession.go GitHub Actions / lint-and-ut (1.19)
Check failure on line 4 in pkg/app/middlewares/server/localsession/localsession.go GitHub Actions / lint-and-ut (1.20)
Check failure on line 4 in pkg/app/middlewares/server/localsession/localsession.go GitHub Actions / lint-and-ut (1.18)
Check failure on line 4 in pkg/app/middlewares/server/localsession/localsession.go GitHub Actions / lint-and-ut (1.19)
|
||
"github.com/cloudwego/hertz/pkg/app" | ||
"github.com/cloudwego/localsession/backup" | ||
) | ||
|
||
func BackupSession(opts backup.Options) app.HandlerFunc { | ||
backup.Init(opts) | ||
|
||
return func(c context.Context, ctx *app.RequestContext) { | ||
backup.BackupCtx(c) | ||
defer backup.ClearCtx() | ||
ctx.Next(c) | ||
} | ||
} |
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