grpc

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

This file contains the gRPC server package's struct, Run() function, and helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(srv *Service, conf *GrpcConfig, sconf *security.SecurityConfig) (func(), error)

Run initializes and starts the gRPC server.

It takes a configuration struct as input. Returns a function to shut down the server and an error.

Types

type GrpcConfig

type GrpcConfig struct {
	KeepaliveInterval time.Duration `desc:"Interval at which to send keepalive pings to client" default:"60s" short:"k"`
	KeepaliveTimeout  time.Duration `desc:"Wait this duration for the ping ack before assuming the connection is dead" default:"10s" short:"t"`
	ListenAddress     string        `desc:"Address (host:port) at which to listen" default:"localhost:3144" short:"l"`
}

The struct required to configure the server. See the config package

type Service

type Service struct {
	LockServer lockServer
	pb.UnimplementedLDLMServer
}

func NewService

func NewService(srv lockServer) *Service

NewService returns a new Service with the given lockServer.

func (*Service) HandleConn

func (s *Service) HandleConn(ctx context.Context, st stats.ConnStats)

HandleConn is a function that handles a connection changes in the Service.

It takes in a context and a stats.ConnStats as parameters. It does not return anything.

func (*Service) HandleRPC

func (s *Service) HandleRPC(ctx context.Context, _ stats.RPCStats)

func (*Service) Lock

func (s *Service) Lock(ctx context.Context, req *pb.LockRequest) (*pb.LockResponse, error)

Lock locks a lock with the given name and lock timeout, and waits for the lock if necessary.

Parameters: - ctx: the context.Context for the request. - req: the *pb.LockRequest

Returns: - *pb.LockResponse: the response containing the name, key, locked

func (*Service) Renew

func (s *Service) Renew(ctx context.Context, req *pb.RenewRequest) (*pb.LockResponse, error)

Renew renews the lock for a given name and key with a new lock timeout.

Parameters: - ctx: the context.Context for the request. - req: the *pb.RenewRequest containing the name, key, and lock timeout.

Returns: - *pb.LockResponse: the response containing the name, key, locked status, and error. - error: any error that occurred during the renew.

func (*Service) TagConn

func (s *Service) TagConn(ctx context.Context, st *stats.ConnTagInfo) context.Context

TagConn is a function that is called with each new connection.

It takes in a context and a ConnTagInfo struct as parameters. It returns a modified context.

func (*Service) TagRPC

func (s *Service) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context

Unimplemented methods, but needed to satisfy grpc.stats.Handler interface

func (*Service) TryLock

func (s *Service) TryLock(ctx context.Context, req *pb.TryLockRequest) (*pb.LockResponse, error)

TryLock attempts to acquire a lock with the given name and lock timeout.

Parameters: - ctx: the context.Context for the request. - req: the *pb.TryLockRequest

Returns: - *pb.LockResponse: the response containing the name, key, locked status, and error. - error: any error that occurred during the lock attempt.

func (*Service) Unlock

func (s *Service) Unlock(ctx context.Context, req *pb.UnlockRequest) (*pb.UnlockResponse, error)

Unlock unlocks a lock with the given name and key.

Parameters: - ctx: the context.Context for the request. - req: the *pb.UnlockRequest containing the name and key of the lock to unlock.

Returns: - *pb.UnlockResponse: the response containing the name, unlocked status, and error. - error: any error that occurred during the unlock attempt.

Jump to

Keyboard shortcuts

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