tinygrpc

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 18 Imported by: 0

README

tinygrpc

A collection of tiny tools for gRPC server development in Go.

For more advanced features, go-grpc-middleware could be a better option.

Depends on

  • grpc
  • logrus

Installation

go get -u github.com/unsafe9/tinygrpc

Documentation

Index

Constants

View Source
const (
	CallTypeUnary = CallType(iota)
	CallTypeClientStream
	CallTypeServerStream
	CallTypeBidiStream
)

Variables

This section is empty.

Functions

func ExtractAuthMetadata added in v0.0.6

func ExtractAuthMetadata(ctx context.Context, mdKey, schema string) (string, error)

func GracefulStop

func GracefulStop(grpcServer *grpc.Server, hook func(os.Signal)) chan struct{}

func LogrusKeySortingFunc

func LogrusKeySortingFunc(keys []string)

func StreamServerAuthHandler added in v0.0.2

func StreamServerAuthHandler(authProvider AuthProvider) grpc.StreamServerInterceptor

func StreamServerContextInjector added in v0.0.2

func StreamServerContextInjector(injector ContextInjector) grpc.StreamServerInterceptor

func StreamServerErrorDeterminer added in v0.0.3

func StreamServerErrorDeterminer(determiner ErrorDeterminer) grpc.StreamServerInterceptor

func StreamServerLogger added in v0.0.2

func StreamServerLogger(logger *logrus.Logger, determiner LogLevelDeterminer, payloadLevel logrus.Level) grpc.StreamServerInterceptor

func StreamServerRecoveryHandler added in v0.0.2

func StreamServerRecoveryHandler(recoveryHandler RecoveryHandler) grpc.StreamServerInterceptor

func StreamServerSelector added in v0.0.2

func StreamServerSelector(interceptor grpc.StreamServerInterceptor, matcher SelectorMatcher) grpc.StreamServerInterceptor

func UnaryServerAuthHandler added in v0.0.2

func UnaryServerAuthHandler(authProvider AuthProvider) grpc.UnaryServerInterceptor

func UnaryServerContextInjector added in v0.0.2

func UnaryServerContextInjector(injector ContextInjector) grpc.UnaryServerInterceptor

func UnaryServerErrorDeterminer added in v0.0.3

func UnaryServerErrorDeterminer(determiner ErrorDeterminer) grpc.UnaryServerInterceptor

func UnaryServerLogger added in v0.0.2

func UnaryServerLogger(logger *logrus.Logger, determiner LogLevelDeterminer) grpc.UnaryServerInterceptor

func UnaryServerRecoveryHandler added in v0.0.2

func UnaryServerRecoveryHandler(recoveryHandler RecoveryHandler) grpc.UnaryServerInterceptor

func UnaryServerSelector added in v0.0.2

func UnaryServerSelector(interceptor grpc.UnaryServerInterceptor, matcher SelectorMatcher) grpc.UnaryServerInterceptor

Types

type AuthProvider added in v0.0.5

type AuthProvider interface {
	VerifyAuth(c *CallContext) (context.Context, error)
}

type AuthProviderFunc added in v0.0.7

type AuthProviderFunc func(c *CallContext) (context.Context, error)

func (AuthProviderFunc) VerifyAuth added in v0.0.7

func (f AuthProviderFunc) VerifyAuth(c *CallContext) (context.Context, error)

type CallContext added in v0.0.2

type CallContext struct {
	Server     any
	FullMethod string
	CallType   CallType
	// contains filtered or unexported fields
}

func (*CallContext) Context added in v0.0.7

func (c *CallContext) Context() context.Context

type CallType added in v0.0.2

type CallType int

type ContextInjector

type ContextInjector func(c *CallContext) context.Context

type ErrorDeterminer added in v0.0.2

type ErrorDeterminer func(c *CallContext, err error) error

type LogLevelDeterminer added in v0.0.2

type LogLevelDeterminer func(c *CallContext, err error) logrus.Level

type MultiAuthProvider added in v0.0.7

type MultiAuthProvider struct {
	// Providers is a list of auth providers to be chained
	Providers []AuthProvider

	// AllowUnauthenticated allows the process to pass without authentication
	//  if all providers fail.
	AllowUnauthenticated bool

	// EvaluateAll ensures that all providers in the chain are evaluated,
	//  injecting combined contexts from all successful providers, even if one succeeds early.
	EvaluateAll bool

	// RequireAll requires all providers to succeed, otherwise it will return an error.
	RequireAll bool
}

func (*MultiAuthProvider) VerifyAuth added in v0.0.7

func (p *MultiAuthProvider) VerifyAuth(c *CallContext) (context.Context, error)

type PanicWrapper

type PanicWrapper struct {
	Panic any
	Stack []byte
}

func (PanicWrapper) Error

func (p PanicWrapper) Error() string

type RecoveryHandler added in v0.0.2

type RecoveryHandler func(c *CallContext, p *PanicWrapper) error

type SelectorMatcher added in v0.0.2

type SelectorMatcher func(c *CallContext) bool

Jump to

Keyboard shortcuts

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