grpc

package
v0.0.0-...-543d84f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthStub = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowStub   = fmt.Errorf("proto: integer overflow")
)

Functions

func CtxWithIncomingToken

func CtxWithIncomingToken(ctx context.Context, token string) context.Context

CtxWithIncomingToken stores token to ctx of reponse.

func CtxWithIncomingUserID

func CtxWithIncomingUserID(ctx context.Context, userID string) context.Context

CtxWithIncomingUserID stores userID to ctx of reponse.

func CtxWithToken

func CtxWithToken(ctx context.Context, token string) context.Context

CtxWithToken stores token to ctx of request.

func CtxWithUserID

func CtxWithUserID(ctx context.Context, userID string) context.Context

CtxWithUserID stores userID to ctx of request.

func ForwardErrorf

func ForwardErrorf(code codes.Code, formatter string, args ...interface{}) error

ForwardErrorf tries to unwrap args as error with GRPCStatus() and forward original code and details.

func ForwardFromError

func ForwardFromError(code codes.Code, err error) error

ForwardFromError tries to unwrap err as GRPCStatus() and forward original code and details.

func NewClientConn

func NewClientConn(host string, tls security.TLSConfig, opt ...grpc.DialOption) (*grpc.ClientConn, error)

NewClientConn creates gRPC client connection

func NewOAuthAccess

func NewOAuthAccess(getTokenFunc OAuthGetTokenFunc) credentials.PerRPCCredentials

NewOAuthAccess constructs the PerRPCCredentials using a given token.

func RegisterStubServiceServer

func RegisterStubServiceServer(s *grpc.Server, srv StubServiceServer)

func StreamServerInterceptor

func StreamServerInterceptor(intercept Interceptor) grpc.ServerOption

func TokenFromMD

func TokenFromMD(ctx context.Context) (string, error)

TokenFromMD is a helper function for extracting the :authorization header from the gRPC metadata of the request.

func TokenFromOutgoingMD

func TokenFromOutgoingMD(ctx context.Context) (string, error)

TokenFromOutgoingMD extracts token stored by CtxWithToken.

func UnaryServerInterceptor

func UnaryServerInterceptor(intercept Interceptor) grpc.ServerOption

func UserIDFromMD

func UserIDFromMD(ctx context.Context) (string, error)

UserIDFromMD is a helper function for extracting the :userid header from the gRPC metadata of the request.

func UserIDFromOutgoingMD

func UserIDFromOutgoingMD(ctx context.Context) (string, error)

UserIDFromOutgoingMD extracts userID stored by CtxWithUserID.

func UserIDFromTokenMD

func UserIDFromTokenMD(ctx context.Context) (string, error)

UserIDFromTokenMD is a helper function for extracting the userID from the :authorization gRPC metadata of the request.

Types

type AuthInterceptors

type AuthInterceptors struct {
	// contains filtered or unexported fields
}

func MakeAuthInterceptors

func MakeAuthInterceptors(authFunc Interceptor, whiteListedMethods ...string) AuthInterceptors

func MakeJWTInterceptors

func MakeJWTInterceptors(jwksURL string, tls *tls.Config, claims ClaimsFunc, whiteListedMethods ...string) AuthInterceptors

func (AuthInterceptors) Stream

func (f AuthInterceptors) Stream() grpc.ServerOption

func (AuthInterceptors) Unary

type Claims

type Claims = interface{ Valid() error }

type ClaimsFunc

type ClaimsFunc = func(ctx context.Context, method string) Claims

type Config

type Config struct {
	Addr string `envconfig:"ADDRESS" env:"ADDRESS" long:"address" default:"0.0.0.0:9100"`
}

Config holds service's settings.

type Interceptor

type Interceptor = func(ctx context.Context, method string) (context.Context, error)

func ValidateJWT

func ValidateJWT(jwksURL string, tls *tls.Config, claims ClaimsFunc) Interceptor

type Iterator

type Iterator struct {
	Err error
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator(stream grpc.ClientStream, err error) *Iterator

func (*Iterator) Close

func (it *Iterator) Close()

func (*Iterator) Next

func (it *Iterator) Next(v interface{}) bool

type OAuthGetTokenFunc

type OAuthGetTokenFunc = func(ctx context.Context) (*oauth2.Token, error)

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

Server handles gRPC requests to the service.

func NewServer

func NewServer(addr string, opts ...grpc.ServerOption) (*Server, error)

NewServer instantiates a gRPC server. When passing addr with an unspecified port or ":", use Addr().

func StubGrpcServer

func StubGrpcServer(opts ...grpc.ServerOption) *Server

func (*Server) AddCloseFunc

func (s *Server) AddCloseFunc(f func())

AddCloseFunc adds a function to be called by the Close method. This eliminates the need for wrapping the Server.

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) Close

func (s *Server) Close()

Close stops the gRPC server. It immediately closes all open connections and listeners. It cancels all active RPCs on the server side and the corresponding pending RPCs on the client side will get notified by connection errors.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts serving and blocks.

type StubServiceClient

type StubServiceClient interface {
	TestCall(ctx context.Context, in *TestRequest, opts ...grpc.CallOption) (*TestResponse, error)
	TestStream(ctx context.Context, opts ...grpc.CallOption) (StubService_TestStreamClient, error)
}

StubServiceClient is the client API for StubService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewStubServiceClient

func NewStubServiceClient(cc *grpc.ClientConn) StubServiceClient

func StubGrpcClient

func StubGrpcClient(addr string) StubServiceClient

type StubServiceServer

type StubServiceServer interface {
	TestCall(context.Context, *TestRequest) (*TestResponse, error)
	TestStream(StubService_TestStreamServer) error
}

StubServiceServer is the server API for StubService service.

type StubService_TestStreamClient

type StubService_TestStreamClient interface {
	Send(*TestRequest) error
	Recv() (*TestResponse, error)
	grpc.ClientStream
}

type StubService_TestStreamServer

type StubService_TestStreamServer interface {
	Send(*TestResponse) error
	Recv() (*TestRequest, error)
	grpc.ServerStream
}

type TestRequest

type TestRequest struct {
	Test string `protobuf:"bytes,1,opt,name=test,proto3" json:"test,omitempty"`
}

func (*TestRequest) Descriptor

func (*TestRequest) Descriptor() ([]byte, []int)

func (*TestRequest) GetTest

func (m *TestRequest) GetTest() string

func (*TestRequest) Marshal

func (m *TestRequest) Marshal() (dAtA []byte, err error)

func (*TestRequest) MarshalTo

func (m *TestRequest) MarshalTo(dAtA []byte) (int, error)

func (*TestRequest) ProtoMessage

func (*TestRequest) ProtoMessage()

func (*TestRequest) Reset

func (m *TestRequest) Reset()

func (*TestRequest) Size

func (m *TestRequest) Size() (n int)

func (*TestRequest) String

func (m *TestRequest) String() string

func (*TestRequest) Unmarshal

func (m *TestRequest) Unmarshal(dAtA []byte) error

func (*TestRequest) XXX_DiscardUnknown

func (m *TestRequest) XXX_DiscardUnknown()

func (*TestRequest) XXX_Marshal

func (m *TestRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TestRequest) XXX_Merge

func (m *TestRequest) XXX_Merge(src proto.Message)

func (*TestRequest) XXX_Size

func (m *TestRequest) XXX_Size() int

func (*TestRequest) XXX_Unmarshal

func (m *TestRequest) XXX_Unmarshal(b []byte) error

type TestResponse

type TestResponse struct {
	Test string `protobuf:"bytes,1,opt,name=test,proto3" json:"test,omitempty"`
}

func (*TestResponse) Descriptor

func (*TestResponse) Descriptor() ([]byte, []int)

func (*TestResponse) GetTest

func (m *TestResponse) GetTest() string

func (*TestResponse) Marshal

func (m *TestResponse) Marshal() (dAtA []byte, err error)

func (*TestResponse) MarshalTo

func (m *TestResponse) MarshalTo(dAtA []byte) (int, error)

func (*TestResponse) ProtoMessage

func (*TestResponse) ProtoMessage()

func (*TestResponse) Reset

func (m *TestResponse) Reset()

func (*TestResponse) Size

func (m *TestResponse) Size() (n int)

func (*TestResponse) String

func (m *TestResponse) String() string

func (*TestResponse) Unmarshal

func (m *TestResponse) Unmarshal(dAtA []byte) error

func (*TestResponse) XXX_DiscardUnknown

func (m *TestResponse) XXX_DiscardUnknown()

func (*TestResponse) XXX_Marshal

func (m *TestResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TestResponse) XXX_Merge

func (m *TestResponse) XXX_Merge(src proto.Message)

func (*TestResponse) XXX_Size

func (m *TestResponse) XXX_Size() int

func (*TestResponse) XXX_Unmarshal

func (m *TestResponse) XXX_Unmarshal(b []byte) error

type UnimplementedStubServiceServer

type UnimplementedStubServiceServer struct {
}

UnimplementedStubServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedStubServiceServer) TestCall

func (*UnimplementedStubServiceServer) TestStream

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL