grpc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientPool

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

ClientPool manages gRPC client connections

func NewClientPool

func NewClientPool() *ClientPool

NewClientPool creates a new client pool

func (*ClientPool) CheckHealth

func (p *ClientPool) CheckHealth(ctx context.Context, serviceName string) error

CheckHealth checks service health

func (*ClientPool) Close

func (p *ClientPool) Close()

Close closes all connections

func (*ClientPool) GetConnection

func (p *ClientPool) GetConnection(ctx context.Context, serviceName, address string) (*grpc.ClientConn, error)

GetConnection gets or creates a connection to the service

type MethodBuilder

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

MethodBuilder helps build service method definitions

func NewMethodBuilder

func NewMethodBuilder(serviceName, methodName string) *MethodBuilder

NewMethodBuilder creates a new service method builder

func (*MethodBuilder) Build

func (b *MethodBuilder) Build() *ServiceMethod

Build creates the service method definition

func (*MethodBuilder) WithHandler

func (b *MethodBuilder) WithHandler(handler func(ctx context.Context, req any) (any, error)) *MethodBuilder

WithHandler sets the method handler

type Server

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

Server wraps gRPC server

func NewServer

func NewServer(address string, opts ...grpc.ServerOption) (*Server, error)

NewServer creates a new gRPC server

func (*Server) GetAddress

func (s *Server) GetAddress() string

GetAddress returns server address

func (*Server) RegisterService

func (s *Server) RegisterService(name string, service any, registrar func(*grpc.Server, any))

RegisterService registers a gRPC service

func (*Server) Start

func (s *Server) Start() error

Start starts the gRPC server

func (*Server) Stop

func (s *Server) Stop(timeout time.Duration) error

Stop gracefully stops the server

type ServiceInfo

type ServiceInfo struct {
	Name    string
	Address string
	Port    int
	Tags    []string
	Meta    map[string]string
}

ServiceInfo contains gRPC service information

type ServiceMethod

type ServiceMethod struct {
	Name        string
	ServiceName string
	Handler     func(ctx context.Context, req any) (any, error)
}

ServiceMethod represents a simple service method definition

type ServiceRegistry

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

ServiceRegistry handles gRPC service registration and discovery

func NewServiceRegistry

func NewServiceRegistry(consulAddr string) (*ServiceRegistry, error)

NewServiceRegistry creates a new service registry

func (*ServiceRegistry) Close

func (r *ServiceRegistry) Close()

Close closes the registry and all connections

func (*ServiceRegistry) DiscoverService

func (r *ServiceRegistry) DiscoverService(ctx context.Context, serviceName string) (string, error)

DiscoverService discovers a service and returns its address

func (*ServiceRegistry) GetConnection

func (r *ServiceRegistry) GetConnection(ctx context.Context, serviceName string) (*grpc.ClientConn, error)

GetConnection gets a gRPC connection to a service

func (*ServiceRegistry) RegisterService

func (r *ServiceRegistry) RegisterService(ctx context.Context, info *ServiceInfo) error

RegisterService registers a gRPC service

type SimpleServiceRegistry

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

SimpleServiceRegistry manages simple service methods

func NewSimpleServiceRegistry

func NewSimpleServiceRegistry() *SimpleServiceRegistry

NewSimpleServiceRegistry creates a new simple service registry

func (*SimpleServiceRegistry) GetMethod

func (r *SimpleServiceRegistry) GetMethod(serviceName, methodName string) (*ServiceMethod, bool)

GetMethod gets a service method

func (*SimpleServiceRegistry) ListMethods

func (r *SimpleServiceRegistry) ListMethods(serviceName string) []*ServiceMethod

ListMethods lists all methods for a service

func (*SimpleServiceRegistry) ListServices

func (r *SimpleServiceRegistry) ListServices() []string

ListServices lists all registered services

func (*SimpleServiceRegistry) RegisterMethod

func (r *SimpleServiceRegistry) RegisterMethod(method *ServiceMethod)

RegisterMethod registers a service method

Jump to

Keyboard shortcuts

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