grpc

package
v0.0.0-...-29fb6bf Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 30 Imported by: 3

README

gRPC SDK

Create gRPC server

grpcServer, err := grpc.NewServer()
if err != nil {
    log.Fatalf("grpc.NewServer: %v", err)
}

The default is port 8080 for gRPC and port 8081 for metrics. You can update it using options:

grpcServer, err := grpc.NewServer(
    grpc.WithPort("11000"),
    grpc.WithMetricsPort("11001"),
)
...

Jaeger tracer option:

grpcServer, err := grpc.NewServer(
    grpc.WithJaeger("jaeger:5555"),
)
...

Graylog option:

grpcServer, err := grpc.NewServer(
    grpc.WithGraylog("graylog:9000"),
)
...

Use domain-name-service to automatically resolve addresses and connect to other gRPC services by name only. First of all you have to run this service sources.

grpcServer, err := grpc.NewServer(
    grpc.WithDomainNameService(
         context.TODO(), 
         "localhost:10000",
     ),
)
...

Connect to another gRPC service

  1. You are not using domain-name-service to resolve addresses by service-name
authClient, err := grpc.NewClient[auth_service.AuthServiceClient](
        ctx,
	auth_service.NewAuthServiceClient,
	"localhost:7040",
)
...
  1. You are using domain-name-service
authClient, err := grpc.NewClient[auth_service.AuthServiceClient](
        ctx,
	auth_service.NewAuthServiceClient,
	"rpc:///auth-service",
)
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRegistry

func GetRegistry() *prometheus.Registry

func GetTracer

func GetTracer() opentracing.Tracer

func NewClient

func NewClient[Client any](ctx context.Context, connWrapper ConnWrapper[Client], serviceName string) (Client, error)

func NewDomainNameService

func NewDomainNameService(ctx context.Context, domainNameServiceHost string) error

func NewTracer

func NewTracer(jaegerEndpoint string) (opentracing.Tracer, io.Closer, error)

Types

type ConnWrapper

type ConnWrapper[Client any] func(_ grpc.ClientConnInterface) Client

type Server

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

func NewServer

func NewServer(options ...ServerOption) (*Server, error)

func (*Server) ProxyRouter

func (s *Server) ProxyRouter() *runtime.ServeMux

func (*Server) Run

func (s *Server) Run(ctx context.Context, descs ...ServiceDescriptor) error

type ServerOption

type ServerOption func(s *Server) error

func WithDomainNameService

func WithDomainNameService(ctx context.Context, dnsHost string) ServerOption

func WithGraylog

func WithGraylog(graylogHost string) ServerOption

func WithMetricsPort

func WithMetricsPort(metricsPort string) ServerOption

func WithPort

func WithPort(port string) ServerOption

func WithProxyPort

func WithProxyPort(proxyPort string) ServerOption

func WithRealtimeConfigsService

func WithRealtimeConfigsService(ctx context.Context, dnsHost string) ServerOption

func WithSwaggerPort

func WithSwaggerPort(swaggerPort string) ServerOption

func WithTracer

func WithTracer(jaegerEndpoint string) ServerOption

type ServiceDescriptor

type ServiceDescriptor interface {
	GetDescription() *grpc.ServiceDesc
}

Directories

Path Synopsis
pkg
domain-name-service
Package domain_name_service is a reverse proxy.
Package domain_name_service is a reverse proxy.

Jump to

Keyboard shortcuts

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