ez3

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 10 Imported by: 2

README

ez3

Go Reference

ez3 makes it easy to use AWS S3 as a key-value store. It handles serialization automatically as long as your data structs implement the ez3.Serializable interface.

ez3 uses AWS SDK for Go V2 under the hood, so it works with S3-compatible cloud storage providers aside from AWS, such as Backblaze B2.

Usage

// Connect to AWS S3 using your local credentials
store, err := ez3.NewS3(ez3.S3Args{
    Bucket:    "some-bucket",
    Namespace: "some-directory",
})
check(err)

// Persist a User struct (implements Serializable) to S3.
u1 := User{Name: "John", Email: "john@gmail.com"}
err = store.Set("user", &u1)
check(err)

// Then fetch the data back from S3 into a User struct.
var u2 User
err := store.Get("user", &u2)
check(err)

See the examples directory for complete examples.

Documentation

Overview

Package ez3 provides an interface to persisting structs into a key-value store such as AWS S3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewS3Client

func NewS3Client(args S3ClientArgs) (*awsS3.Client, error)

NewS3Client creates a new S3 client for use with S3EZ3. This is a helper function for users who want to connect to an S3-compatible cloud that is not AWS.

Types

type EZ3

type EZ3 interface {
	// Get retrieves a value from the store.
	Get(key string, dst Serializable) error
	// Set stores a value in the store.
	Set(key string, val Serializable) error
	// Del removes a value from the store.
	Del(key string) error
	// List lists all keys in the store with the given prefix.
	List(prefix string) (keys []string, err error)
}

EZ3 is a persistence interface which supports de/serialization.

func NewMemory

func NewMemory() EZ3

NewMemory creates a new memory-based EZ3 client.

func NewS3

func NewS3(args S3Args) (EZ3, error)

NewS3 creates a new S3-based EZ3 client.

type MemoryEZ3

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

MemoryEZ3 is an in-memory implementation of the EZ3 API.

func (MemoryEZ3) Del

func (e MemoryEZ3) Del(key string) error

Del removes a value from memory.

func (MemoryEZ3) Get

func (e MemoryEZ3) Get(key string, dst Serializable) error

Get retrieves a value from memory.

func (MemoryEZ3) List

func (e MemoryEZ3) List(prefix string) ([]string, error)

List lists all keys in memory with the given prefix.

func (MemoryEZ3) Set

func (e MemoryEZ3) Set(key string, val Serializable) error

Set stores a value in memory.

type S3Args

type S3Args struct {
	Bucket    string   // Required. The bucket that holds stored data.
	Namespace string   // Required. The namespace for this instance's keys.
	Client    S3Client // Optional. If not provided, autoconfigures an AWS S3 client from your environment.
}

S3Args is the set of arguments for creating a new S3-backed EZ3.

type S3Client

S3Client is the interface for an AWS S3-compatible client.

type S3ClientArgs

type S3ClientArgs struct {
	Endpoint     string // Required. The web endpoint of the S3 service. Usually starts with https://
	Region       string // Required. The region of the S3 service.
	UsePathStyle bool   // Optional. If true, the S3 client will use path-style addressing.
}

S3ClientArgs is the set of arguments for creating a new S3 client for use with S3EZ3.

type S3EZ3

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

S3EZ3 is an implementation of EZ3 backed by an S3-compatible file store.

func (S3EZ3) Del

func (s S3EZ3) Del(key string) error

Del removes a value from S3.

func (S3EZ3) Get

func (s S3EZ3) Get(key string, dst Serializable) error

Get retrieves a value from S3.

func (S3EZ3) List

func (s S3EZ3) List(prefix string) ([]string, error)

List lists all keys in the namespace with the given prefix.

func (S3EZ3) Set

func (s S3EZ3) Set(key string, val Serializable) error

Set stores a value in S3.

type Serializable

type Serializable interface {
	// Serialize serializes the struct's data into bytes.
	Serialize() ([]byte, error)
	// Deserialize deserializes the given bytes into the struct's data.
	Deserialize([]byte) error
}

Serializable is a data type which supports de/serialization. Any data stored through EZ3 must implement this interface.

Directories

Path Synopsis
examples
1_in_memory
Persist and retrieve a User object using the in-memory store.
Persist and retrieve a User object using the in-memory store.
2_aws_s3
Persist and retrieve a User object using AWS S3.
Persist and retrieve a User object using AWS S3.
3_backblaze_b2
Persist and retrieve a User object using Backblaze B2
Persist and retrieve a User object using Backblaze B2

Jump to

Keyboard shortcuts

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