s3lite

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

README

S3Lite

S3Lite is a native Golang storage system, similar to Amazon S3.

Go Report Card GoDoc

It allows to store and retrieve data by key. Data is stored in a directory, with each key being a file. The package provides functions to set, get, and delete data. It also provides an iterator to traverse over all data in the storage.

Installation

go get github.com/kirill-scherba/sqlh

Usage

package main

import (
    "github.com/kirill-scherba/s3lite"
)

func main() {
    // Create a new S3Lite instance
    s3lite, err := s3lite.New("./data", "my-bucket")
    if err != nil {
        panic(err)
    }

    // Add some data to the S3Lite instance with Set method
    err := s3lite.Set("key", []byte("value"))
    if err != nil {
        panic(err)
    }

    // Get the data from the S3Lite instance with Get method
    value, err := s3lite.Get("key")
    if err != nil {
        panic(err)
    }
    fmt.Println(string(value))

    // Iterate over all keys with List method
    for key := range s3lite.List("") {
        fmt.Println(key)
    }

    // Delete the data from the S3Lite instance with Delete method
    err = s3lite.Delete("key")
    if err != nil {
        panic(err)
    }
}

Licence

BSD

Documentation

Overview

S3 like native Golang storage.

This package provides a simple storage system, similar to Amazon S3. It allows to store and retrieve data by key. Data is stored in a directory, with each key being a file. The package provides functions to set, get, and delete data. It also provides an iterator to traverse over all data in the storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type S3Lite

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

S3Lite is a wrapper for Badger database.

func New

func New(path, bucket string) (s *S3Lite, err error)

New creates a new S3 object.

The dbPath argument is the path to the directory where the Badger database files will be stored.

If the database connection can't be opened, an error is returned.

Example: s, err := s3.New("/path/to/db")

if err != nil {
	log.Fatal(err)
}

func (*S3Lite) Close

func (s *S3Lite) Close()

Close closes the database connection.

func (*S3Lite) Del

func (s *S3Lite) Del(key string) (err error)

Del deletes a key-value pair from the database.

Parameters:

  • key: the key to delete from the database.

Returns:

  • error: an error if the Del operation fails.

Example: s, err := s3.New("/path/to/db")

if err != nil {
	log.Fatal(err)
}

err = s.Del("key")

if err != nil {
	log.Fatal(err)
}

func (*S3Lite) Dir

func (s *S3Lite) Dir(key string) (dir string)

Dir returns the directory of the given key.

func (*S3Lite) Get

func (s *S3Lite) Get(key string) (value []byte, err error)

Get retrieves a value by its key from the database.

Parameters:

  • key: the key to get from the database.

Returns:

  • value: the value retrieved from the database.
  • error: an error if the Get operation fails.

Example: s, err := s3.New("/path/to/db", "bucket")

if err != nil {
	log.Fatal(err)
}

value, err := s.Get("key")

if err != nil {
	log.Fatal(err)
}

func (*S3Lite) IsFolder

func (s *S3Lite) IsFolder(key string) bool

IsFolder returns true if key is a folder.

func (*S3Lite) List

func (s *S3Lite) List(prefix string) iter.Seq[string]

List returns an iterator for all keys with given prefix.

The iterator yields each key that starts with the given prefix. The keys are yielded in lexicographical order.

Example: s, err := s3.New("/path/to/db", "bucket")

if err != nil {
	log.Fatal(err)
}

keysIter, err := s.List("prefix")

if err != nil {
	log.Fatal(err)
}

for keysIter.Next() {
	key := keysIter.Value()
	fmt.Println(key)
}

func (*S3Lite) Set

func (s *S3Lite) Set(key string, value []byte) (err error)

Set sets a key-value pair in the database.

Parameters:

  • key: the key to set in the database.
  • value: the value to set in the database.

Returns:

  • error: an error if the Set operation fails.

Example:

s, err := s3.New("/path/to/db")
if err != nil {
	log.Fatal(err)
}

err = s.Set("key", []byte("value"))
if err != nil {
	log.Fatal(err)
}

Jump to

Keyboard shortcuts

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