storage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 2 Imported by: 0

README

Storage Backend for Darkroom

About

This module holds the logic to get an image blob from a source. It is used by the Darkroom Application Server.
You may implement the Storage interface to gain custom functionality while still keeping other Darkroom functionality.
You may write custom backend for downloading images from a hosting provider or a web proxy.

Interfaces
type Storage interface {
	Get(ctx context.Context, path string) IResponse
}

Any struct implementing the above interface can be used with Darkroom.

Note: The response returned should be of type IResponse

type IResponse interface {
	Data() []byte
	Error() error
	Status() int
}
Example
s3s := s3.NewStorage(
                s3.WithBucketName("bucket"),
                s3.WithBucketRegion("region"),
                s3.WithAccessKey("randomAccessKey"),
                s3.WithSecretKey("randomSecretKey"),
                s3.WithHystrixCommand(storage.HystrixCommand{
                    Name: "TestCommand",
                    Config: hystrix.CommandConfig{
                        Timeout:                2000,
                        MaxConcurrentRequests:  100,
                        RequestVolumeThreshold: 10,
                        SleepWindow:            10,
                        ErrorPercentThreshold:  25,
                    },
                }),
            )

res := s3s.Get(context.Background(), "path/to/image-blob")
if res.Error() != nil {
	fatal(res.Error())
}

// res.Status() -> Status Code returned by the backend
// res.Data() -> Data in form of []byte returned by the backend

Documentation

Overview

Package storage contains the Storage interface and its various implementations for different backends.

Index

Constants

View Source
const (
	HeaderAcceptRanges  = "Accept-Ranges"
	HeaderContentLength = "Content-Length"
	HeaderContentRange  = "Content-Range"
	HeaderContentType   = "Content-Type"
	HeaderETag          = "ETag"
	HeaderLastModified  = "Last-Modified"
	HeaderRange         = "Range"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetPartiallyRequestOptions added in v0.1.0

type GetPartiallyRequestOptions struct {
	Range string
}

GetPartiallyRequestOptions holds option to request data from storage

type HystrixCommand

type HystrixCommand struct {
	Name   string
	Config hystrix.CommandConfig
}

HystrixCommand wraps the command name and the configuration to be used with hystrix

type IResponse

type IResponse interface {
	// Data method returns a byte array if the operation was successful
	Data() []byte
	// Error method returns an error if the operation was unsuccessful
	Error() error
	// Status method returns the http StatusCode from the storage backend if there is any
	Status() int
	// Metadata method returns response metadata if the operation is successful and client support metadata
	Metadata() *ResponseMetadata
}

IResponse interface sets the contract that can be used to return the result from different Storage backends.

type Response

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

Response implements the IResponse interface

func NewResponse

func NewResponse(data []byte, statusCode int, err error) *Response

NewResponse takes data, statusCode and error as arguments and returns a new Response

func (*Response) Data

func (r *Response) Data() []byte

Data returns the data field from the struct

func (*Response) Error

func (r *Response) Error() error

Error returns the err field from the struct

func (*Response) Metadata added in v0.1.0

func (r *Response) Metadata() *ResponseMetadata

Metadata returns metadata field from the struct

func (*Response) Status

func (r *Response) Status() int

Status returns the status field from the struct

func (*Response) WithMetadata added in v0.1.0

func (r *Response) WithMetadata(metadata *ResponseMetadata) *Response

WithMetadata sets metadata field on the struct

type ResponseMetadata added in v0.1.0

type ResponseMetadata struct {
	AcceptRanges  string
	ContentLength string
	ContentRange  string
	ContentType   string
	ETag          string
	LastModified  string
}

ResponseMetadata contains metadata of the storage response

type Storage

type Storage interface {
	// Get takes in the Context and path as an argument and returns an IResponse interface implementation.
	// This method figures out how to get the data from the storage backend.
	Get(ctx context.Context, path string) IResponse
	// GetPartially takes in the Context, path, and opt as an argument and returns an IResponse interface implementation.
	// This method figures out how to get partial data from the storage backend.
	GetPartially(ctx context.Context, path string, opt *GetPartiallyRequestOptions) IResponse
}

Storage interface sets the contract that the implementation has to fulfil.

Directories

Path Synopsis
aws
s3

Jump to

Keyboard shortcuts

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