aws_manager

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

README

PaySuper AWS S3 manager wrapper

Build Status codecov go report

Environment variables:

Name Required Default Description
AWS_ACCESS_KEY_ID true - AWS access key identifier
AWS_SECRET_ACCESS_KEY true - AWS access secret key
AWS_BUCKET true - AWS bucket name
AWS_REGION - eu-west-1 AWS region
AWS_TOKEN - "" AWS region

Usage example

package main

import (
    "context"
    awsWrapper "github.com/paysuper/paysuper-aws-manager"
    "log"
    "os"
)

func main() {
    awsManager, err := awsWrapper.New()
    
    if err != nil {
        log.Fatalln(err)
    }
    
    //upload open file
    file, err := os.Open("/tmp/file.pdf")
    defer file.Close()

    out := &awsWrapper.UploadInput{
        Body:     file,
        FileName: "file.pdf",
    }
    _, err = awsManager.Upload(context.TODO(), out)

    if err != nil {
        log.Fatalln(err)    
    }
    
    log.Println("file upload successfully")

    //upload file by path
    uploadReq := &awsWrapper.UploadInput{
        Path:     "/tmp/file.pdf",
        FileName: "file.pdf",
    }
    _, err = awsManager.Upload(context.TODO(), uploadReq)

    if err != nil {
        log.Fatalln(err)    
    }
    
    log.Println("file upload successfully")

    // download file
    filePath := os.TempDir() + string(os.PathSeparator) + "file.pdf"
    downloadReq := &awsWrapper.DownloadInput{
        FileName: "file.pdf",
    }
    _, err = awsManager.Download(context.TODO(), filePath, downloadReq)
    
    if err != nil {
        log.Fatalln(err)    
    }
    
    log.Println("file download successfully")
}

Re-Build mocks for package

REQUIRED: package mockery must be installed before run next command

mockery -name AwsManagerInterface -output ./pkg/mocks

Contributing

We feel that a welcoming community is important and we ask that you follow PaySuper's Open Source Code of Conduct in all interactions with the community.

PaySuper welcomes contributions from anyone and everyone. Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

The master branch of this repository contains the latest stable release of this component.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AwsManager

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

func (*AwsManager) Download

func (m *AwsManager) Download(
	ctx context.Context,
	path string,
	in *DownloadInput,
	opts ...func(*s3manager.Downloader),
) (int64, error)

func (*AwsManager) Upload

func (m *AwsManager) Upload(
	ctx context.Context,
	in *UploadInput,
	opts ...func(*s3manager.Uploader),
) (*s3manager.UploadOutput, error)

type AwsManagerInterface

type AwsManagerInterface interface {
	Upload(context.Context, *UploadInput, ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error)
	Download(context.Context, string, *DownloadInput, ...func(*s3manager.Downloader)) (int64, error)
}

func New

func New(options ...Option) (AwsManagerInterface, error)

type DownloadInput

type DownloadInput struct {
	Bucket                     string
	IfMatch                    string
	IfModifiedSince            time.Time
	IfNoneMatch                string
	IfUnmodifiedSince          time.Time
	FileName                   string
	PartNumber                 *int64
	Range                      string
	RequestPayer               string
	ResponseCacheControl       string
	ResponseContentDisposition string
	ResponseContentEncoding    string
	ResponseContentLanguage    string
	ResponseContentType        string
	ResponseExpires            time.Time
	SSECustomerAlgorithm       string
	SSECustomerKey             string
	SSECustomerKeyMD5          string
	VersionId                  string
}

type Option

type Option func(*Options)

func AccessKeyId

func AccessKeyId(accessKeyId string) Option

func Bucket

func Bucket(bucket string) Option

func Region

func Region(region string) Option

func SecretAccessKey

func SecretAccessKey(secretAccessKey string) Option

func Token

func Token(token string) Option

type Options

type Options struct {
	AccessKeyId     string `envconfig:"AWS_ACCESS_KEY_ID" required:"true"`
	SecretAccessKey string `envconfig:"AWS_SECRET_ACCESS_KEY" required:"true"`
	Region          string `envconfig:"AWS_REGION" default:"eu-west-1"`
	Bucket          string `envconfig:"AWS_BUCKET" required:"true"`
	Token           string `envconfig:"AWS_TOKEN" default:""`
}

func (*Options) HasEmptySettings

func (opts *Options) HasEmptySettings() bool

type UploadInput

type UploadInput struct {
	ACL                       string
	Body                      io.Reader
	Path                      string
	Bucket                    string
	CacheControl              string
	ContentDisposition        string
	ContentEncoding           string
	ContentLanguage           string
	ContentMD5                string
	ContentType               string
	Expires                   time.Time
	GrantFullControl          string
	GrantRead                 string
	GrantReadACP              string
	GrantWriteACP             string
	FileName                  string
	Metadata                  map[string]string
	ObjectLockLegalHoldStatus string
	ObjectLockMode            string
	ObjectLockRetainUntilDate time.Time
	RequestPayer              string
	SSECustomerAlgorithm      string
	SSECustomerKey            string
	SSECustomerKeyMD5         string
	SSEKMSEncryptionContext   string
	SSEKMSKeyId               string
	ServerSideEncryption      string
	StorageClass              string
	Tagging                   string
	WebsiteRedirectLocation   string
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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