diff --git a/bucket-view.go b/bucket-view.go index 1e96423..4452cf2 100644 --- a/bucket-view.go +++ b/bucket-view.go @@ -27,8 +27,8 @@ func BucketViewHandler(s3 S3Client) http.Handler { bucketName := mux.Vars(r)["bucketName"] var objs []ObjectWithIcon - l := path.Join("templates", "layout.html.tmpl") - p := path.Join("templates", "bucket.html.tmpl") + l := path.Join(tmplDirectory, "layout.html.tmpl") + p := path.Join(tmplDirectory, "bucket.html.tmpl") t, err := template.ParseFiles(l, p) if err != nil { diff --git a/buckets-view.go b/buckets-view.go index 205f6ab..e1eda44 100644 --- a/buckets-view.go +++ b/buckets-view.go @@ -9,8 +9,8 @@ import ( // BucketsViewHandler shows all buckets func BucketsViewHandler(s3 S3Client) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - l := path.Join("templates", "layout.html.tmpl") - p := path.Join("templates", "buckets.html.tmpl") + l := path.Join(tmplDirectory, "layout.html.tmpl") + p := path.Join(tmplDirectory, "buckets.html.tmpl") t, err := template.ParseFiles(l, p) if err != nil { diff --git a/create-bucket.go b/create-bucket.go index 2fadbf7..6a387b7 100644 --- a/create-bucket.go +++ b/create-bucket.go @@ -26,7 +26,7 @@ func CreateBucketHandler(s3 S3Client) http.Handler { return } - w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set(headerContentType, contentTypeJSON) w.WriteHeader(http.StatusCreated) err = json.NewEncoder(w).Encode(bucket) diff --git a/create-object.go b/create-object.go index 7b90465..84476f7 100644 --- a/create-object.go +++ b/create-object.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "github.com/gorilla/mux" minio "github.com/minio/minio-go" @@ -22,7 +23,7 @@ func CreateObjectHandler(s3 S3Client) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - if r.Header.Get("Content-Type") == "application/json" { + if strings.Contains(r.Header.Get(headerContentType), contentTypeJSON) { var copy CopyObjectInfo err := json.NewDecoder(r.Body).Decode(©) @@ -41,7 +42,7 @@ func CreateObjectHandler(s3 S3Client) http.Handler { return } - w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set(headerContentType, contentTypeJSON) w.WriteHeader(http.StatusCreated) err = json.NewEncoder(w).Encode(copy) @@ -66,7 +67,7 @@ func CreateObjectHandler(s3 S3Client) http.Handler { } defer file.Close() - _, err = s3.PutObject(vars["bucketName"], handler.Filename, file, "application/octet-stream") + _, err = s3.PutObject(vars["bucketName"], handler.Filename, file, contentTypeOctetStream) if err != nil { msg := "error putting object" handleHTTPError(w, msg, err, http.StatusInternalServerError) diff --git a/get-object.go b/get-object.go index 6801942..82260a8 100644 --- a/get-object.go +++ b/get-object.go @@ -21,8 +21,8 @@ func GetObjectHandler(s3 S3Client) http.Handler { return } - w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", objectName)) - w.Header().Set("Content-Type", "application/octet-stream") + w.Header().Set(headerContentDisposition, fmt.Sprintf("attachment; filename=\"%s\"", objectName)) + w.Header().Set(headerContentType, contentTypeOctetStream) _, err = io.Copy(w, object) if err != nil { diff --git a/main.go b/main.go index 1663f8f..5d875d9 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,14 @@ import ( "github.com/mastertinner/adapters/logging" ) +const ( + tmplDirectory = "templates" + headerContentType = "Content-Type" + headerContentDisposition = "Content-Disposition" + contentTypeJSON = "application/json" + contentTypeOctetStream = "application/octet-stream" +) + func main() { s3 := newMinioClient() logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)