updated readme & go formatted code

This commit is contained in:
Remco 2014-10-20 14:54:42 +02:00
parent 16ad1833d2
commit b8eaf23805
4 changed files with 92 additions and 91 deletions

View file

@ -1,6 +1,8 @@
# transfer.sh # transfer.sh
Easy and fast file sharing from the command-line. This code contains the server with everything you need to create your own instance. Transfer.sh currently runs on top of Amazon S3. Other storage types will be added shortly. Easy and fast file sharing from the command-line. This code contains the server with everything you need to create your own instance.
Transfer.sh support currently the s3 (Amazon S3) provider and local file system (local).
[![Build Status](https://travis-ci.org/dutchcoders/transfer.sh.svg?branch=master)](https://travis-ci.org/dutchcoders/transfer.sh) [![Build Status](https://travis-ci.org/dutchcoders/transfer.sh.svg?branch=master)](https://travis-ci.org/dutchcoders/transfer.sh)

View file

@ -38,19 +38,19 @@ import (
"github.com/golang/gddo/httputil/header" "github.com/golang/gddo/httputil/header"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/kennygrant/sanitize" "github.com/kennygrant/sanitize"
html_template "html/template"
"io" "io"
"io/ioutil" "io/ioutil"
"strconv"
"log" "log"
"math/rand" "math/rand"
"mime" "mime"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"time"
html_template "html/template"
text_template "text/template" text_template "text/template"
"time"
) )
func healthHandler(w http.ResponseWriter, r *http.Request) { func healthHandler(w http.ResponseWriter, r *http.Request) {
@ -275,7 +275,7 @@ func putHandler(w http.ResponseWriter, r *http.Request) {
contentType = mime.TypeByExtension(filepath.Ext(vars["filename"])) contentType = mime.TypeByExtension(filepath.Ext(vars["filename"]))
} }
token := Encode(10000000+int64(rand.Intn(1000000000))) token := Encode(10000000 + int64(rand.Intn(1000000000)))
log.Printf("Uploading %s %d %s", token, filename, contentLength, contentType) log.Printf("Uploading %s %d %s", token, filename, contentLength, contentType)

View file

@ -1,12 +1,12 @@
package main package main
import ( import (
"io"
"github.com/goamz/goamz/s3"
"strconv"
"fmt" "fmt"
"github.com/goamz/goamz/s3"
"io"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
) )
type Storage interface { type Storage interface {
@ -20,10 +20,9 @@ type LocalStorage struct {
} }
func NewLocalStorage(basedir string) (*LocalStorage, error) { func NewLocalStorage(basedir string) (*LocalStorage, error) {
return &LocalStorage {basedir: basedir}, nil return &LocalStorage{basedir: basedir}, nil
} }
func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) { func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) {
path := filepath.Join(s.basedir, token, filename) path := filepath.Join(s.basedir, token, filename)
@ -78,7 +77,7 @@ func NewS3Storage() (*S3Storage, error) {
return nil, err return nil, err
} }
return &S3Storage {bucket: bucket}, nil return &S3Storage{bucket: bucket}, nil
} }
func (s *S3Storage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) { func (s *S3Storage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) {