datastores

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const BUFFER_SIZE = 255
View Source
const CHUNK_HEADER_SIZE = 8 + CHUNK_ID_LENGTH
View Source
const CHUNK_ID_LENGTH = 16
View Source
const CHUNK_VERSION = 1
View Source
const ENTRY_VERSION = 1

Variables

View Source
var Definitions = hyper.DatastoreDefinitions{
	"redis": hyper.DatastoreDefinition{
		Name:              "Redis Datastore",
		Description:       "For Production Use",
		Maker:             MakeRedis,
		SettingsValidator: ValidateRedisSettings,
	},
	"file": hyper.DatastoreDefinition{
		Name:              "File-based Datastore",
		Description:       "An file-based datastore",
		Maker:             MakeFile,
		SettingsValidator: ValidateFileSettings,
	},
}
View Source
var FileForm = forms.Form{
	ErrorMsg: "invalid data encountered in the File config form",
	Fields: []forms.Field{
		{
			Name: "filename",
			Validators: []forms.Validator{
				forms.IsString{},
			},
		},
	},
}
View Source
var RedisForm = forms.Form{
	ErrorMsg: "invalid data encountered in the Redis config form",
	Fields: []forms.Field{
		{
			Name: "addresses",
			Validators: []forms.Validator{
				forms.IsRequired{},
				forms.IsStringList{},
			},
		},
		{
			Name: "key",
			Validators: []forms.Validator{
				forms.IsOptional{Default: "entries"},
				forms.IsString{},
			},
		},
		{
			Name: "master_name",
			Validators: []forms.Validator{
				forms.IsOptional{Default: ""},
				forms.IsString{},
			},
		},
		{
			Name: "database",
			Validators: []forms.Validator{
				forms.IsOptional{Default: 0},
				forms.IsInteger{Min: 0, Max: 100},
			},
		},
		{
			Name: "password",
			Validators: []forms.Validator{
				forms.IsRequired{},
				forms.IsString{},
			},
		},
	},
}

Functions

func FromBytes

func FromBytes(data []byte) (*hyper.DataEntry, error)

func MakeFile

func MakeFile(settings interface{}) (hyper.Datastore, error)

func MakeRedis

func MakeRedis(settings interface{}) (hyper.Datastore, error)

func Reassemble

func Reassemble(chunks []*DataChunk) (*hyper.DataEntry, error)

func ToBytes

func ToBytes(e *hyper.DataEntry) []byte

func ValidateFileSettings

func ValidateFileSettings(settings map[string]interface{}) (interface{}, error)

func ValidateRedisSettings

func ValidateRedisSettings(settings map[string]interface{}) (interface{}, error)

Types

type ByPosition

type ByPosition struct {
	Entries   []*hyper.DataEntry
	Positions map[string]int
}

func (ByPosition) Len

func (b ByPosition) Len() int

func (ByPosition) Less

func (b ByPosition) Less(i, j int) bool

func (ByPosition) Swap

func (b ByPosition) Swap(i, j int)

type DataChunk

type DataChunk struct {
	// The number of chunks for this hash
	Chunks uint16
	// The index of this chunk
	Index uint16
	// The actual ID of the entry this chunk belongs to
	ID []byte
	// The actual data in this chunk
	Data []byte
}

func MakeDataChunk

func MakeDataChunk(id []byte, chunks, index uint16, data []byte) *DataChunk

func Split

func Split(e *hyper.DataEntry) ([]*DataChunk, error)

Splits a data entry into multiple data chunks.

func (*DataChunk) Read

func (d *DataChunk) Read(reader io.Reader) error

func (*DataChunk) Write

func (d *DataChunk) Write(writer io.Writer) error

Writes a data chunkn to the given writer

type FileDatastore

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

A file-based data store

func (*FileDatastore) Init

func (f *FileDatastore) Init() error

func (*FileDatastore) Read

func (f *FileDatastore) Read() ([]*hyper.DataEntry, error)

func (*FileDatastore) Write

func (f *FileDatastore) Write(entry *hyper.DataEntry) error

type FileSettings

type FileSettings struct {
	Filename string `json:"filename"`
}

type Redis

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

func (*Redis) Client

func (d *Redis) Client() redis.Cmdable

func (*Redis) Close

func (d *Redis) Close() error

func (*Redis) Init

func (d *Redis) Init() error

func (*Redis) Open

func (d *Redis) Open() error

func (*Redis) Read

func (d *Redis) Read() ([]*hyper.DataEntry, error)

func (*Redis) Write

func (d *Redis) Write(entry *hyper.DataEntry) error

type RedisSettings

type RedisSettings struct {
	MasterName string   `json:"master_name"`
	Addresses  []string `json:"addresses`
	Database   int64    `json:"database"`
	Key        string   `json:"key"`
	Password   string   `json:"password"`
}

Jump to

Keyboard shortcuts

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