common

package
v0.0.0-...-344bb71 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KB - Kilobytes
	KB uint64 = 1024

	// MB - Megabytes
	MB uint64 = 1024 * 1024
)

Variables

This section is empty.

Functions

func BoolToByte

func BoolToByte(b bool) byte

BoolToByte converts a bool to byte

func ByteSliceToFloat64

func ByteSliceToFloat64(b []byte) float64

func ByteSliceToI64

func ByteSliceToI64(b []byte) int64

ByteSliceToI64 converts a byte slice to int64. The byte should have been created using I64ToByte

func ByteSliceToU64

func ByteSliceToU64(b []byte) uint64

ByteSliceToU64 converts a byte slice to Uint64. The byte should have been created using U64ToByte

func ByteSliceToU64Slice

func ByteSliceToU64Slice(bslice []byte) []uint64

ByteSliceToU64Slice converts a byte slice to a slice of uint64

func ByteToBool

func ByteToBool(b byte) bool

ByteToBool converts a byte to bool

func Float64ToByteSlice

func Float64ToByteSlice(f float64) []byte

func I64ToByteSlice

func I64ToByteSlice(num int64) []byte

I64ToByteSlice converts a int64 to []byte

func MinU64

func MinU64(a, b uint64) uint64

MinU64 returns min of two uint64

func U64SliceToByteSlice

func U64SliceToByteSlice(uslice []uint64) []byte

U64SliceToByteSlice converts a uint64 slice to a byte slice

func U64ToByteSlice

func U64ToByteSlice(num uint64) []byte

U64ToByteSlice converts a uint64 to []byte

Types

type ClientConfig

type ClientConfig struct {
	Servers []Peer `yaml:"servers"`
}

ClientConfig defines the configuration settings for IcecaneSQL

func (*ClientConfig) LoadFromFile

func (conf *ClientConfig) LoadFromFile(path string)

LoadFromFile reads the client config from the file

type KVConfig

type KVConfig struct {
	ID      uint64 `yaml:"id"`
	DbPath  string `yaml:"dbPath"`
	Address string `yaml:"address"`
	Port    string `yaml:"port"`

	// Peers contains the list of all the icecanekv instances excluding this server.
	Peers []Peer `yaml:"peers"`
}

KVConfig defines the configuration settings for IcecaneKV

func NewDefaultKVConfig

func NewDefaultKVConfig() *KVConfig

NewDefaultKVConfig returns a new default key vault configuration.

func (*KVConfig) LoadFromFile

func (conf *KVConfig) LoadFromFile(path string)

LoadFromFile loads the config from the file. It assumes that config already has the defaults. In the case of an error, it leaves the config untouched.

func (*KVConfig) Validate

func (conf *KVConfig) Validate() error

Validate validates a KVConfig and returns an error if it's invalid.

type Peer

type Peer struct {
	ID      uint64 `yaml:"id"`
	Address string `yaml:"address"`
	Port    string `yaml:"port"`
}

Peer indicates a single icecanekv instance info

type ProtectedBool

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

ProtectedBool is a boolean protected by RW lock

func (*ProtectedBool) Get

func (b *ProtectedBool) Get() bool

Get gets the value

func (*ProtectedBool) Set

func (b *ProtectedBool) Set(nvalue bool)

Set sets the value (surprise surprise!)

type ProtectedMapUConn

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

ProtectedMapUConn is a RWMutex protected map from uint64 to grpc.ClientConn

func NewProtectedMapUConn

func NewProtectedMapUConn() *ProtectedMapUConn

NewProtectedMapUConn initializes a new protected map of uint64 to grpc connection.

func (*ProtectedMapUConn) Get

func (pm *ProtectedMapUConn) Get(key uint64) (*grpc.ClientConn, bool)

Get gets the value

func (*ProtectedMapUConn) Iterate

func (pm *ProtectedMapUConn) Iterate() map[uint64]*grpc.ClientConn

Iterate exposes the underlying map by locking it.

func (*ProtectedMapUConn) Set

func (pm *ProtectedMapUConn) Set(key uint64, value *grpc.ClientConn)

Set sets the value

type ProtectedString

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

ProtectedString is a string protected by RW lock

func (*ProtectedString) Get

func (b *ProtectedString) Get() string

Get gets the value

func (*ProtectedString) Set

func (b *ProtectedString) Set(nvalue string)

Set sets the value (surprise surprise!)

type ProtectedUint64

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

ProtectedUint64 is a Uint64 protected by RW lock

func (*ProtectedUint64) Get

func (b *ProtectedUint64) Get() uint64

Get gets the value

func (*ProtectedUint64) Increment

func (b *ProtectedUint64) Increment() uint64

Increment increments the value atomically and returns the new value.

func (*ProtectedUint64) Set

func (b *ProtectedUint64) Set(nvalue uint64)

Set sets the value (surprise surprise!)

func (*ProtectedUint64) SetIfGreater

func (b *ProtectedUint64) SetIfGreater(nvalue uint64) (old uint64)

SetIfGreater sets the nvalue if the old value < nvalue. if return value is less than nvalue, then the value was updated.

Jump to

Keyboard shortcuts

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