s3

package
v0.0.0-...-974551f Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: GPL-3.0 Imports: 21 Imported by: 0

README

AWS S3

AWS S3 backend for MayCMF OSS

Usage

import "github.com/MayCMF/oss/awss3"

func main() {
  storage := s3.New(s3.Config{
    AccessID: "access_id",
    AccessKey: "access_key",
    Region: "region",
    Bucket: "bucket",
    Endpoint: "cdn.example.com",
    ACL: awss3.BucketCannedACLPublicRead,
  })

  // Save a reader interface into storage
  storage.Put("/example.txt", reader)

  // Get file with path
  storage.Get("/example.txt")

  // Get object as io.ReadCloser
  storage.GetStream("/example.txt")

  // Delete file with path
  storage.Delete("/example.txt")

  // List all objects under path
  storage.List("/")

  // Get Public Accessible URL (useful if current file saved privately)
  storage.GetURL("/example.txt")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EC2RoleAwsConfig

func EC2RoleAwsConfig(config *Config) *aws.Config

Does this need to be publicly exported?

Types

type Client

type Client struct {
	*s3.S3
	Config *Config
}

Client S3 storage

func New

func New(config *Config) *Client

New initialize S3 storage

func (Client) Delete

func (client Client) Delete(path string) error

Delete delete file

func (Client) Get

func (client Client) Get(path string) (file *os.File, err error)

Get receive file with given path

func (Client) GetEndpoint

func (client Client) GetEndpoint() string

GetEndpoint get endpoint, FileSystem's endpoint is /

func (Client) GetStream

func (client Client) GetStream(path string) (io.ReadCloser, error)

GetStream get file as stream

func (Client) GetURL

func (client Client) GetURL(path string) (url string, err error)

GetURL get public accessible URL

func (Client) List

func (client Client) List(path string) ([]*ofs.Object, error)

List list all objects under current path

func (Client) Put

func (client Client) Put(urlPath string, reader io.Reader) (*ofs.Object, error)

Put store a reader into given path

func (Client) ToRelativePath

func (client Client) ToRelativePath(urlPath string) string

ToRelativePath process path to relative path

type Config

type Config struct {
	AccessID         string
	AccessKey        string
	Region           string
	Bucket           string
	SessionToken     string
	ACL              string
	Endpoint         string
	S3Endpoint       string
	S3ForcePathStyle bool
	CacheControl     string

	Session *session.Session

	RoleARN string
}

Config S3 client config

Jump to

Keyboard shortcuts

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