Documentation
¶
Index ¶
- type Client
- type Config
- type Option
- func WithAddress(addr string) Option
- func WithCircuitBreaker(cbCfg *resilience.CircuitBreakerConfig) Option
- func WithLogger(log *logger.Logger) Option
- func WithMetrics(metricsClient metrics.Client) Option
- func WithRetry(retryCfg *resilience.RetryConfig) Option
- func WithServiceName(name string) Option
- func WithTLS(cfg *TLSConfig) Option
- func WithTracing(tracingClient tracing.Client) Option
- type TLSConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a gRPC client with built-in observability, retry logic, and circuit breaker support.
func NewClient ¶
NewClient creates a new gRPC client with observability.
Example:
c, err := client.NewClient(
client.WithAddress("localhost:50051"),
client.WithServiceName("order-service"),
client.WithTracing(tracingClient),
)
func (*Client) Connection ¶
func (c *Client) Connection() *grpc.ClientConn
Connection returns the underlying gRPC connection.
func (*Client) Invoke ¶
func (c *Client) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error
Invoke performs a unary gRPC call with observability and optional retry.
func (*Client) NewStream ¶
func (c *Client) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
NewStream creates a new streaming gRPC call with observability.
type Config ¶
type Config struct {
// Address is the gRPC server address (e.g., "localhost:50051")
Address string
// ServiceName is the name of the service for metrics/tracing.
ServiceName string
// UseTLS enables TLS for the connection.
UseTLS bool
// TLSConfig holds TLS configuration.
TLSConfig *TLSConfig
// Timeout is the default timeout for each request.
Timeout time.Duration
// MaxRetries is the maximum number of retry attempts.
MaxRetries int
// EnableCompression enables gzip compression for gRPC messages.
// Reduces bandwidth usage at low CPU cost.
EnableCompression bool
}
Config holds the configuration for the gRPC client.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default gRPC configuration.
type Option ¶
Option configures the gRPC client. All options are applied during NewClient construction.
Example:
c, err := client.NewClient(
client.WithAddress("localhost:50051"),
client.WithServiceName("order-service"),
client.WithTracing(tracingClient),
client.WithMetrics(metricsClient),
)
func WithCircuitBreaker ¶
func WithCircuitBreaker(cbCfg *resilience.CircuitBreakerConfig) Option
WithCircuitBreaker adds circuit breaker support.
func WithLogger ¶
WithLogger sets a custom logger for the gRPC client.
func WithMetrics ¶
WithMetrics adds metrics support.
func WithRetry ¶
func WithRetry(retryCfg *resilience.RetryConfig) Option
WithRetry adds retry support.
func WithServiceName ¶
WithServiceName sets the service name for metrics.
func WithTracing ¶
WithTracing adds distributed tracing support.
type TLSConfig ¶
type TLSConfig struct {
// CertFile is the path to the client TLS certificate.
CertFile string
// KeyFile is the path to the client TLS key.
KeyFile string
// CAFile is the path to the CA certificate for server verification.
CAFile string
// ServerNameOverride is used to verify server hostname.
ServerNameOverride string
}
TLSConfig holds TLS certificate paths for mutual TLS authentication.