Skip to content

Grpc Go-API

import "givc/modules/pkgs/grpc"

The grpc package provides functionality to create and manage gRPC server and client connections.

Copyright 2024 TII (SSRC) and the Ghaf contributors SPDX-License-Identifier: Apache-2.0

Constants for gRPC client configuration

const (
MAX_RETRY = uint(3)
TIMEOUT = 150 * time.Millisecond
)

Constants for gRPC server configuration

const (
LISTENER_WAIT_TIME = 1 * time.Second
LISTENER_RETRIES = 20
)

func NewClient(cfg *types.EndpointConfig) (*grpc.ClientConn, error)

NewClient creates a new gRPC client connection based on the provided endpoint configuration.

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

func vsockDialer(ctx context.Context, addr string) (net.Conn, error)

vsockDialer is a custom dialer for vsock connections.

func withOutgoingContext(ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

withOutgoingContext is a gRPC client interceptor that adds outgoing metadata to the context.

func withRetryOpts() grpc.UnaryClientInterceptor

withRetryOpts is a gRPC client interceptor that adds retry options to the gRPC call.

type GrpcServer struct {
config *GrpcServerConfig
grpcServer *grpc.Server
}

func NewServer(cfg *types.EndpointConfig, services []types.GrpcServiceRegistration) (*GrpcServer, error)

NewServer creates a new gRPC server based on the provided endpoint configuration and service registrations.

func (s *GrpcServer) ListenAndServe(ctx context.Context, started chan struct{}) error

ListenAndServe starts the gRPC server and listens for incoming connections.

type GrpcServerConfig struct {
Transport *types.TransportConfig
TlsConfig *tls.Config
Services []types.GrpcServiceRegistration
}

Generated by gomarkdoc