babys3

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 13 Imported by: 0

README

Baby S3

This a simple interface to some common S3 tasks.

For example:

import (
    s3 "github.com/meowgorithm/baby-s3"
)

func main() {
    if err := s3.CreateBucket("my-cute-bucket"); err != nil  {
        fmt.Println("It didn't work :(", err)
        return
    }

    if err := s3.MakeBucketPublic("my-cute-bucket"); err != nil {
        fmt.Println("It didn't work. Weird :/", err)
    }

    err := s3.UploadObject("my-cute-bucket", "some-bytes.txt", []byte("a few nice bytes"));
    err != nil {
        fmt.Println("Nope :(", err)
    }
}

⚠️ For now, this library is in an alpha state and the API could change. If you have any thoughts about the API do let me know.

AWS Keys and Regions and Stuff

AWS loves it when you put settings in environment variables, so you'll need to do that to work with this library. Set the following:

AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY
AWS_REGION

Dependencies

This only dependency of this library is github.com/aws/aws-sdk-go. More details can be found in Gopkg.toml. If you use dep to manage your dependencies the AWS SDK will be installed automatically.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BucketExists

func BucketExists(name string) (exists bool, err error)

BucketExists determines if a given bucket exists

func CreateBucket

func CreateBucket(name string) error

CreateBucket creates a new S3 bucket. At the time of writing (2018/05/14) creating a bucket that exists and is owned by you will succeed silently.

func DeleteBucket

func DeleteBucket(name string) error

DeleteBucket does exactly that

func DeleteObject

func DeleteObject(bucket, filename string) error

DeleteObject deletes an object from an S3 bucket

func HeadObject

func HeadObject(bucket, filename string) (*s3.HeadObjectOutput, error)

HeadObject fetches simple information about about an object without actually fetching the object.

For information on what exactly is returned see: https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#HeadObjectOutput

func MakeBucketPublic

func MakeBucketPublic(name string) error

MakeBucketPublic makes a bucket publicly readable over HTTP/HTTPS

func ObjectExists

func ObjectExists(bucket, filename string) (exists bool, err error)

ObjectExists returns true if the object exists on S3, and false if not

func RandomBucketName

func RandomBucketName() string

RandomBucketName creates a random string valid for AWS bucket names. Note that bucket names must be between 3 and 63 characters. Here, we're doing it 32 characters in length, because 32 is a cool number.

func UploadObject

func UploadObject(bucket, filename string, data []byte) (err error)

UploadObject uploads a given file to an S3 bucket

func UploadObjectAsBase64

func UploadObjectAsBase64(bucket, filename, base64Data string) (err error)

UploadObjectAsBase64 uploads base64 data to a given S3 bucket. It's just a convenience function for `UploadObject()`

Types

This section is empty.

Jump to

Keyboard shortcuts

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