storage

package
v0.0.0-...-9bc5457 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package storage used for handling saving/retreiving data on a single node server

Index

Constants

View Source
const (
	DefaultPartitionFormat = "partition_%d"
)

Variables

This section is empty.

Functions

func Hash

func Hash(key string, partitionNumber int) (hash int, partition int, err error)

Hash returns hash value and partition of a string key

Types

type Document

type Document struct {
	Key       string
	Value     any
	CreatedAt time.Time
	UpdatedAt time.Time
}

func NewDocument

func NewDocument(key string, val any) *Document

type SaveData

type SaveData struct {
	Key   string
	Value any
}

type Storage

type Storage struct {
	DefaultPath     string
	PartitionNumber int
}

func NewStorage

func NewStorage(defaultPath string, partitionNumber int) *Storage

func (*Storage) Get

func (s *Storage) Get(key string) (any, bool, error)

func (*Storage) Put

func (s *Storage) Put(key string, value interface{}) error

Put function is for saving value under key string By default saves under path/gopher-storage/partition_n/key_hash/number.json

type Storer

type Storer interface {
	Put(key string, value interface{}) error
	Get(key string) (any, bool, error)
}

Jump to

Keyboard shortcuts

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