grpcx

package module
v2.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 29 Imported by: 39

Documentation

Overview

Package grpcx provides grpc service functionalities.

Index

Constants

View Source
const (
	FreePortAddress = ":0" // FreePortAddress marks the server listens using random free port.

)

Variables

View Source
var (
	Ctx      = modCtx{}      // Ctx is instance of module Context, which manages the context feature.
	Balancer = modBalancer{} // Balancer is instance of module Balancer, which manages the load balancer features.
	Resolver = modResolver{} // Resolver is instance of module Resolver, which manages the DNS resolving for client.
	Client   = modClient{}   // Client is instance of module Client, which manages the client features.
	Server   = modServer{}   // Server is instance of module Server, which manages the server feature.
)

Functions

This section is empty.

Types

type GrpcServer

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

GrpcServer is the server for GRPC protocol.

func (*GrpcServer) GetConfig added in v2.4.0

func (s *GrpcServer) GetConfig() *GrpcServerConfig

GetConfig returns the configuration of current Server.

func (*GrpcServer) GetListenedAddress

func (s *GrpcServer) GetListenedAddress() string

GetListenedAddress retrieves and returns the address string which are listened by current server.

func (*GrpcServer) GetListenedPort

func (s *GrpcServer) GetListenedPort() int

GetListenedPort retrieves and returns one port which is listened to by current server.

func (*GrpcServer) Logger added in v2.4.0

func (s *GrpcServer) Logger() *glog.Logger

Logger is alias of GetLogger.

func (*GrpcServer) Run

func (s *GrpcServer) Run()

Run starts the server in blocking way.

func (*GrpcServer) Service

func (s *GrpcServer) Service(services ...gsvc.Service)

Service binds service list to current server. Server will automatically register the service list after it starts.

func (*GrpcServer) Start

func (s *GrpcServer) Start()

Start starts the server in no-blocking way.

func (*GrpcServer) Stop

func (s *GrpcServer) Stop()

Stop gracefully stops the server.

func (*GrpcServer) UnaryLogger

func (s *GrpcServer) UnaryLogger(
	ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler,
) (interface{}, error)

UnaryLogger is the default unary interceptor for logging purpose.

func (*GrpcServer) Wait

func (s *GrpcServer) Wait()

Wait works with Start, which blocks current goroutine until the server stops.

type GrpcServerConfig

type GrpcServerConfig struct {
	// (optional) Name for current service.
	Name string

	// (optional) Single address for server listening, use `:0` or `ip:0` to serve random port.
	Address string

	// (optional) Logger for server.
	Logger *glog.Logger

	// (optional) LogPath specifies the directory for storing logging files.
	LogPath string

	// (optional) LogStdout specifies whether printing logging content to stdout.
	LogStdout bool

	// (optional) ErrorStack specifies whether logging stack information when error.
	ErrorStack bool

	// (optional) ErrorLogEnabled enables error logging content to files.
	ErrorLogEnabled bool

	// (optional) ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log
	ErrorLogPattern string

	// (optional) AccessLogEnabled enables access logging content to file.
	AccessLogEnabled bool

	// (optional) AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log
	AccessLogPattern string

	// (optional) Endpoints are custom endpoints for service register, it uses Address if empty.
	Endpoints []string

	// (optional) GRPC Server options.
	Options []grpc.ServerOption
}

GrpcServerConfig is the configuration for server.

func (*GrpcServerConfig) MustSetWithMap

func (c *GrpcServerConfig) MustSetWithMap(m g.Map)

MustSetWithMap acts as SetWithMap but panics if error occurs.

func (*GrpcServerConfig) SetWithMap

func (c *GrpcServerConfig) SetWithMap(m g.Map) error

SetWithMap changes current configuration with map. This is commonly used for changing several configurations of current object.

type Service

type Service struct {
	gsvc.Service
	Endpoints gsvc.Endpoints
}

Service implements gsvc.Service interface.

Directories

Path Synopsis
internal
balancer
Package balancer defines APIs for load balancing in gRPC.
Package balancer defines APIs for load balancing in gRPC.
grpcctx
Package grpcctx provides context feature for GRPC.
Package grpcctx provides context feature for GRPC.
resolver
Package resolver defines APIs for name resolution in gRPC.
Package resolver defines APIs for name resolution in gRPC.
tracing
Package tracing provide tracing feature for GRPC.
Package tracing provide tracing feature for GRPC.
utils
Package utils provides utilities for GRPC.
Package utils provides utilities for GRPC.

Jump to

Keyboard shortcuts

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