s3lib

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 13 Imported by: 0

README

s3lib

Just another go library for s3 that makes it a little easier to work with.

API
Utilities
  • NewClient
  • NewClientWithSession
  • NewClientWithConfig
  • BucketKeyExists
  • DownloadFile
  • UploadDirectory
  • UploadFile
  • GetPresignedURL
Object Persistence
  • GetObject
  • GetString
  • PutObject
  • DeleteObject
  • PutContent
  • List
  • KeyExists
Usage
go get github.com/jritsema/s3lib
s3, err := s3lib.NewClient("my-bucket", "us-east-1")
check(err)

//save an object
obj := &myType{version: "1.0"}
key := "mykey"
err = s3.PutObject(key, obj)
check(err)

//fetch
_, err = s3.GetObject(key, obj)
check(err)

//update
obj.version = "2.0"
err = s3.PutObject(key, obj)
check(err)

//delete
err = s3.DeleteObject(key)
check(err)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Bucket string
	Region string
	// contains filtered or unexported fields
}

Client is an s3 client

func NewClient

func NewClient(bucket, region string) (*Client, error)

NewClient creates a new client with a bucket and optional region

func NewClientWithConfig

func NewClientWithConfig(bucket string, config aws.Config) (*Client, error)

NewClientWithConfig creates a new client based on a bucket and config

func NewClientWithSession

func NewClientWithSession(bucket string, s *session.Session) *Client

NewClientWithSession creates a new client based on a bucket and a session

func (*Client) BucketKeyExists

func (c *Client) BucketKeyExists(bucket, key string) (bool, error)

BucketKeyExists checks if an S3 bucket and key exists

func (*Client) DeleteObject

func (c *Client) DeleteObject(key string) error

DeleteObject deletes an object from S3

func (*Client) DownloadFile

func (c *Client) DownloadFile(key string, dst string) error

DownloadFile downloads a key to a file in a local directory

func (*Client) GetObject

func (c *Client) GetObject(key string, value interface{}) (bool, error)

GetObject returns an object from JSON for a key. Return false if key is not found.

func (*Client) GetPresignedURL

func (c *Client) GetPresignedURL(key string, expiration time.Duration) (string, error)

GetPresignedURL gets a presigned URL for the specified key

func (*Client) GetString

func (c *Client) GetString(key string) (string, error)

GetString returns a string representation of a key

func (*Client) KeyExists

func (c *Client) KeyExists(key string) (bool, error)

KeyExists checks if a key exists

func (*Client) List

func (c *Client) List(prefix string) (*s3.ListObjectsV2Output, error)

List lists bucket keys with an optional prefix filter

func (*Client) PutContent

func (c *Client) PutContent(key string, body io.ReadSeeker, contentType string) error

PutContent writes content to a key

func (*Client) PutObject

func (c *Client) PutObject(key string, value interface{}) error

PutObject marshals an object to JSON and writes it to a key

func (*Client) UploadDirectory

func (c *Client) UploadDirectory(prefix string, dir string) error

UploadDirectory uploads a local directory to s3

func (*Client) UploadFile

func (c *Client) UploadFile(prefix string, dir string, filePath string) error

UploadFile uploads a file to s3

Jump to

Keyboard shortcuts

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