dlock_grpc

package module
v0.0.0-...-27a1838 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 10 Imported by: 0

README

dlock_grpc

dlock is a simple distributed lock implemented in golang. In its original implementation it supports local calls or REST API calls. This package provides a GRPC implementation of the lock that aims to provide better speed and scalability.

To use

Install (or update) the package using the command go get -u bitbucket.org/HelgeOlav/dlock_grpc

Look at server_test.go for an example on how to use this with gRPC.

To build the code when dlock.proto is updated

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative dlock.proto

Documentation

Index

Constants

View Source
const (
	Dlock_Lock_FullMethodName      = "/dlock/Lock"
	Dlock_Unlock_FullMethodName    = "/dlock/Unlock"
	Dlock_IsPresent_FullMethodName = "/dlock/IsPresent"
)
View Source
const Version = "0.0.2"

Variables

View Source
var Dlock_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "dlock",
	HandlerType: (*DlockServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Lock",
			Handler:    _Dlock_Lock_Handler,
		},
		{
			MethodName: "Unlock",
			Handler:    _Dlock_Unlock_Handler,
		},
		{
			MethodName: "IsPresent",
			Handler:    _Dlock_IsPresent_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "dlock.proto",
}

Dlock_ServiceDesc is the grpc.ServiceDesc for Dlock service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var File_dlock_proto protoreflect.FileDescriptor

Functions

func RegisterDlockServer

func RegisterDlockServer(s grpc.ServiceRegistrar, srv DlockServer)

Types

type DlockClient

type DlockClient interface {
	Lock(ctx context.Context, in *Lockparams, opts ...grpc.CallOption) (*Lockresponse, error)
	Unlock(ctx context.Context, in *Lockparams, opts ...grpc.CallOption) (*Lockresponse, error)
	IsPresent(ctx context.Context, in *Lockparams, opts ...grpc.CallOption) (*Lockresponse, error)
}

DlockClient is the client API for Dlock service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewDlockClient

func NewDlockClient(cc grpc.ClientConnInterface) DlockClient

type DlockGRPC

type DlockGRPC struct {
	UnimplementedDlockServer
	// contains filtered or unexported fields
}

DlockGRPC is the struct that represents a gRPC server object

func NewDlockGRPC

func NewDlockGRPC(opts ...dlock.ServerOption) *DlockGRPC

NewDlockGRPC returns a new gRPC server object

func (*DlockGRPC) GetLockServer

func (d *DlockGRPC) GetLockServer() *dlock.DLockServer

GetLockServer returns the underlying lock server object

func (*DlockGRPC) IsPresent

func (d *DlockGRPC) IsPresent(_ context.Context, params *Lockparams) (*Lockresponse, error)

IsPresent checks if a lock is present

func (*DlockGRPC) Lock

func (d *DlockGRPC) Lock(_ context.Context, params *Lockparams) (*Lockresponse, error)

Lock tries to lock the object by the given name

func (*DlockGRPC) Unlock

func (d *DlockGRPC) Unlock(_ context.Context, params *Lockparams) (*Lockresponse, error)

Unlock unlocks (releases) an object and returns true if the object was released

type DlockServer

type DlockServer interface {
	Lock(context.Context, *Lockparams) (*Lockresponse, error)
	Unlock(context.Context, *Lockparams) (*Lockresponse, error)
	IsPresent(context.Context, *Lockparams) (*Lockresponse, error)
	// contains filtered or unexported methods
}

DlockServer is the server API for Dlock service. All implementations must embed UnimplementedDlockServer for forward compatibility

type Lockparams

type Lockparams struct {
	Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
	// contains filtered or unexported fields
}

func (*Lockparams) Descriptor deprecated

func (*Lockparams) Descriptor() ([]byte, []int)

Deprecated: Use Lockparams.ProtoReflect.Descriptor instead.

func (*Lockparams) GetName

func (x *Lockparams) GetName() string

func (*Lockparams) ProtoMessage

func (*Lockparams) ProtoMessage()

func (*Lockparams) ProtoReflect

func (x *Lockparams) ProtoReflect() protoreflect.Message

func (*Lockparams) Reset

func (x *Lockparams) Reset()

func (*Lockparams) String

func (x *Lockparams) String() string

type Lockresponse

type Lockresponse struct {
	IsLocked *bool `protobuf:"varint,1,req,name=isLocked" json:"isLocked,omitempty"`
	// contains filtered or unexported fields
}

func (*Lockresponse) Descriptor deprecated

func (*Lockresponse) Descriptor() ([]byte, []int)

Deprecated: Use Lockresponse.ProtoReflect.Descriptor instead.

func (*Lockresponse) GetIsLocked

func (x *Lockresponse) GetIsLocked() bool

func (*Lockresponse) ProtoMessage

func (*Lockresponse) ProtoMessage()

func (*Lockresponse) ProtoReflect

func (x *Lockresponse) ProtoReflect() protoreflect.Message

func (*Lockresponse) Reset

func (x *Lockresponse) Reset()

func (*Lockresponse) String

func (x *Lockresponse) String() string

type UnimplementedDlockServer

type UnimplementedDlockServer struct {
}

UnimplementedDlockServer must be embedded to have forward compatible implementations.

func (UnimplementedDlockServer) IsPresent

func (UnimplementedDlockServer) Lock

func (UnimplementedDlockServer) Unlock

type UnsafeDlockServer

type UnsafeDlockServer interface {
	// contains filtered or unexported methods
}

UnsafeDlockServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to DlockServer will result in compilation errors.

Jump to

Keyboard shortcuts

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