grpctools

package module
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

README

grpctools

Build Status GoDoc License

Little helpers for grpc

Testing

Simply run:

make

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultInstrumenter = NewInstrumenter("rpc.request")

DefaultInstrumenter instruments via "rpc.request" metric

Functions

func Dial

func Dial(target string, opts *DialOptions, extra ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a client connection.

func DialContext

func DialContext(ctx context.Context, target string, opts *DialOptions, extra ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext creates a client connection with specified context.

func HTTPStatus added in v0.3.0

func HTTPStatus(c codes.Code) int

HTTPStatus returns a http stats from a grpc error code

func HTTPStatusFromError added in v0.3.0

func HTTPStatusFromError(err error) int

HTTPStatusFromError returns a http stats from a grpc error code

func SetLogger

func SetLogger(logger grpclog.LoggerV2)

SetLogger is a proxy to grpclog.SetLogger

Types

type DialOptions

type DialOptions struct {
	// Enables transport security.
	SkipInsecure bool

	// Makes Dial non-blocking (Dial won't wait for connection to be up before returning).
	SkipBlock bool

	// Unary client interceptors.
	UnaryInterceptors []grpc.UnaryClientInterceptor

	// Stream client interceptors.
	StreamInterceptors []grpc.StreamClientInterceptor
}

DialOptions represent dial options.

type Instrumenter

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

Instrumenter instances instrument RPC requests via interceptors.

func NewInstrumenter

func NewInstrumenter(metric string) *Instrumenter

NewInstrumenter inits a new instrumenter with a metric

func (*Instrumenter) StreamServerInterceptor

func (i *Instrumenter) StreamServerInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

StreamServerInterceptor implements an grpc.StreamServerInterceptor

func (*Instrumenter) UnaryServerInterceptor

func (i *Instrumenter) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

UnaryServerInterceptor implements an grpc.UnaryServerInterceptor

type Options

type Options struct {
	MaxConcurrentStreams uint32
	SkipInstrumentation  bool

	UnaryInterceptors  []grpc.UnaryServerInterceptor
	StreamInterceptors []grpc.StreamServerInterceptor
}

Options represent server options

type Server

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

Server embeds a standard grpc Server with a healthcheck

func NewServer

func NewServer(name string, addr string, opts *Options, extra ...grpc.ServerOption) *Server

NewServer returns a new Server instance.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the server (blocking).

type VErrors added in v0.5.0

VErrors contains a set of field-violations.

func VErrorsConvert added in v0.5.0

func VErrorsConvert(err error) VErrors

VErrorsConvert extracts validation errors from an error. This function will return nil if no validation errors are attached.

func VErrorsFromStatus added in v0.5.0

func VErrorsFromStatus(sts *status.Status) VErrors

VErrorsFromStatus extracts validation errors from status.

func (VErrors) Append added in v0.5.0

func (e VErrors) Append(field, message string) VErrors

Append appends a field message.

func (VErrors) InvalidArgument added in v0.5.0

func (e VErrors) InvalidArgument(message string) *status.Status

InvalidArgument returns an InvalidArgument status.

func (VErrors) Len added in v0.5.0

func (e VErrors) Len() int

Len returns the error count.

func (VErrors) Messages added in v0.5.0

func (e VErrors) Messages() []string

Messages returns messages.

func (VErrors) Reset added in v0.5.0

func (e VErrors) Reset() VErrors

Reset resets the slice.

func (VErrors) Status added in v0.5.0

func (e VErrors) Status(code codes.Code, message string) *status.Status

Status returns a custom status.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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