Merge pull request #722 from BrianBland/vet-fix

Miscellaneous go vet fixes
This commit is contained in:
Olivier Gambier 2014-11-12 21:01:38 -08:00
commit a32680eb53
6 changed files with 22 additions and 21 deletions

View file

@ -162,7 +162,7 @@ func (storage *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error {
// MarshalYAML implements the yaml.Marshaler interface // MarshalYAML implements the yaml.Marshaler interface
func (storage Storage) MarshalYAML() (interface{}, error) { func (storage Storage) MarshalYAML() (interface{}, error) {
if storage.Parameters == nil { if storage.Parameters() == nil {
return storage.Type, nil return storage.Type, nil
} }
return map[string]Parameters(storage), nil return map[string]Parameters(storage), nil

View file

@ -14,7 +14,7 @@ func TestErrorCodes(t *testing.T) {
} }
if ec.Message() != errorCodesMessages[ec] { if ec.Message() != errorCodesMessages[ec] {
t.Fatalf("incorrect message for error code %v: %q != !q", ec, ec.Message(), errorCodesMessages[ec]) t.Fatalf("incorrect message for error code %v: %q != %q", ec, ec.Message(), errorCodesMessages[ec])
} }
// Serialize the error code using the json library to ensure that we // Serialize the error code using the json library to ensure that we
@ -26,7 +26,7 @@ func TestErrorCodes(t *testing.T) {
} }
if len(p) <= 0 { if len(p) <= 0 {
t.Fatalf("expected content in marshaled before for error code %v: %v", ec) t.Fatalf("expected content in marshaled before for error code %v", ec)
} }
// First, unmarshal to interface and ensure we have a string. // First, unmarshal to interface and ensure we have a string.

View file

@ -60,7 +60,7 @@ func (d *FilesystemDriver) subPath(subPath string) string {
func (d *FilesystemDriver) GetContent(path string) ([]byte, error) { func (d *FilesystemDriver) GetContent(path string) ([]byte, error) {
contents, err := ioutil.ReadFile(d.subPath(path)) contents, err := ioutil.ReadFile(d.subPath(path))
if err != nil { if err != nil {
return nil, storagedriver.PathNotFoundError{path} return nil, storagedriver.PathNotFoundError{Path: path}
} }
return contents, nil return contents, nil
} }
@ -89,7 +89,7 @@ func (d *FilesystemDriver) ReadStream(path string, offset uint64) (io.ReadCloser
return nil, err return nil, err
} else if seekPos < int64(offset) { } else if seekPos < int64(offset) {
file.Close() file.Close()
return nil, storagedriver.InvalidOffsetError{path, offset} return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset}
} }
return file, nil return file, nil
@ -104,7 +104,7 @@ func (d *FilesystemDriver) WriteStream(subPath string, offset, size uint64, read
} }
if offset > resumableOffset { if offset > resumableOffset {
return storagedriver.InvalidOffsetError{subPath, offset} return storagedriver.InvalidOffsetError{Path: subPath, Offset: offset}
} }
fullPath := d.subPath(subPath) fullPath := d.subPath(subPath)
@ -161,7 +161,7 @@ func (d *FilesystemDriver) CurrentSize(subPath string) (uint64, error) {
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return 0, err return 0, err
} else if err != nil { } else if err != nil {
return 0, storagedriver.PathNotFoundError{subPath} return 0, storagedriver.PathNotFoundError{Path: subPath}
} }
return uint64(fileInfo.Size()), nil return uint64(fileInfo.Size()), nil
} }
@ -200,7 +200,7 @@ func (d *FilesystemDriver) Delete(subPath string) error {
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return err return err
} else if err != nil { } else if err != nil {
return storagedriver.PathNotFoundError{subPath} return storagedriver.PathNotFoundError{Path: subPath}
} }
err = os.RemoveAll(fullPath) err = os.RemoveAll(fullPath)

View file

@ -45,7 +45,7 @@ func (d *InMemoryDriver) GetContent(path string) ([]byte, error) {
defer d.mutex.RUnlock() defer d.mutex.RUnlock()
contents, ok := d.storage[path] contents, ok := d.storage[path]
if !ok { if !ok {
return nil, storagedriver.PathNotFoundError{path} return nil, storagedriver.PathNotFoundError{Path: path}
} }
return contents, nil return contents, nil
} }
@ -64,7 +64,7 @@ func (d *InMemoryDriver) ReadStream(path string, offset uint64) (io.ReadCloser,
if err != nil { if err != nil {
return nil, err return nil, err
} else if len(contents) < int(offset) { } else if len(contents) < int(offset) {
return nil, storagedriver.InvalidOffsetError{path, offset} return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset}
} }
src := contents[offset:] src := contents[offset:]
@ -84,7 +84,7 @@ func (d *InMemoryDriver) WriteStream(path string, offset, size uint64, reader io
} }
if offset > resumableOffset { if offset > resumableOffset {
return storagedriver.InvalidOffsetError{path, offset} return storagedriver.InvalidOffsetError{Path: path, Offset: offset}
} }
contents, err := ioutil.ReadAll(reader) contents, err := ioutil.ReadAll(reader)
@ -138,7 +138,7 @@ func (d *InMemoryDriver) Move(sourcePath string, destPath string) error {
defer d.mutex.Unlock() defer d.mutex.Unlock()
contents, ok := d.storage[sourcePath] contents, ok := d.storage[sourcePath]
if !ok { if !ok {
return storagedriver.PathNotFoundError{sourcePath} return storagedriver.PathNotFoundError{Path: sourcePath}
} }
d.storage[destPath] = contents d.storage[destPath] = contents
delete(d.storage, sourcePath) delete(d.storage, sourcePath)
@ -156,7 +156,7 @@ func (d *InMemoryDriver) Delete(path string) error {
} }
if len(subPaths) == 0 { if len(subPaths) == 0 {
return storagedriver.PathNotFoundError{path} return storagedriver.PathNotFoundError{Path: path}
} }
for _, subPath := range subPaths { for _, subPath := range subPaths {

View file

@ -38,7 +38,6 @@ func StorageDriverServer(driver storagedriver.StorageDriver) error {
} }
go receive(driver, receiver) go receive(driver, receiver)
} }
return nil
} }
} }

View file

@ -65,7 +65,7 @@ func FromParameters(parameters map[string]string) (*S3Driver, error) {
} }
region := aws.GetRegion(regionName) region := aws.GetRegion(regionName)
if region.Name == "" { if region.Name == "" {
return nil, fmt.Errorf("Invalid region provided: %s", region) return nil, fmt.Errorf("Invalid region provided: %v", region)
} }
bucket, ok := parameters["bucket"] bucket, ok := parameters["bucket"]
@ -140,7 +140,7 @@ func (d *S3Driver) WriteStream(path string, offset, size uint64, reader io.ReadC
} }
if (offset) > uint64(len(parts))*chunkSize || (offset < size && offset%chunkSize != 0) { if (offset) > uint64(len(parts))*chunkSize || (offset < size && offset%chunkSize != 0) {
return storagedriver.InvalidOffsetError{path, offset} return storagedriver.InvalidOffsetError{Path: path, Offset: offset}
} }
if len(parts) > 0 { if len(parts) > 0 {
@ -226,7 +226,9 @@ func (d *S3Driver) List(path string) ([]string, error) {
func (d *S3Driver) Move(sourcePath string, destPath string) error { func (d *S3Driver) Move(sourcePath string, destPath string) error {
/* This is terrible, but aws doesn't have an actual move. */ /* This is terrible, but aws doesn't have an actual move. */
_, err := d.Bucket.PutCopy(destPath, getPermissions(), s3.CopyOptions{d.getOptions(), "", d.getContentType()}, d.Bucket.Name+"/"+sourcePath) _, err := d.Bucket.PutCopy(destPath, getPermissions(),
s3.CopyOptions{Options: d.getOptions(), MetadataDirective: "", ContentType: d.getContentType()},
d.Bucket.Name+"/"+sourcePath)
if err != nil { if err != nil {
return err return err
} }
@ -237,7 +239,7 @@ func (d *S3Driver) Move(sourcePath string, destPath string) error {
func (d *S3Driver) Delete(path string) error { func (d *S3Driver) Delete(path string) error {
listResponse, err := d.Bucket.List(path, "", "", listPartsMax) listResponse, err := d.Bucket.List(path, "", "", listPartsMax)
if err != nil || len(listResponse.Contents) == 0 { if err != nil || len(listResponse.Contents) == 0 {
return storagedriver.PathNotFoundError{path} return storagedriver.PathNotFoundError{Path: path}
} }
s3Objects := make([]s3.Object, listPartsMax) s3Objects := make([]s3.Object, listPartsMax)
@ -247,7 +249,7 @@ func (d *S3Driver) Delete(path string) error {
s3Objects[index].Key = key.Key s3Objects[index].Key = key.Key
} }
err := d.Bucket.DelMulti(s3.Delete{false, s3Objects[0:len(listResponse.Contents)]}) err := d.Bucket.DelMulti(s3.Delete{Quiet: false, Objects: s3Objects[0:len(listResponse.Contents)]})
if err != nil { if err != nil {
return nil return nil
} }