Documentation
¶
Index ¶
- Constants
- func DefaultSkipper(context.Context, *Request) bool
- func FromContext[T any](ctx context.Context) (T, bool)
- func IsExtractTokenErr(err error) bool
- func IsParseTokenErr(err error) bool
- func NewAuthInterceptor(opts ...authInterceptorOpt) (*authInterceptor, error)
- func NewAuthMiddleware(opts ...authMiddlewareOpt) (*authMiddleware, error)
- func NewContext(ctx context.Context, payload any) context.Context
- func WithClientHandler(h ClientTokenGetter) authInterceptorOpt
- func WithErrorWriterOpts(opts ...connect.HandlerOption) authMiddlewareOpt
- func WithHandler(h AuthHandler) authMiddlewareOpt
- func WithServiceHandler(h AuthHandler) authInterceptorOpt
- func WithStreamServiceHandler(h AuthHandler) authInterceptorOpt
- func WithUnaryServiceHandler(h AuthHandler) authInterceptorOpt
- type AuthHandler
- type ClientTokenGetter
- type Middleware
- type Request
- type ServiceHandlerType
Constants ¶
const (
UnaryAndStreamHandler = UnaryHandler | StreamHandler
)
Variables ¶
This section is empty.
Functions ¶
func DefaultSkipper ¶
DefaultSkipper returns false which processes the middleware.
func FromContext ¶
FromContext is used to get the payload from context, T is the returned type from parser
func IsExtractTokenErr ¶
IsExtractTokenErr checks if err is from Extractor
func IsParseTokenErr ¶
IsParseTokenErr checks if err is from Parser It can be used in ErrorHandle to determine where to err come from
func NewAuthInterceptor ¶
func NewAuthInterceptor(opts ...authInterceptorOpt) (*authInterceptor, error)
func NewAuthMiddleware ¶ added in v0.2.0
func NewAuthMiddleware(opts ...authMiddlewareOpt) (*authMiddleware, error)
func WithClientHandler ¶ added in v0.6.1
func WithClientHandler(h ClientTokenGetter) authInterceptorOpt
func WithErrorWriterOpts ¶ added in v0.2.1
func WithErrorWriterOpts(opts ...connect.HandlerOption) authMiddlewareOpt
func WithHandler ¶ added in v0.6.1
func WithHandler(h AuthHandler) authMiddlewareOpt
func WithServiceHandler ¶ added in v0.6.1
func WithServiceHandler(h AuthHandler) authInterceptorOpt
func WithStreamServiceHandler ¶ added in v0.6.1
func WithStreamServiceHandler(h AuthHandler) authInterceptorOpt
func WithUnaryServiceHandler ¶ added in v0.6.1
func WithUnaryServiceHandler(h AuthHandler) authInterceptorOpt
Types ¶
type AuthHandler ¶
type AuthHandler interface {
//Skip defines a function to skip the middleware
Skip(ctx context.Context, req *Request) bool
// Before defines a function which is executed before Extracor and Parser
// If this function return an error, the middleware will return the error and skip the rest of the process
// HandleError will be ignored if Before return an error
Before(ctx context.Context, req *Request) error
// Extract defines a function which is used to extract data from request, and may return a new context to be used in parse
Extract(ctx context.Context, req *Request) (context.Context, error)
// Parse is used to parse data from context
Parse(ctx context.Context) (any, error)
// Success defines a function which is executed after Extracor and Parser when they return no error.
// This function accepts the modified context, and the request.
// If this function return an error, the middleware will return with the error and skip error handler.
Success(ctx context.Context, req *Request) error
// HandleError defines a function which is executed when Extractor or Parser return error.
HandleError(ctx context.Context, req *Request, err error) error
}
AuthHandler is used in unary and streaming service handler The order of execution of handler's functions are: Skip(if this function return true, skip the rest process) -> Before(if this function return err, skip the rest process) -> Extract(if this function return err, jump to HandleError) -> Parse (if this function return err, jump to HandleError) -> Success(if this function return err, the error is returned) -> HandleError
type ClientTokenGetter ¶
ClientTokenGetter is used to get token for client request
type Request ¶ added in v0.2.0
type Request struct {
Procedure string // for example, "/acme.foo.v1.FooService/Bar"
ClientAddr string // client address, in IP:port format
Protocol string // connect.ProtocolConnect, connect.ProtocolGRPC, or connect.ProtocolGRPCWeb
Header http.Header
}
Request describes a single RPC invocation.
type ServiceHandlerType ¶ added in v0.2.0
type ServiceHandlerType int
const ( UnaryHandler ServiceHandlerType = 1 << iota StreamHandler )
Directories
¶
| Path | Synopsis |
|---|---|
|
gen/ping/v1/pingv1connect
The connect.ping.v1 package contains an echo service designed to test the connect-go implementation.
|
The connect.ping.v1 package contains an echo service designed to test the connect-go implementation. |