mirror of https://github.com/minio/minio.git
Golint cleanup pkg/storage
This commit is contained in:
parent
256faddab5
commit
76e601b26b
|
@ -43,10 +43,10 @@ func (s *MySuite) TestCauchyDecode(c *C) {
|
|||
chunks[9] = nil
|
||||
chunks[13] = nil
|
||||
|
||||
recovered_data, err := e.Decode(chunks, length)
|
||||
recoveredData, err := e.Decode(chunks, length)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
if !bytes.Equal(data, recovered_data) {
|
||||
if !bytes.Equal(data, recoveredData) {
|
||||
c.Fatalf("Recovered data mismatches with original data")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ func (s *MySuite) TestVanderMondeDecode(c *C) {
|
|||
chunks[9] = nil
|
||||
chunks[13] = nil
|
||||
|
||||
recovered_data, err := e.Decode(chunks, length)
|
||||
recoveredData, err := e.Decode(chunks, length)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
if !bytes.Equal(recovered_data, data) {
|
||||
if !bytes.Equal(recoveredData, data) {
|
||||
c.Fatalf("Recovered data mismatches with original data")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ type storage struct {
|
|||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
// SerializedMetadata - carries content type
|
||||
type SerializedMetadata struct {
|
||||
ContentType string
|
||||
}
|
||||
|
@ -237,9 +238,8 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
|
|||
{
|
||||
if os.IsNotExist(err) {
|
||||
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}
|
||||
} else {
|
||||
return 0, mstorage.EmbedError(bucket, object, err)
|
||||
}
|
||||
return 0, mstorage.EmbedError(bucket, object, err)
|
||||
}
|
||||
}
|
||||
file, err := os.Open(objectPath)
|
||||
|
@ -311,20 +311,20 @@ func (storage *storage) GetObjectMetadata(bucket string, object string) (mstorag
|
|||
return metadata, nil
|
||||
}
|
||||
|
||||
type Path struct {
|
||||
type bucketDir struct {
|
||||
files map[string]os.FileInfo
|
||||
root string
|
||||
}
|
||||
|
||||
func (p *Path) getAllFiles(path string, fl os.FileInfo, err error) error {
|
||||
func (p *bucketDir) getAllFiles(object string, fl os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fl.Mode().IsRegular() {
|
||||
if strings.HasSuffix(path, "$metadata") {
|
||||
if strings.HasSuffix(object, "$metadata") {
|
||||
return nil
|
||||
}
|
||||
_p := strings.Split(path, p.root+"/")
|
||||
_p := strings.Split(object, p.root+"/")
|
||||
if len(_p) > 1 {
|
||||
p.files[_p[1]] = fl
|
||||
}
|
||||
|
@ -332,8 +332,8 @@ func (p *Path) getAllFiles(path string, fl os.FileInfo, err error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func delimiter(path, delimiter string) string {
|
||||
readBuffer := bytes.NewBufferString(path)
|
||||
func delimiter(object, delimiter string) string {
|
||||
readBuffer := bytes.NewBufferString(object)
|
||||
reader := bufio.NewReader(readBuffer)
|
||||
stringReader := strings.NewReader(delimiter)
|
||||
delimited, _ := stringReader.ReadByte()
|
||||
|
@ -341,20 +341,20 @@ func delimiter(path, delimiter string) string {
|
|||
return delimitedStr
|
||||
}
|
||||
|
||||
type ByObjectKey []mstorage.ObjectMetadata
|
||||
type byObjectKey []mstorage.ObjectMetadata
|
||||
|
||||
// Len
|
||||
func (b ByObjectKey) Len() int { return len(b) }
|
||||
func (b byObjectKey) Len() int { return len(b) }
|
||||
|
||||
// Swap
|
||||
func (b ByObjectKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
func (b byObjectKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
|
||||
// Less
|
||||
func (b ByObjectKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
||||
func (b byObjectKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
||||
|
||||
// GET bucket (list objects)
|
||||
func (storage *storage) ListObjects(bucket string, resources mstorage.BucketResourcesMetadata) ([]mstorage.ObjectMetadata, mstorage.BucketResourcesMetadata, error) {
|
||||
p := Path{}
|
||||
p := bucketDir{}
|
||||
p.files = make(map[string]os.FileInfo)
|
||||
|
||||
if mstorage.IsValidBucket(bucket) == false {
|
||||
|
@ -450,7 +450,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
|
|||
}
|
||||
|
||||
ret:
|
||||
sort.Sort(ByObjectKey(metadataList))
|
||||
sort.Sort(byObjectKey(metadataList))
|
||||
return metadataList, resources, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Mini Object Storage, (C) 2015 Minio, Inc.
|
||||
* Minio Object Storage, (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -72,9 +72,8 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
|
|||
objectBuffer := bytes.NewBuffer(val.data)
|
||||
written, err := io.Copy(w, objectBuffer)
|
||||
return written, err
|
||||
} else {
|
||||
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}
|
||||
}
|
||||
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
|
@ -176,16 +175,16 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
|
|||
return results, resources, nil
|
||||
}
|
||||
|
||||
type ByBucketName []mstorage.BucketMetadata
|
||||
type byBucketName []mstorage.BucketMetadata
|
||||
|
||||
// Len of bucket name
|
||||
func (b ByBucketName) Len() int { return len(b) }
|
||||
func (b byBucketName) Len() int { return len(b) }
|
||||
|
||||
// Swap bucket i, j
|
||||
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
func (b byBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||
|
||||
// Less
|
||||
func (b ByBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name }
|
||||
func (b byBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name }
|
||||
|
||||
// List buckets
|
||||
func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
|
||||
|
@ -193,7 +192,7 @@ func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
|
|||
for _, bucket := range storage.bucketdata {
|
||||
results = append(results, bucket.metadata)
|
||||
}
|
||||
sort.Sort(ByBucketName(results))
|
||||
sort.Sort(byBucketName(results))
|
||||
return results, nil
|
||||
}
|
||||
|
||||
|
@ -203,7 +202,6 @@ func (storage *storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMe
|
|||
|
||||
if object, ok := storage.objectdata[objectKey]; ok == true {
|
||||
return object.metadata, nil
|
||||
} else {
|
||||
return mstorage.ObjectMetadata{}, mstorage.ObjectNotFound{Bucket: bucket, Object: key}
|
||||
}
|
||||
return mstorage.ObjectMetadata{}, mstorage.ObjectNotFound{Bucket: bucket, Object: key}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Storage - generic API interface
|
||||
type Storage interface {
|
||||
// Bucket Operations
|
||||
ListBuckets() ([]BucketMetadata, error)
|
||||
|
@ -37,11 +38,13 @@ type Storage interface {
|
|||
StoreObject(bucket string, key string, contentType string, data io.Reader) error
|
||||
}
|
||||
|
||||
// BucketMetadata - name and create date
|
||||
type BucketMetadata struct {
|
||||
Name string
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
// ObjectMetadata - object key and its relevant metadata
|
||||
type ObjectMetadata struct {
|
||||
Bucket string
|
||||
Key string
|
||||
|
@ -52,7 +55,7 @@ type ObjectMetadata struct {
|
|||
Size int64
|
||||
}
|
||||
|
||||
// Various types of bucket resources
|
||||
// BucketResourcesMetadata - various types of bucket resources
|
||||
type BucketResourcesMetadata struct {
|
||||
Prefix string
|
||||
Marker string
|
||||
|
@ -67,7 +70,8 @@ type BucketResourcesMetadata struct {
|
|||
Notification string
|
||||
}
|
||||
|
||||
// Verify Bucket name in accordance with http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
|
||||
// IsValidBucket - verify bucket name in accordance with
|
||||
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
|
||||
func IsValidBucket(bucket string) bool {
|
||||
if len(bucket) < 3 || len(bucket) > 63 {
|
||||
return false
|
||||
|
@ -83,7 +87,8 @@ func IsValidBucket(bucket string) bool {
|
|||
return match
|
||||
}
|
||||
|
||||
// Verify Object name in accordance with http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
|
||||
// IsValidObject - verify object name in accordance with
|
||||
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
|
||||
func IsValidObject(object string) bool {
|
||||
if len(object) > 1024 || len(object) == 0 {
|
||||
return false
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// API test suite
|
||||
// APITestSuite - collection of API tests
|
||||
func APITestSuite(c *C, create func() Storage) {
|
||||
testCreateBucket(c, create)
|
||||
testMultipleObjectCreation(c, create)
|
||||
|
|
|
@ -16,62 +16,76 @@
|
|||
|
||||
package storage
|
||||
|
||||
// BackendError - generic disk backend error
|
||||
type BackendError struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
type GenericError struct {
|
||||
Bucket string
|
||||
Path string
|
||||
// BackendCorrupted - path has corrupted data
|
||||
type BackendCorrupted BackendError
|
||||
|
||||
// APINotImplemented - generic API not implemented error
|
||||
type APINotImplemented struct {
|
||||
API string
|
||||
}
|
||||
|
||||
type ObjectExists struct {
|
||||
Bucket string
|
||||
Key string
|
||||
}
|
||||
|
||||
type ApiNotImplemented struct {
|
||||
Api string
|
||||
}
|
||||
|
||||
type ObjectNotFound GenericObjectError
|
||||
|
||||
// GenericBucketError - generic bucket error
|
||||
type GenericBucketError struct {
|
||||
Bucket string
|
||||
}
|
||||
|
||||
// GenericObjectError - generic object error
|
||||
type GenericObjectError struct {
|
||||
Bucket string
|
||||
Object string
|
||||
}
|
||||
|
||||
// ImplementationError - generic implementation error
|
||||
type ImplementationError struct {
|
||||
Bucket string
|
||||
Object string
|
||||
Err error
|
||||
}
|
||||
|
||||
type BackendCorrupted BackendError
|
||||
/// Bucket related errors
|
||||
|
||||
// BucketPolicyNotFound - missing bucket policy
|
||||
type BucketPolicyNotFound GenericBucketError
|
||||
|
||||
// BucketNameInvalid - bucketname provided is invalid
|
||||
type BucketNameInvalid GenericBucketError
|
||||
|
||||
// BucketExists - bucket already exists
|
||||
type BucketExists GenericBucketError
|
||||
|
||||
// BucketNotFound - requested bucket not found
|
||||
type BucketNotFound GenericBucketError
|
||||
|
||||
/// Object related errors
|
||||
|
||||
// ObjectNotFound - requested object not found
|
||||
type ObjectNotFound GenericObjectError
|
||||
|
||||
// ObjectExists - object already exists
|
||||
type ObjectExists GenericObjectError
|
||||
|
||||
// ObjectNameInvalid - object name provided is invalid
|
||||
type ObjectNameInvalid GenericObjectError
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self ImplementationError) Error() string {
|
||||
func (e ImplementationError) Error() string {
|
||||
error := ""
|
||||
if self.Bucket != "" {
|
||||
error = error + "Bucket: " + self.Bucket + " "
|
||||
if e.Bucket != "" {
|
||||
error = error + "Bucket: " + e.Bucket + " "
|
||||
}
|
||||
if self.Object != "" {
|
||||
error = error + "Object: " + self.Object + " "
|
||||
if e.Object != "" {
|
||||
error = error + "Object: " + e.Object + " "
|
||||
}
|
||||
error = error + "Error: " + self.Err.Error()
|
||||
error = error + "Error: " + e.Err.Error()
|
||||
return error
|
||||
}
|
||||
|
||||
// Wrapper function for error object
|
||||
// EmbedError - wrapper function for error object
|
||||
func EmbedError(bucket, object string, err error) ImplementationError {
|
||||
return ImplementationError{
|
||||
Bucket: bucket,
|
||||
|
@ -81,46 +95,46 @@ func EmbedError(bucket, object string, err error) ImplementationError {
|
|||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self BucketPolicyNotFound) Error() string {
|
||||
return "Bucket policy not found for: " + self.Bucket
|
||||
func (e BucketPolicyNotFound) Error() string {
|
||||
return "Bucket policy not found for: " + e.Bucket
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self ObjectNotFound) Error() string {
|
||||
return "Object not Found: " + self.Bucket + "#" + self.Object
|
||||
func (e ObjectNotFound) Error() string {
|
||||
return "Object not Found: " + e.Bucket + "#" + e.Object
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self ApiNotImplemented) Error() string {
|
||||
return "Api not implemented: " + self.Api
|
||||
func (e APINotImplemented) Error() string {
|
||||
return "Api not implemented: " + e.Api
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self ObjectExists) Error() string {
|
||||
return "Object exists: " + self.Bucket + "#" + self.Key
|
||||
func (e ObjectExists) Error() string {
|
||||
return "Object exists: " + e.Bucket + "#" + e.Object
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self BucketNameInvalid) Error() string {
|
||||
return "Bucket name invalid: " + self.Bucket
|
||||
func (e BucketNameInvalid) Error() string {
|
||||
return "Bucket name invalid: " + e.Bucket
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self BucketExists) Error() string {
|
||||
return "Bucket exists: " + self.Bucket
|
||||
func (e BucketExists) Error() string {
|
||||
return "Bucket exists: " + e.Bucket
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self BucketNotFound) Error() string {
|
||||
return "Bucket not Found: " + self.Bucket
|
||||
func (e BucketNotFound) Error() string {
|
||||
return "Bucket not Found: " + e.Bucket
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self ObjectNameInvalid) Error() string {
|
||||
return "Object name invalid: " + self.Bucket + "#" + self.Object
|
||||
func (e ObjectNameInvalid) Error() string {
|
||||
return "Object name invalid: " + e.Bucket + "#" + e.Object
|
||||
}
|
||||
|
||||
// Return string an error formatted as the given text
|
||||
func (self BackendCorrupted) Error() string {
|
||||
return "Backend corrupted: " + self.Path
|
||||
func (e BackendCorrupted) Error() string {
|
||||
return "Backend corrupted: " + e.Path
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue