Skip to content

Instantly share code, notes, and snippets.

@otterley
Created March 2, 2017 04:52
Show Gist options
  • Save otterley/ed6e95b7771e1479d56c858d63b4ffc6 to your computer and use it in GitHub Desktop.
Save otterley/ed6e95b7771e1479d56c858d63b4ffc6 to your computer and use it in GitHub Desktop.
s3gof3r example
package main
import (
"compress/gzip"
"io"
"log"
"net/http"
"os"
"github.com/rlmcpherson/s3gof3r"
)
func main() {
keys, err := s3gof3r.EnvKeys()
if err != nil {
log.Fatal(err)
}
s3 := s3gof3r.New("s3-endpoint.amazonaws.com", keys)
bucket := s3.Bucket("myBucket")
w, err := bucket.PutWriter("myObject", http.Header{}, nil)
if err != nil {
log.Fatal(err)
}
defer w.Close()
zw := gzip.NewWriter(w)
defer zw.Close()
f, err := os.Open("/path/to/file")
if err != nil {
log.Fatal(err)
}
defer f.Close()
_, err = io.Copy(zw, f)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment