s3

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

AWS S3

package main

import (
    "context"

    "github.com/joshqu1985/fireman/configor"
    "github.com/joshqu1985/fireman/store/s3"
)

type Config struct {
    S3       s3.Config
}

var (
    Conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
        panic(err)
    }
}

func main() {
    pool := s3.NewPool(Conf.S3)

    var data []byte
    handle := func(client *s3.S3Client) error {
        _, err := client.Client.PutObject(&s3.PutObjectInput{
            Key:         aws.String("/image/original/1.jpg"),
            Body:        bytes.NewReader(data),
            Bucket:      aws.String(client.Bucket),
            ACL:         aws.String(client.ACL),
            ContentType: aws.String("image/jpeg"),
        })
        return err
    }
    err := pool.Doit(context.Background(), "image", handle)

    fmt.Prinln(err)
}
#conf.toml
[s3]
    host = "us-east-2"
    [[s3.buckets]]
        acl    = "private"
        bucket = "image"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BkConfig

type BkConfig struct {
	ACL    string `toml:"acl"`
	Bucket string `toml:"bucket"`
}

type Config

type Config struct {
	Host    string     `toml:"host"`
	Buckets []BkConfig `toml:"buckets"`
}

type DeleteObjectInput

type DeleteObjectInput = s3.DeleteObjectInput

type Pool

type Pool struct {
	Clients map[string]*S3Client
}

func NewPool

func NewPool(conf Config) *Pool

func (*Pool) Doit

func (p *Pool) Doit(c context.Context, bucket string, h func(*S3Client) error) error

type PutObjectInput

type PutObjectInput = s3.PutObjectInput

type S3Client

type S3Client struct {
	Client *s3.S3
	ACL    string // s3 acl for uploaded files - for our use either "public" or "private"
	Bucket string // s3 bucket to upload to
}

Jump to

Keyboard shortcuts

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