Fetch the repository succeeded.
// Package endpoint provides a wrapper that executes other wrappers for specific methods
package endpoint
import (
"gitee.com/sasukebo/go-micro/v4/client"
"gitee.com/sasukebo/go-micro/v4/server"
"context"
)
type clientWrapper struct {
endpoints map[string]bool // endpoints to execute on
wrapper client.Wrapper // the original wrapper
client.Client
}
func (c *clientWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
// execute client wrapper?
if !c.endpoints[req.Endpoint()] {
// no
return c.Client.Call(ctx, req, rsp, opts...)
}
// yes
return c.wrapper(c.Client).Call(ctx, req, rsp, opts...)
}
// NewClientWrapper wraps another client wrapper but only executes when the endpoints specified are executed.
func NewClientWrapper(cw client.Wrapper, eps ...string) client.Wrapper {
// create map of endpoints
endpoints := make(map[string]bool)
for _, ep := range eps {
endpoints[ep] = true
}
return func(c client.Client) client.Client {
return &clientWrapper{endpoints, cw, c}
}
}
// NewHandlerWrapper wraps another handler wrapper but only executes when the endpoints specified are executed.
func NewHandlerWrapper(hw server.HandlerWrapper, eps ...string) server.HandlerWrapper {
// create map of endpoints
endpoints := make(map[string]bool)
for _, ep := range eps {
endpoints[ep] = true
}
return func(h server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
// execute the handler wrapper?
if !endpoints[req.Endpoint()] {
// no
return h(ctx, req, rsp)
}
// yes
return hw(h)(ctx, req, rsp)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。