You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1014 B
Go

package filter
import (
"context"
"fmt"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/protocol"
)
func init() {
extension.SetFilter("authFilter", NewAuthFilter)
}
func NewAuthFilter() filter.Filter {
return &AuthFilter{}
}
type AuthFilter struct {
}
func (f *AuthFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
//xxx 接收凭证
invocation.SetAttachment("usertoken", "this is jwt token")
return invoker.Invoke(ctx, invocation)
}
func (f *AuthFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, protocol protocol.Invocation) protocol.Result {
fmt.Println("AuthFilter OnResponse is called")
myAttachmentMap := make(map[string]interface{})
myAttachmentMap["key1"] = "value1"
myAttachmentMap["key2"] = []string{"value1", "value2"}
result.SetAttachments(myAttachmentMap)
fmt.Printf("result %v--", result)
return result
}