atur

package module
v0.0.0-...-47cf6cb Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 12 Imported by: 0

README

atur

an object storage for go

Test Go Report Card

Introduction

An objects storage for go implement in leveldb. You can see the example to know how to use it.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Err_NotFound = errors.New("atur: not found")
	Err_TimeOut  = errors.New("atur: timeout")
)

Functions

func InterfaceTo

func InterfaceTo[T any](i interface{}) T

func InterfaceToWithBool

func InterfaceToWithBool[T any](i interface{}, b bool) (T, bool)

func InterfaceToWithError

func InterfaceToWithError[T any](i interface{}, err error) (T, error)

Types

type Int32

type Int32 struct{ V int32 }

func (*Int32) Serialize

func (i32 *Int32) Serialize() (b []byte)

func (*Int32) Unserialize

func (i32 *Int32) Unserialize(s []byte) (err error)

type Int64

type Int64 struct{ V int64 }

func (*Int64) Serialize

func (i64 *Int64) Serialize() (b []byte)

func (*Int64) Unserialize

func (i64 *Int64) Unserialize(s []byte) (err error)

type KvOption

type KvOption func(*KvStoreConfig)

func SetDir

func SetDir(dir string) KvOption

func SetShards

func SetShards(shards int) KvOption

type KvStore

type KvStore interface {

	// Set kv pair to KVstore
	// input:
	// ctx : context
	// key : []byte
	// value : a Serializable Object, must be a point
	//
	// return :
	// error
	SetCtx(ctx context.Context, key []byte, value Serializable) (err error)

	// Delete the key from KVstore
	// input:
	// ctx : context
	// key : []byte
	//
	// return:
	// error
	DelCtx(ctx context.Context, key []byte) (err error)

	// Get kv pair from KVstore
	// input:
	// ctx : context
	// key : []byte
	// value : a Serializable Object, must be an initialized point,
	// 				 a null point is not availiable.
	//
	// return:
	// error
	GetCtx(ctx context.Context, key []byte, value Serializable) (err error)

	// Set a TTL kv pair to KVstore
	// input:
	// ctx : context
	// key : []byte
	// value : a Serializable Object, must be a TTLSerializable point
	//
	// return:
	// error
	SetTTLCtx(ctx context.Context, key []byte, value TTLSerializable) (err error)

	// Get TTL kv pair from KVstore
	// input:
	// ctx : context
	// key : []byte
	// value : a TTLSerializable Object, must be an initialized point,
	// 				 a null point is not availiable.
	//
	// return:
	// error
	GetTTLCtx(ctx context.Context, key []byte, value TTLSerializable) (err error)

	// Check if the key exist or not
	// input:
	// ctx : context
	// key : []byte
	//
	// return:
	// exist bool
	Exist(ctx context.Context, key []byte) (exist bool)

	// maybe only used by leveldbKvStore
	GetFull() map[string]string
	Close() (err error)
}

func NewKvStore

func NewKvStore(kvConf *KvStoreConfig) (KvStore, error)

type KvStoreConfig

type KvStoreConfig struct {
	Dir            string
	Shards         int
	LeveldbOptions *leveldbOpt.Options
}

func DefaultKvConfig

func DefaultKvConfig() *KvStoreConfig

func NewKvConfig

func NewKvConfig(opts ...KvOption) (ksc *KvStoreConfig)

type Object

type Object interface {
	GetId() []byte
	Serializable
}

type Serializable

type Serializable interface {
	// This function support to serialize the object to []byte
	// in order to write down to the disk
	// this fuction **MUST** be no error, this rule must be
	// obeyed by the implementor.
	Serialize() []byte

	// Unserialize the []byte to Object.
	Unserialize(s []byte) (err error)
}

type SpinLock

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

func (*SpinLock) Lock

func (l *SpinLock) Lock()

func (*SpinLock) Unlock

func (l *SpinLock) Unlock()

type TTLSerializable

type TTLSerializable interface {
	TtlObject
	Serializable
}

type TtlObject

type TtlObject interface {
	// return the last time (unix ms) this Object can keep.
	GetTTLTime() int64
}

type Uint32

type Uint32 struct{ V uint32 }

func (*Uint32) Serialize

func (ui32 *Uint32) Serialize() (b []byte)

func (*Uint32) Unserialize

func (ui32 *Uint32) Unserialize(s []byte) (err error)

type Uint64

type Uint64 struct{ V uint64 }

func (*Uint64) Serialize

func (ui64 *Uint64) Serialize() (b []byte)

func (*Uint64) Unserialize

func (ui64 *Uint64) Unserialize(s []byte) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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