Documentation
¶
Index ¶
- func AppFromContext(ctx context.Context) (string, string)
- func LoginFromContext(ctx context.Context) (string, string)
- func StreamServerInterceptor(authorize Authorize) grpc.StreamServerInterceptor
- func TokenFromContext(ctx context.Context) string
- func UnaryServerInterceptor(authorize Authorize) grpc.UnaryServerInterceptor
- type AppCredential
- type Authorize
- type Authorizer
- type LoginCredential
- type Metadata
- func (m Metadata) Add(key string, value string) Metadata
- func (m Metadata) AsMD() *metadata.MD
- func (m Metadata) Del(key string) Metadata
- func (m Metadata) FirstValue(key string, defalutValue string) string
- func (m Metadata) LastValue(key string, defalutValue string) string
- func (m Metadata) Set(key string, value string) Metadata
- func (m Metadata) ToIncoming(ctx context.Context) context.Context
- func (m Metadata) ToOutgoing(ctx context.Context) context.Context
- func (m Metadata) Values(key string) []string
- type ServerStream
- type TokenCredential
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppFromContext ¶
AppFromContext get app from context
func LoginFromContext ¶
LoginFromContext get login from context
func StreamServerInterceptor ¶
func StreamServerInterceptor(authorize Authorize) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new unary server interceptors that performs per-request auth.
func TokenFromContext ¶
TokenFromContext get token from context
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(authorize Authorize) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that performs per-request auth.
Types ¶
type AppCredential ¶
AppCredential authorize via appkey and appsecret
func (AppCredential) GetRequestMetadata ¶
GetRequestMetadata build app metadata
func (AppCredential) RequireTransportSecurity ¶
func (c AppCredential) RequireTransportSecurity() bool
RequireTransportSecurity indicates whether the credentials requires transport security.
type Authorizer ¶
type Authorizer interface {
Authorize(ctx context.Context, fullMethodName string) (context.Context, error)
}
Authorizer allows a given gRPC service implementation to override the global `Authorize`.
If a service implements the AuthorizeOverride method, it takes precedence over the `Authorize` method, and will be called instead of Authorize for all method invocations within that service.
type LoginCredential ¶
LoginCredential authorize via login and password
func (*LoginCredential) GetRequestMetadata ¶
GetRequestMetadata build login metadata
func (*LoginCredential) RequireTransportSecurity ¶
func (c *LoginCredential) RequireTransportSecurity() bool
RequireTransportSecurity indicates whether the credentials requires transport security.
type Metadata ¶
Metadata is a convenience wrapper definiting extra functions on the metadata.
func FromIncoming ¶
FromIncoming extracts an inbound metadata from the server-side context.
This function always returns a Metadata wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty Metadata.
func FromOutgoing ¶
FromOutgoing extracts an outbound metadata from the client-side context.
This function always returns a Metadata wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty Metadata.
func (Metadata) Add ¶
Add retrieves a single value from the metadata.
It works analogously to http.Header.Add, as it appends to any existing values associated with key.
func (Metadata) Del ¶
Del retrieves a single value from the metadata.
It works analogously to http.Header.Del, deleting all values if they exist.
func (Metadata) FirstValue ¶
FirstValue retrieves a single value from the metadata.
It works analogously to http.Header.Get, returning the first value if there are many set. If the value is not set, an empty string is returned.
func (Metadata) Set ¶
Set sets the given value in a metadata.
It works analogously to http.Header.Set, overwriting all previous metadata values.
func (Metadata) ToIncoming ¶
ToIncoming sets the given Metadata as a server-side context for dispatching.
This is mostly useful in ServerInterceptors..
func (Metadata) ToOutgoing ¶
ToOutgoing sets the given Metadata as a client-side context for dispatching.
type ServerStream ¶
type ServerStream struct {
grpc.ServerStream
// WrappedContext is the wrapper's own Context. You can assign it.
WrappedContext context.Context
}
ServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.
func WrapServerStream ¶
func WrapServerStream(stream grpc.ServerStream) *ServerStream
WrapServerStream returns a ServerStream that has the ability to overwrite context.
func (*ServerStream) Context ¶
func (w *ServerStream) Context() context.Context
Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()
type TokenCredential ¶
TokenCredential authorize via token
func (TokenCredential) GetRequestMetadata ¶
func (c TokenCredential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)
GetRequestMetadata build token metadata
func (TokenCredential) RequireTransportSecurity ¶
func (c TokenCredential) RequireTransportSecurity() bool
RequireTransportSecurity indicates whether the credentials requires transport security.