grpc

package
v0.0.0-...-3cc3ff2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 28 Imported by: 0

README

gRPC

Provides gRPC client and server implementations.

endpoint "mock" "grpc" {
    package = "semaphore.greeter"
	service = "Say"
    method = "Hello"
}

Documentation

Index

Constants

View Source
const (
	// ServiceOption represents the service name option key
	ServiceOption = "service"
	// MethodOption represents the method name option key
	MethodOption = "method"
	// PackageOption represents the package name option key
	PackageOption = "package"
)

Variables

This section is empty.

Functions

func CodeFromStatus

func CodeFromStatus(status int) codes.Code

CodeFromStatus converts a response status error code into the corresponding gRPC status.

func Codec

func Codec() grpc.Codec

Codec returns a proxying grpc.Codec with the default protobuf codec as parent.

See CodecWithParent.

func CodecWithParent

func CodecWithParent(fallback grpc.Codec) grpc.Codec

CodecWithParent returns a proxying grpc.Codec with a user provided codec as parent.

This codec is *crucial* to the functioning of the proxy. It allows the proxy server to be oblivious to the schema of the forwarded messages. It basically treats a gRPC message frame as raw bytes. However, if the server handler, or the client caller are not proxy-internal functions it will fall back to trying to decode the message using a fallback codec.

func CopyMD

func CopyMD(source metadata.MD) rpcMeta.MD

CopyMD copies the given semaphore metadata into a grpc metadata

func CopyRPCMD

func CopyRPCMD(source rpcMeta.MD) metadata.MD

CopyRPCMD copies the given grpc metadata into a semaphore metadata

func NewCaller

func NewCaller() transport.NewCaller

NewCaller constructs a new HTTP caller

func NewListener

func NewListener(addr string, opts specs.Options) transport.NewListener

NewListener constructs a new listener for the given addr

func StatusFromCode

func StatusFromCode(code codes.Code) int

StatusFromCode converts a gRPC error code into the corresponding response status.

Types

type Call

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

Call represents the HTTP caller implementation

func (*Call) Address

func (call *Call) Address() string

func (*Call) Close

func (call *Call) Close() error

Close closes the given caller

func (*Call) Director

func (call *Call) Director(ctx context.Context) (*grpc.ClientConn, error)

Director returns a client connection and a outgoing context for the given method

func (*Call) GetMethod

func (call *Call) GetMethod(name string) transport.Method

GetMethod attempts to return a method matching the given name

func (*Call) GetMethods

func (call *Call) GetMethods() []transport.Method

GetMethods returns the available methods within the HTTP caller

func (*Call) SendMsg

func (call *Call) SendMsg(ctx context.Context, rw transport.ResponseWriter, pr *transport.Request, refs references.Store) error

SendMsg calls the configured host and attempts to call the given endpoint with the given headers and stream

type Caller

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

Caller represents the caller constructor

func (*Caller) Dial

func (caller *Caller) Dial(service *specs.Service, functions functions.Custom, opts specs.Options, resolver discovery.Resolver) (transport.Call, error)

Dial constructs a new caller for the given host

func (*Caller) Name

func (caller *Caller) Name() string

Name returns the name of the given caller

type CallerOptions

type CallerOptions struct {
}

CallerOptions represents the available HTTP options

func ParseCallerOptions

func ParseCallerOptions(options specs.Options) (*CallerOptions, error)

ParseCallerOptions parses the given specs options into HTTP options

type EndpointOptions

type EndpointOptions struct {
	Package string
	Service string
	Method  string
}

EndpointOptions represents the available HTTP options

func ParseEndpointOptions

func ParseEndpointOptions(endpoint *transport.Endpoint) (*EndpointOptions, error)

ParseEndpointOptions parses the given specs options into HTTP options

type ErrUnknownMethod

type ErrUnknownMethod struct {
	Method string
}

ErrUnknownMethod occurs when undefined method is called

func (ErrUnknownMethod) Error

func (e ErrUnknownMethod) Error() string

Error returns a description of the given error as a string

func (ErrUnknownMethod) Prettify

func (e ErrUnknownMethod) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type Listener

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

Listener represents a HTTP listener

func (*Listener) Close

func (listener *Listener) Close() error

Close closes the given listener

func (*Listener) Handle

func (listener *Listener) Handle(ctx *broker.Context, endpoints []*transport.Endpoint, codecs map[string]codec.Constructor) error

Handle parses the given endpoints and constructs route handlers

func (*Listener) Name

func (listener *Listener) Name() string

Name returns the name of the given listener

func (*Listener) Serve

func (listener *Listener) Serve() error

Serve opens the HTTP listener and calls the given handler function on reach request

func (*Listener) ServerReflectionInfo

func (listener *Listener) ServerReflectionInfo(stream rpb.ServerReflection_ServerReflectionInfoServer) error

ServerReflectionInfo handles the gRPC reflection v1 alpha implementation.

type ListenerOptions

type ListenerOptions struct {
}

ListenerOptions represents the available HTTP options

func ParseListenerOptions

func ParseListenerOptions(options specs.Options) (*ListenerOptions, error)

ParseListenerOptions parses the given specs options into HTTP options

type Method

type Method struct {
	*transport.Endpoint
	Service *proto.Service
	Name    string
	Flow    transport.Flow
}

Method represents a gRPC endpoint

func (*Method) GetName

func (method *Method) GetName() string

GetName returns the method name

func (*Method) GetRequest

func (method *Method) GetRequest() specs.Message

GetRequest returns the request input parameter map

func (*Method) GetResponse

func (method *Method) GetResponse() specs.Message

GetResponse returns the request output parameter map

func (*Method) References

func (method *Method) References() []*specs.Property

References returns the available method references

func (*Method) String

func (method *Method) String() string

Jump to

Keyboard shortcuts

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