Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmbedContext

func EmbedContext(ctx context.Context) (context.Context, error)

func ExtractTransit

func ExtractTransit(ctx context.Context) (context.Context, error)

ExtractTransit extracts transit from ctx or creates a new one

func MustDialOption

func MustDialOption(opt grpc.DialOption, err error) grpc.DialOption

MustDialOption panics if it receives an error

func WithMutualTLS

func WithMutualTLS(
	serverName, certFile, keyFile, caFile string,
) (grpc.DialOption, error)

WithMutualTLS returns a dial option for the GRPC client that activates a mutual TLS authentication between the server and the client.

func WithTLS

func WithTLS(
	certFile, serverNameOverride string,
) (grpc.DialOption, error)

WithTLS returns a dial option for the GRPC client that activates TLS. This must be used when the server has TLS activated.

func WrapResolver

func WrapResolver(r spine.Resolver) grpc.Resolver

WrapResolver wraps a spine resolver with a gRPC resolver

Types

type Client

type Client struct {

	// HTTP is the standard net/http client
	GRPC *grpc.ClientConn
	// PropagateContext tells whether the context should be propagated upstream
	//
	// This should be activated when the upstream endpoint is a SPINE service
	// or another SPINE-compatible service. The context can potentially leak
	// sensitive information, so do not activate it for services that you
	// don't trust.
	PropagateContext bool
	// contains filtered or unexported fields
}

Client is a wrapper for the grpc client.

func NewClient

func NewClient(
	ctx context.Context, target string, opts ...grpc.DialOption,
) (*Client, error)

func (*Client) AppendStreamMiddleware

func (c *Client) AppendStreamMiddleware(m StreamClientMiddleware)

func (*Client) AppendUnaryMiddleware

func (c *Client) AppendUnaryMiddleware(m UnaryClientMiddleware)

func (*Client) Close

func (c *Client) Close() error

func (*Client) WaitForStateReady

func (c *Client) WaitForStateReady(ctx context.Context) error

WaitForStateReady waits until the connection is ready or the context times out

type Info

type Info struct {
	// FullMethod is the full RPC method string, i.e., /package.service/method.
	FullMethod string
	// StartTime is the time on which the request hast started
	StartTime time.Time
}

Info contains information about a request

type Server

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

A Server defines parameters for running a spine compatible GRPC server

func NewServer

func NewServer() *Server

NewServer creates a new GRPC server

func (*Server) ActivateMutualTLS

func (s *Server) ActivateMutualTLS(certFile, keyFile, caFile string)

ActivateMutualTLS activates TLS on this handler. That means only incoming TLS connections are allowed and clients must authenticate themselves to the server.

If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

func (*Server) ActivateTLS

func (s *Server) ActivateTLS(certFile, keyFile string)

ActivateTLS activates TLS on this handler. That means only incoming TLS connections are allowed.

If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

Clients are not authenticated.

func (*Server) AppendStreamMiddleware

func (s *Server) AppendStreamMiddleware(m StreamServerMiddleware)

AppendStreamMiddleware appends a stream middleware to the call chain

func (*Server) AppendUnaryMiddleware

func (s *Server) AppendUnaryMiddleware(m UnaryServerMiddleware)

AppendUnaryMiddleware appends an unary middleware to the call chain

func (*Server) Drain

func (s *Server) Drain()

Drain puts the handler into drain mode.

func (*Server) Handle

func (s *Server) Handle(f func(*grpc.Server))

Handle just injects the GRPC server to register a service. The function is called back only when Serve is called. This must be called before invoking Serve.

func (*Server) RegisterService

func (s *Server) RegisterService(sd *grpc.ServiceDesc, ss interface{})

RegisterService register a service and its implementation to the gRPC server. Called from the IDL generated code.

The function is called back only when Serve is called. This must be called before invoking Serve.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, addr string) error

Serve starts serving HTTP requests (blocking call)

func (*Server) SetOptions

func (s *Server) SetOptions(opts ...grpc.ServerOption)

SetOptions changes the handler options

type StreamClientMiddleware

type StreamClientMiddleware func(grpc.Streamer) grpc.Streamer

func OpenTracingStreamClientMiddleware

func OpenTracingStreamClientMiddleware(spanOpts ...opentracing.StartSpanOption) StreamClientMiddleware

OpenTracingStreamClientMiddleware returns a StreamClientMiddleware that injects a child span into the gRPC metadata if a span is found within the given context.

type StreamHandler

type StreamHandler func(srv interface{}, info *Info, ss grpc.ServerStream) error

type StreamServerMiddleware

type StreamServerMiddleware func(next StreamHandler) StreamHandler

type UnaryClientMiddleware

type UnaryClientMiddleware func(grpc.UnaryInvoker) grpc.UnaryInvoker

func OpenTracingUnaryClientMiddleware

func OpenTracingUnaryClientMiddleware(spanOpts ...opentracing.StartSpanOption) UnaryClientMiddleware

OpenTracingUnaryClientMiddleware returns a UnaryClientMiddleware that injects a child span into the gRPC metadata if a span is found within the given context.

type UnaryHandler

type UnaryHandler func(ctx context.Context, info *Info, req interface{}) (interface{}, error)

type UnaryServerMiddleware

type UnaryServerMiddleware func(next UnaryHandler) UnaryHandler