From 540723d7aebba0b78a92a19de31a672b47debf94 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 5 Mar 2015 21:07:19 -0800 Subject: [PATCH] Golint cleanup pkg/api --- pkg/api/minioapi/api_test.go | 24 +++++----- pkg/api/minioapi/bucket_handlers.go | 24 +++++----- pkg/api/minioapi/definitions.go | 8 ++-- pkg/api/minioapi/error_response.go | 66 ++++++++++++++-------------- pkg/api/minioapi/generic_handlers.go | 10 ++--- pkg/api/minioapi/muxer.go | 14 +++--- pkg/api/minioapi/object_handlers.go | 28 ++++++------ pkg/api/minioapi/policy_handlers.go | 22 +++++----- pkg/api/minioapi/response.go | 10 ++--- pkg/api/webuiapi/webuiapi.go | 14 +++--- pkg/server/httpserver/httpserver.go | 13 +++--- pkg/server/server.go | 36 ++++++++------- pkg/storage/fs/fs.go | 2 +- pkg/storage/inmemory/inmemory.go | 6 +-- pkg/storage/storage_errors.go | 2 +- 15 files changed, 144 insertions(+), 135 deletions(-) diff --git a/pkg/api/minioapi/api_test.go b/pkg/api/minioapi/api_test.go index de37a7281..0ef96e88d 100644 --- a/pkg/api/minioapi/api_test.go +++ b/pkg/api/minioapi/api_test.go @@ -41,7 +41,7 @@ var _ = Suite(&MySuite{}) func (s *MySuite) TestNonExistantObject(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -53,7 +53,7 @@ func (s *MySuite) TestNonExistantObject(c *C) { func (s *MySuite) TestEmptyObject(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -78,7 +78,7 @@ func (s *MySuite) TestEmptyObject(c *C) { func (s *MySuite) TestObject(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -101,7 +101,7 @@ func (s *MySuite) TestObject(c *C) { func (s *MySuite) TestMultipleObjects(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -181,7 +181,7 @@ func (s *MySuite) TestMultipleObjects(c *C) { func (s *MySuite) TestNotImplemented(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -192,7 +192,7 @@ func (s *MySuite) TestNotImplemented(c *C) { func (s *MySuite) TestHeader(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -215,7 +215,7 @@ func (s *MySuite) TestHeader(c *C) { func (s *MySuite) TestPutBucket(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -240,7 +240,7 @@ func (s *MySuite) TestPutBucket(c *C) { func (s *MySuite) TestPutObject(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -297,7 +297,7 @@ func (s *MySuite) TestPutObject(c *C) { func (s *MySuite) TestListBuckets(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -376,7 +376,7 @@ func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentTy func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -401,7 +401,7 @@ func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) { func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -426,7 +426,7 @@ func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) { func (s *MySuite) TestContentTypePersists(c *C) { _, _, storage := inmemory.Start() - httpHandler := HttpHandler("", storage) + httpHandler := HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() diff --git a/pkg/api/minioapi/bucket_handlers.go b/pkg/api/minioapi/bucket_handlers.go index ef7a743bc..a19288baf 100644 --- a/pkg/api/minioapi/bucket_handlers.go +++ b/pkg/api/minioapi/bucket_handlers.go @@ -30,7 +30,7 @@ import ( // of the objects in a bucket. You can use the request parameters as selection // criteria to return a subset of the objects in a bucket. // -func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) bucket := vars["bucket"] @@ -56,7 +56,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ { error := errorCodeError(NoSuchBucket) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ImplementationError: @@ -65,21 +65,21 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNameInvalid: { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ObjectNameInvalid: { error := errorCodeError(NoSuchKey) errorResponse := getErrorResponse(error, resources.Prefix) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -89,7 +89,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ // ----------- // This implementation of the GET operation returns a list of all buckets // owned by the authenticated sender of the request. -func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Request) { acceptsContentType := getContentType(req) buckets, err := server.storage.ListBuckets() switch err := err.(type) { @@ -103,7 +103,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BackendCorrupted: @@ -111,7 +111,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -120,7 +120,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ // PUT Bucket // ---------- // This implementation of the PUT operation creates a new bucket for authenticated request -func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) bucket := vars["bucket"] err := server.storage.StoreBucket(bucket) @@ -142,14 +142,14 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketExists: { error := errorCodeError(BucketAlreadyExists) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ImplementationError: @@ -158,7 +158,7 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } diff --git a/pkg/api/minioapi/definitions.go b/pkg/api/minioapi/definitions.go index bdafe5ab6..ac2a5d11b 100644 --- a/pkg/api/minioapi/definitions.go +++ b/pkg/api/minioapi/definitions.go @@ -38,7 +38,7 @@ type ObjectListResponse struct { CommonPrefixes []*Prefix } -// Bucket list response format +// BucketListResponse - bucket list response format type BucketListResponse struct { XMLName xml.Name `xml:"ListAllMyBucketsResult" json:"-"` Owner Owner @@ -47,17 +47,18 @@ type BucketListResponse struct { } // Buckets are nested } +// Prefix - common prefix type Prefix struct { Prefix string } -// Bucket struct +// Bucket - bucket item type Bucket struct { Name string CreationDate string } -// Object struct +// Item - object item type Item struct { Key string LastModified string @@ -67,6 +68,7 @@ type Item struct { Owner Owner } +// Owner - bucket owner/principal type Owner struct { ID string DisplayName string diff --git a/pkg/api/minioapi/error_response.go b/pkg/api/minioapi/error_response.go index 019b88058..e175cf991 100644 --- a/pkg/api/minioapi/error_response.go +++ b/pkg/api/minioapi/error_response.go @@ -25,17 +25,17 @@ import ( type Error struct { Code string Description string - HttpStatusCode int + HTTPStatusCode int } -// Error response format +// ErrorResponse - error response format type ErrorResponse struct { XMLName xml.Name `xml:"Error" json:"-"` Code string Message string Resource string - RequestId string - HostId string + RequestID string + HostID string } // Error codes, non exhaustive list @@ -47,7 +47,7 @@ const ( EntityTooLarge IncompleteBody InternalError - InvalidAccessKeyId + InvalidAccessKeyID InvalidBucketName InvalidDigest InvalidRange @@ -70,117 +70,117 @@ var errorCodeResponse = map[int]Error{ AccessDenied: { Code: "AccessDenied", Description: "Access Denied", - HttpStatusCode: http.StatusForbidden, + HTTPStatusCode: http.StatusForbidden, }, BadDigest: { Code: "BadDigest", Description: "The Content-MD5 you specified did not match what we received.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, BucketAlreadyExists: { Code: "BucketAlreadyExists", Description: "The requested bucket name is not available.", - HttpStatusCode: http.StatusConflict, + HTTPStatusCode: http.StatusConflict, }, EntityTooSmall: { Code: "EntityTooSmall", Description: "Your proposed upload is smaller than the minimum allowed object size.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, EntityTooLarge: { Code: "EntityTooLarge", Description: "Your proposed upload exceeds the maximum allowed object size.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, IncompleteBody: { Code: "IncompleteBody", Description: "You did not provide the number of bytes specified by the Content-Length HTTP header", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, InternalError: { Code: "InternalError", Description: "We encountered an internal error, please try again.", - HttpStatusCode: http.StatusInternalServerError, + HTTPStatusCode: http.StatusInternalServerError, }, - InvalidAccessKeyId: { - Code: "InvalidAccessKeyId", - Description: "The access key Id you provided does not exist in our records.", - HttpStatusCode: http.StatusForbidden, + InvalidAccessKeyID: { + Code: "InvalidAccessKeyID", + Description: "The access key ID you provided does not exist in our records.", + HTTPStatusCode: http.StatusForbidden, }, InvalidBucketName: { Code: "InvalidBucketName", Description: "The specified bucket is not valid.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, InvalidDigest: { Code: "InvalidDigest", Description: "The Content-MD5 you specified is not valid.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, InvalidRange: { Code: "InvalidRange", Description: "The requested range cannot be satisfied.", - HttpStatusCode: http.StatusRequestedRangeNotSatisfiable, + HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable, }, MalformedXML: { Code: "MalformedXML", Description: "The XML you provided was not well-formed or did not validate against our published schema.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, MissingContentLength: { Code: "MissingContentLength", Description: "You must provide the Content-Length HTTP header.", - HttpStatusCode: http.StatusLengthRequired, + HTTPStatusCode: http.StatusLengthRequired, }, MissingRequestBodyError: { Code: "MissingRequestBodyError", Description: "Request body is empty.", - HttpStatusCode: http.StatusLengthRequired, + HTTPStatusCode: http.StatusLengthRequired, }, NoSuchBucket: { Code: "NoSuchBucket", Description: "The specified bucket does not exist.", - HttpStatusCode: http.StatusNotFound, + HTTPStatusCode: http.StatusNotFound, }, NoSuchKey: { Code: "NoSuchKey", Description: "The specified key does not exist.", - HttpStatusCode: http.StatusNotFound, + HTTPStatusCode: http.StatusNotFound, }, NoSuchUpload: { Code: "NoSuchUpload", Description: "The specified multipart upload does not exist.", - HttpStatusCode: http.StatusNotFound, + HTTPStatusCode: http.StatusNotFound, }, NotImplemented: { Code: "NotImplemented", Description: "A header you provided implies functionality that is not implemented.", - HttpStatusCode: http.StatusNotImplemented, + HTTPStatusCode: http.StatusNotImplemented, }, RequestTimeTooSkewed: { Code: "RequestTimeTooSkewed", Description: "The difference between the request time and the server's time is too large.", - HttpStatusCode: http.StatusForbidden, + HTTPStatusCode: http.StatusForbidden, }, SignatureDoesNotMatch: { Code: "SignatureDoesNotMatch", Description: "The request signature we calculated does not match the signature you provided.", - HttpStatusCode: http.StatusForbidden, + HTTPStatusCode: http.StatusForbidden, }, TooManyBuckets: { Code: "TooManyBuckets", Description: "You have attempted to create more buckets than allowed.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, InvalidPolicyDocument: { Code: "InvalidPolicyDocument", Description: "The content of the form does not meet the conditions specified in the policy document.", - HttpStatusCode: http.StatusBadRequest, + HTTPStatusCode: http.StatusBadRequest, }, NoSuchBucketPolicy: { Code: "NoSuchBucketPolicy", Description: "The specified bucket does not have a bucket policy.", - HttpStatusCode: http.StatusNotFound, + HTTPStatusCode: http.StatusNotFound, }, } @@ -199,8 +199,8 @@ func getErrorResponse(err Error, resource string) ErrorResponse { data.Resource = resource } // TODO implement this in future - data.RequestId = "3L137" - data.HostId = "3L137" + data.RequestID = "3L137" + data.HostID = "3L137" return data } diff --git a/pkg/api/minioapi/generic_handlers.go b/pkg/api/minioapi/generic_handlers.go index 56f3e704a..78865de83 100644 --- a/pkg/api/minioapi/generic_handlers.go +++ b/pkg/api/minioapi/generic_handlers.go @@ -60,14 +60,14 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err := h.conf.ReadConfig(); err != nil { error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { user, ok := h.conf.Users[accessKey] if ok == false { error := errorCodeError(AccessDenied) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { ok, _ = signers.ValidateRequest(user, r) @@ -76,7 +76,7 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } else { error := errorCodeError(AccessDenied) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -91,7 +91,7 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // ## Uncommented below links of code after disabling anonymous requests // error := errorCodeError(AccessDenied) // errorResponse := getErrorResponse(error, "") - // w.WriteHeader(error.HttpStatusCode) + // w.WriteHeader(error.HTTPStatusCode) // w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -109,7 +109,7 @@ func (h rHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) { error := errorCodeError(NotImplemented) errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { h.handler.ServeHTTP(w, r) diff --git a/pkg/api/minioapi/muxer.go b/pkg/api/minioapi/muxer.go index ce0fb2552..bdd2f06b1 100644 --- a/pkg/api/minioapi/muxer.go +++ b/pkg/api/minioapi/muxer.go @@ -26,13 +26,13 @@ import ( ) // private use -type minioApi struct { +type minioAPI struct { domain string storage mstorage.Storage } // Path based routing -func pathMux(api minioApi, mux *x.Router) *x.Router { +func pathMux(api minioAPI, mux *x.Router) *x.Router { mux.HandleFunc("/", api.listBucketsHandler).Methods("GET") mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET") mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT") @@ -44,7 +44,7 @@ func pathMux(api minioApi, mux *x.Router) *x.Router { } // Domain based routing -func domainMux(api minioApi, mux *x.Router) *x.Router { +func domainMux(api minioAPI, mux *x.Router) *x.Router { mux.HandleFunc("/", api.listObjectsHandler).Host("{bucket}" + "." + api.domain).Methods("GET") mux.HandleFunc("/{object:.*}", @@ -60,7 +60,7 @@ func domainMux(api minioApi, mux *x.Router) *x.Router { } // Get proper router based on domain availability -func getMux(api minioApi, mux *x.Router) *x.Router { +func getMux(api minioAPI, mux *x.Router) *x.Router { switch true { case api.domain == "": return pathMux(api, mux) @@ -71,10 +71,10 @@ func getMux(api minioApi, mux *x.Router) *x.Router { return nil } -// Http wrapper handler -func HttpHandler(domain string, storage mstorage.Storage) http.Handler { +// HTTPHandler - http wrapper handler +func HTTPHandler(domain string, storage mstorage.Storage) http.Handler { var mux *x.Router - var api = minioApi{} + var api = minioAPI{} api.storage = storage api.domain = domain diff --git a/pkg/api/minioapi/object_handlers.go b/pkg/api/minioapi/object_handlers.go index 3f0a74474..e9f3565ac 100644 --- a/pkg/api/minioapi/object_handlers.go +++ b/pkg/api/minioapi/object_handlers.go @@ -28,7 +28,7 @@ import ( // ---------- // This implementation of the GET operation retrieves object. To use GET, // you must have READ access to the object. -func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Request) { var object, bucket string acceptsContentType := getContentType(req) @@ -50,21 +50,21 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques { error := errorCodeError(NoSuchKey) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ObjectNameInvalid: { error := errorCodeError(NoSuchKey) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNameInvalid: { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ImplementationError: @@ -73,7 +73,7 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -82,7 +82,7 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques // HEAD Object // ----------- // The HEAD operation retrieves metadata from an object without returning the object itself. -func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Request) { var object, bucket string acceptsContentType := getContentType(req) vars := mux.Vars(req) @@ -97,14 +97,14 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque { error := errorCodeError(NoSuchKey) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ObjectNameInvalid: { error := errorCodeError(NoSuchKey) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ImplementationError: @@ -113,7 +113,7 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -122,7 +122,7 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque // PUT Object // ---------- // This implementation of the PUT operation adds an object to a bucket. -func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Request) { var object, bucket string vars := mux.Vars(req) acceptsContentType := getContentType(req) @@ -146,28 +146,28 @@ func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Reques log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNotFound: { error := errorCodeError(NoSuchBucket) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNameInvalid: { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.ObjectExists: { error := errorCodeError(NotImplemented) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } diff --git a/pkg/api/minioapi/policy_handlers.go b/pkg/api/minioapi/policy_handlers.go index b5a5362f1..cb38577bc 100644 --- a/pkg/api/minioapi/policy_handlers.go +++ b/pkg/api/minioapi/policy_handlers.go @@ -30,7 +30,7 @@ import ( // ----------------- // This implementation of the PUT operation uses the policy subresource // to add to or replace a policy on a bucket -func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) putBucketPolicyHandler(w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) bucket := vars["bucket"] acceptsContentType := getContentType(req) @@ -39,7 +39,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http. if ok == false { error := errorCodeError(InvalidPolicyDocument) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) return } @@ -56,14 +56,14 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http. { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNotFound: { error := errorCodeError(NoSuchBucket) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BackendCorrupted: @@ -72,7 +72,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http. log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } @@ -82,7 +82,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http. // ----------------- // This implementation of the GET operation uses the policy subresource // to return the policy of a specified bucket. -func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http.Request) { +func (server *minioAPI) getBucketPolicyHandler(w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) bucket := vars["bucket"] acceptsContentType := getContentType(req) @@ -95,7 +95,7 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http. if ret != nil { error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } writeCommonHeaders(w, getContentString(acceptsContentType)) @@ -106,21 +106,21 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http. { error := errorCodeError(InvalidBucketName) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketNotFound: { error := errorCodeError(NoSuchBucket) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BucketPolicyNotFound: { error := errorCodeError(NoSuchBucketPolicy) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } case mstorage.BackendCorrupted: @@ -129,7 +129,7 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http. log.Println(err) error := errorCodeError(InternalError) errorResponse := getErrorResponse(error, bucket) - w.WriteHeader(error.HttpStatusCode) + w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } diff --git a/pkg/api/minioapi/response.go b/pkg/api/minioapi/response.go index d5c806e3d..898caafa3 100644 --- a/pkg/api/minioapi/response.go +++ b/pkg/api/minioapi/response.go @@ -54,16 +54,16 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResp return data } -type ItemKey []*Item +type itemKey []*Item // Len -func (b ItemKey) Len() int { return len(b) } +func (b itemKey) Len() int { return len(b) } // Swap -func (b ItemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] } +func (b itemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] } // Less -func (b ItemKey) Less(i, j int) bool { return b[i].Key < b[j].Key } +func (b itemKey) Less(i, j int) bool { return b[i].Key < b[j].Key } // takes a set of objects and prepares the objects for serialization // input: @@ -95,7 +95,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata, content.Owner = owner contents = append(contents, content) } - sort.Sort(ItemKey(contents)) + sort.Sort(itemKey(contents)) data.Name = bucket data.Contents = contents data.MaxKeys = bucketResources.Maxkeys diff --git a/pkg/api/webuiapi/webuiapi.go b/pkg/api/webuiapi/webuiapi.go index 77f8b331b..d02b28981 100644 --- a/pkg/api/webuiapi/webuiapi.go +++ b/pkg/api/webuiapi/webuiapi.go @@ -29,10 +29,10 @@ import ( ) const ( - DEFAULT_WEB = "polygon" + defaultWeb = "polygon" ) -type webUiApi struct { +type webAPI struct { conf config.Config webPath string } @@ -42,16 +42,16 @@ type encoder interface { Encode(v interface{}) error } -// Http wrapper handler -func HttpHandler() http.Handler { +// HTTPHandler - http wrapper handler +func HTTPHandler() http.Handler { mux := mux.NewRouter() - var api = webUiApi{} + var api = webAPI{} if err := api.conf.SetupConfig(); err != nil { log.Fatal(err) } - api.webPath = path.Join(api.conf.GetConfigPath(), DEFAULT_WEB) + api.webPath = path.Join(api.conf.GetConfigPath(), defaultWeb) mux.Handle("/{polygon:.*}", http.FileServer(http.Dir(api.webPath))).Methods("GET") mux.HandleFunc("/access", api.accessHandler).Methods("POST") return mux @@ -68,7 +68,7 @@ func writeResponse(w http.ResponseWriter, response interface{}) []byte { return bytesBuffer.Bytes() } -func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) { +func (web *webAPI) accessHandler(w http.ResponseWriter, req *http.Request) { var err error var accesskey, secretkey []byte username := req.FormValue("username") diff --git a/pkg/server/httpserver/httpserver.go b/pkg/server/httpserver/httpserver.go index 5a82c826f..1f83c0d9d 100644 --- a/pkg/server/httpserver/httpserver.go +++ b/pkg/server/httpserver/httpserver.go @@ -19,21 +19,22 @@ package httpserver import ( "log" "net/http" - // "time" ) -type HttpServerConfig struct { +// Config - http server config +type Config struct { Address string TLS bool CertFile string KeyFile string - Websocket bool // implement it - TODO + Websocket bool // TODO } -type HttpServer struct{} +// Server - http server related +type Server struct{} // Start http server -func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *HttpServer) { +func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *Server) { ctrlChannel := make(chan string) errorChannel := make(chan error) server := HttpServer{} @@ -42,7 +43,7 @@ func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan } func start(ctrlChannel <-chan string, errorChannel chan<- error, - router http.Handler, config HttpServerConfig, server *HttpServer) { + router http.Handler, config Config, server *Server) { var err error // Minio server config diff --git a/pkg/server/server.go b/pkg/server/server.go index 01a744c5e..ccd4e92c5 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -30,31 +30,37 @@ import ( "github.com/minio-io/minio/pkg/storage/inmemory" ) -type ServerConfig struct { +// Config - http server parameters +type Config struct { Domain string Address string - Tls bool + TLS bool CertFile string KeyFile string - ApiType interface{} + APIType interface{} } -type MinioApi struct { +// MinioAPI - storage type donut, fs, inmemory +type MinioAPI struct { StorageType StorageType } +// WebUIApi - webui related type WebUIApi struct { - Websocket bool + Websocket bool // TODO } +// StorageType - different storage types supported by minio type StorageType int +// Storage types const ( - InMemoryStorage = iota - FileStorage + InMemory = iota + File + Donut ) -func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusChans []<-chan error) { +func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans []<-chan error) { // a pair of control channels, we use these primarily to add to the lists above var ctrlChan chan<- string var statusChan <-chan error @@ -65,7 +71,7 @@ func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusC { // configure web server var storage mstorage.Storage - var httpConfig = httpserver.HttpServerConfig{} + var httpConfig = httpserver.Config{} httpConfig.Address = config.Address httpConfig.Websocket = false httpConfig.TLS = config.Tls @@ -87,7 +93,7 @@ func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusC } case WebUIApi: { - var httpConfig = httpserver.HttpServerConfig{} + var httpConfig = httpserver.Config{} httpConfig.Address = config.Address httpConfig.TLS = config.Tls httpConfig.CertFile = config.CertFile @@ -120,13 +126,13 @@ func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, sta // - ctrlChans has channel to communicate to storage // - statusChans has channel for messages coming from storage switch { - case storageType == InMemoryStorage: + case storageType == InMemory: { ctrlChan, statusChan, storage = inmemory.Start() ctrlChans = append(ctrlChans, ctrlChan) statusChans = append(statusChans, statusChan) } - case storageType == FileStorage: + case storageType == File: { u, err := user.Current() if err != nil { @@ -143,10 +149,10 @@ func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, sta return } -// Create channels -func Start(configs []ServerConfig) { +// Start - create channels +func Start(configs []Config) { // reflected looping is necessary to remove dead channels from loop and not flood switch - ctrlChans, statusChans := getHttpChannels(configs) + ctrlChans, statusChans := getHTTPChannels(configs) cases := createSelectCases(statusChans) for len(cases) > 0 { chosen, value, recvOk := reflect.Select(cases) diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go index 2d8be65f5..f2b2e8806 100644 --- a/pkg/storage/fs/fs.go +++ b/pkg/storage/fs/fs.go @@ -495,7 +495,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea if _, err := os.Stat(objectPath); !os.IsNotExist(err) { return mstorage.ObjectExists{ Bucket: bucket, - Key: key, + Object: key, } } diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 1297afcba..c0daaebab 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -78,12 +78,12 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st // Not implemented func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error { - return mstorage.ApiNotImplemented{Api: "PutBucketPolicy"} + return mstorage.APINotImplemented{API: "PutBucketPolicy"} } // Not implemented func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) { - return policy.BucketPolicy{}, mstorage.ApiNotImplemented{Api: "GetBucketPolicy"} + return policy.BucketPolicy{}, mstorage.APINotImplemented{API: "GetBucketPolicy"} } // PUT object to memory buffer @@ -98,7 +98,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea } if _, ok := storage.objectdata[objectKey]; ok == true { - return mstorage.ObjectExists{Bucket: bucket, Key: key} + return mstorage.ObjectExists{Bucket: bucket, Object: key} } if contentType == "" { diff --git a/pkg/storage/storage_errors.go b/pkg/storage/storage_errors.go index d68373950..7c26c107e 100644 --- a/pkg/storage/storage_errors.go +++ b/pkg/storage/storage_errors.go @@ -106,7 +106,7 @@ func (e ObjectNotFound) Error() string { // Return string an error formatted as the given text func (e APINotImplemented) Error() string { - return "Api not implemented: " + e.Api + return "Api not implemented: " + e.API } // Return string an error formatted as the given text