Use constants
This commit is contained in:
parent
ce5f1ea0a1
commit
fb10a7ac5a
6 changed files with 19 additions and 10 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
8
main.go
8
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)
|
||||
|
|
Loading…
Reference in a new issue