grpc

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const Module = "transport.grpc"

Variables

This section is empty.

Functions

func DefaultClientMiddlewares

func DefaultClientMiddlewares() []middleware.Middleware

DefaultClientMiddlewares provides a default set of client-side middlewares for gRPC services.

func DefaultServerMiddlewares

func DefaultServerMiddlewares() []middleware.Middleware

DefaultServerMiddlewares provides a default set of server-side middlewares for gRPC services. These are essential for ensuring basic stability and observability.

func NewClient added in v0.2.7

func NewClient(ctx context.Context, grpcConfig *grpcv1.Client, clientOpts *ClientOptions) (*grpc.ClientConn, error)

NewClient creates a new concrete gRPC client connection based on the provided configuration. It returns *transgrpc.ClientConn.

func NewServer added in v0.2.7

func NewServer(grpcConfig *grpcv1.Server, serverOpts *ServerOptions) (*transgrpc.Server, error)

NewServer creates a new concrete gRPC server instance based on the provided configuration. It returns *transgrpc.Server, not the generic interfaces.Server.

func WithClientMiddlewares added in v0.2.13

func WithClientMiddlewares(mws map[string]middleware.Middleware) options.Option

WithClientMiddlewares adds a map of named client middlewares to the options.

func WithContext added in v0.2.13

func WithContext(ctx context.Context) options.Option

WithContext sets the context.Context for the service.

func WithContextRegistry added in v0.2.13

func WithContextRegistry(ctx context.Context, registrar transport.GRPCRegistrar) options.Option

WithContextRegistry sets both the context.Context and ServerRegistrar for the service.

func WithDialOptions added in v0.2.13

func WithDialOptions(opts ...grpcx.DialOption) options.Option

WithDialOptions appends native gRPC client dial options.

func WithDiscoveries added in v0.2.13

func WithDiscoveries(discoveries map[string]registry.Discovery) options.Option

WithDiscoveries adds a map of named service discovery clients to the options.

func WithRegistrar added in v0.2.13

func WithRegistrar(registrar transport.GRPCRegistrar) options.Option

WithRegistrar sets the gRPC registrar to use for service registration.

func WithServerMiddlewares added in v0.2.13

func WithServerMiddlewares(mws map[string]middleware.Middleware) options.Option

WithServerMiddlewares adds a map of named server middlewares to the options.

func WithServerOptions added in v0.2.13

func WithServerOptions(opts ...kgprc.ServerOption) options.Option

WithServerOptions appends Kratos gRPC server options.

Types

type ClientOptions

type ClientOptions struct {
	// DialOptions allows passing native gRPC client dial options.
	DialOptions []grpcx.DialOption

	// ClientMiddlewares holds a map of named client middlewares.
	ClientMiddlewares map[string]middleware.Middleware

	// Discoveries holds a map of named service discovery clients.
	Discoveries map[string]registry.Discovery
}

ClientOptions is a container for gRPC client-specific options.

func FromClientOptions

func FromClientOptions(opts []options.Option) *ClientOptions

FromClientOptions creates a new gRPC ClientOptions struct by applying a slice of functional options. It also initializes and includes the common service-level options, ensuring they are applied only once.

type ServerOptions

type ServerOptions struct {
	// ServerOptions allows passing native Kratos gRPC server options.
	ServerOptions []kgprc.ServerOption

	Context   context.Context
	Registrar transport.GRPCRegistrar

	// ServerMiddlewares holds a map of named server middlewares.
	ServerMiddlewares map[string]middleware.Middleware
}

ServerOptions is a container for gRPC server-specific options.

func FromServerOptions

func FromServerOptions(opts []options.Option) *ServerOptions

FromServerOptions creates a new gRPC ServerOptions struct by applying a slice of functional options. It also initializes and includes the common service-level options, ensuring they are applied only once.

Jump to

Keyboard shortcuts

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