+
Skip to content

ulule/gostorages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gostorages

A unified interface to manipulate storage engine for Go.

gostorages is used in picfit to allow us switching over storage engine.

Currently, it supports the following storages:

  • Amazon S3
  • File system

Installation

Just run:

$ go get github.com/ulule/gostorages

Usage

It offers you a single API to manipulate your files on multiple storages.

If you are migrating from a File system storage to an Amazon S3, you don't need to migrate all your methods anymore!

Be lazy again!

File system

To use the FileSystemStorage you must have a location to save your files.

package main

import (
    "fmt"
    "github.com/ulule/gostorages"
    "os"
)

func main() {
    tmp := os.TempDir()

    storage := gostorages.NewFileSystemStorage(tmp, "http://img.example.com")

    // Saving a file named test
    storage.Save("test", gostorages.NewContentFile([]byte("(╯°□°)╯︵ ┻━┻")))

    fmt.Println(storage.URL("test")) // => http://img.example.com/test

    // Deleting the new file on the storage
    storage.Delete("test")
}

Amazon S3

To use the S3Storage you must have:

  • An access key id
  • A secret access key
  • A bucket name
  • Give the region of your bucket
  • Give the ACL you want to use

You can find your credentials in Security credentials.

In the following example, I'm assuming my bucket is located in european region.

package main

import (
    "fmt"
    "github.com/ulule/gostorages"
    "github.com/mitchellh/goamz/aws"
    "github.com/mitchellh/goamz/s3"
    "os"
)

func main() {
    baseURL := "http://s3-eu-west-1.amazonaws.com/my-bucket"

    storage := gostorages.NewS3Storage(os.Getenv("ACCESS_KEY_ID"), os.Getenv("SECRET_ACCESS_KEY"), "my-bucket", "", aws.Regions["eu-west-1"], s3.PublicReadWrite, baseURL)

    // Saving a file named test
    storage.Save("test", gostorages.NewContentFile([]byte("(>_<)")))

    fmt.Println(storage.URL("test")) // => http://s3-eu-west-1.amazonaws.com/my-bucket/test

    // Deleting the new file on the storage
    storage.Delete("test")
}

Roadmap

see issues

Don't hesitate to send patch or improvements.

About

A unified interface to manipulate storage engine (file system, s3, etc.) for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载