objectstore

package module
v0.0.0-...-2e7b226 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 8 Imported by: 0

README

Object Store Driver

This is the object store driver package. It is used to cache schemas and query results. The Interface in interface.go is implemented by both the actual driver and the mock driver. This allows for the use of a mock object store in usecase testing in services.

Creating a Driver

import "git.science.uu.nl/datastrophe/objectstore"

objectStore := objectstore.NewDriver()

// Connect to the object store
// Pass in the minio address, username (accessKeyID) and password (accessKey)
objectStore.Connect("localhost:9000", "root", "DikkeDraak")

Creating a Mock Driver

import "git.science.uu.nl/datastrophe/objectstore"

mockObjectStore := objectstore.NewMockDriver()

Putting Objects

err := objectStore.Put(ctx context.Context, bucketName string, objectName string, objectSize int64, object io.Reader)

Getting Objects

objectReader, err := objectStore.Get(ctx context.Context, bucketName string, objectName string)

Testing

To test the object store package we wrote a bash script. The bash script starts up a Minio Docker container on which the tests are performed. Once the tests are completed, the Docker container is killed and deleted. Code coverage can be found in the cover.html file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver implements the ObjectStore interface

func (*Driver) Connect

func (d *Driver) Connect(address, accessKeyID, accessKey string) error

Connect opens a connection to the object store

Return: if there's an error

func (*Driver) Get

func (d *Driver) Get(ctx context.Context, bucketName string, objectName string) (io.Reader, error)

Get gets the object from the object store

ctx: context.Context, the context in which this operation takes place
bucketName: string, name of the bucket this object is in
objectName: string, name of the object
Returns: io.Reader for the object and a possible error

func (*Driver) Put

func (d *Driver) Put(ctx context.Context, bucketName string, objectName string, objectSize int64, object io.Reader) error

Put puts an object into the object store

ctx: context.Context, the context in which this operation takes place
bucketName: string, the bucket to place the object into
objectName: io.Reader, a reader for the object we want to place in the object store
Returns a possible error

type Interface

type Interface interface {
	Connect(address, accessKeyID, accessKey string) error
	Get(ctx context.Context, bucketName string, objectName string) (io.Reader, error)
	Put(ctx context.Context, bucketName string, objectName string, objectSize int64, object io.Reader) error
}

The Interface models an object store with storage buckets

func NewDriver

func NewDriver() Interface

NewDriver creates a new object store driver

Return: the interface of the new driver

func NewMockDriver

func NewMockDriver() Interface

NewMockDriver creates a new mock object store driver

Return: the interface of the new mock driver

type MockDriver

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

MockDriver implements the ObjectStore interface (mock)

func (*MockDriver) Connect

func (d *MockDriver) Connect(address, accessKeyID, accessKey string) error

Connect opens a connection to the object store (mock)

Return: an error if there is one

func (*MockDriver) Get

func (d *MockDriver) Get(ctx context.Context, bucketName string, objectName string) (io.Reader, error)

Get gets an object from the object store (mock)

ctx: context.Context, the context for the mock driver
bucketName: string, the name of the bucket
objectName: string, the name of the object
Return: (io.Reader, error) returns the reader and an error if there is one

func (*MockDriver) Put

func (d *MockDriver) Put(ctx context.Context, bucketName string, objectName string, objectSize int64, object io.Reader) error

Put puts an object in the object store

ctx: context.Context, the context for the mock driver
bucketName: string, the name of the bucket
objectName: string, the name of the object
objectSize: int64, the size of the object
object: io.Reader, the reader for the mock driver
Return: error if there is one

func (*MockDriver) ToggleThrowGetError

func (d *MockDriver) ToggleThrowGetError()

ToggleThrowGetError makes the Get method throw an error the next time it is called

func (*MockDriver) ToggleThrowPutError

func (d *MockDriver) ToggleThrowPutError()

ToggleThrowPutError makes the Put method throw an error the next time it is called

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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