Git Product home page Git Product logo

gostorages's Introduction

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:

This particular storage can be used to store JPG and PNG images only at the moment.

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.

gostorages's People

Contributors

thoas avatar juliengroch avatar kyojin avatar

Stargazers

Dobrosław Żybort avatar

Watchers

James Cloos avatar

Forkers

landanan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.