s3kv

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: LGPL-2.1 Imports: 9 Imported by: 0

README

s3kv

A simple S3 compatible KV operation wrapper

Documentation

Usage


// Init connection
s3, err = s3kv.New(&s3kv.Config{
	Endpoint:  os.Getenv("S3_ENDPOINT"),
	Bucket:    os.Getenv("S3_BUCKET"),
	AccessKey: os.Getenv("S3_ACCESS_KEY"),
	SecretKey: os.Getenv("S3_SECRET_KEY"),
})

// Put an object
s3.Put("foo", []byte("bar"))

// Get an object
bar, _ := s3.Get("foo")

// Marshal an object to JSON then Put
s3.PutObject("foo-json", []string{"foo", "bar"})

// Get an object and unmarshal it
foobar := make([]string)
s3.GetJSON("foo-json", &foobar)

// List key of objects
keys1, _ := s3.List("") // List all keys
keys2, _ := s3.List("prefix_") // List keys with "prefix_" prefix

// Delete an object
s3.Delete("foo")

// Check if a key is exists
isExists := s3.KeyExists("foo")
  

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExists error = errors.New("Not exists")

Functions

This section is empty.

Types

type Config

type Config struct {
	Endpoint  string
	AccessKey string
	SecretKey string
	Region    string
	Bucket    string
}

type Storage

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

func New

func New(config *Config) (*Storage, error)

func (*Storage) Delete

func (s *Storage) Delete(key string) error

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

Get a key from storage. If key is not exists, a ErrNotExists error is returnd.

func (*Storage) GetJSON

func (s *Storage) GetJSON(key string, value any) error

Get an JSON-encoded object and unmarshal it into value.

func (*Storage) KeyExists

func (s *Storage) KeyExists(key string) (bool, error)

Check if a key is exists. The first return value indicate if the key is exists. If failed, an error is returned and the first return value is meaningless.

func (*Storage) List

func (s *Storage) List(key_prefix string) ([]string, error)

func (*Storage) Put

func (s *Storage) Put(key string, value []byte) error

func (*Storage) PutObject

func (s *Storage) PutObject(key string, value any) error

Marshal an object and then put it to storage.

Jump to

Keyboard shortcuts

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