Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
/ gostorages Public archive
forked from ulule/gostorages

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

License

Notifications You must be signed in to change notification settings

lizdeika/gostorages

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 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/thoas/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/thoas/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/thoas/gostorages"
    "github.com/lizdeika/goamz/aws"
    "github.com/lizdeika/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

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.7%
  • Makefile 1.3%