Use gofmt to format the code of swift driver.

Signed-off-by: Li Wenquan <wenquan.li@hp.com>
This commit is contained in:
davidli 2015-05-22 14:31:47 +08:00 committed by Sylvain Baubeau
parent cce4956131
commit 1f4eb7b735
2 changed files with 26 additions and 26 deletions

View file

@ -155,8 +155,8 @@ func New(params DriverParameters) (*Driver, error) {
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container, err) return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container, err)
} }
if err := ct.ContainerCreate(params.Container + "_segments", nil); err != nil { if err := ct.ContainerCreate(params.Container+"_segments", nil); err != nil {
return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container + "_segments", err) return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container+"_segments", err)
} }
d := &driver{ d := &driver{
@ -279,7 +279,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
headers := make(swift.Headers) headers := make(swift.Headers)
headers["Content-Type"] = "application/json" headers["Content-Type"] = "application/json"
opts := &swift.ObjectsOpts{Prefix: d.swiftPath(path), Headers: headers} opts := &swift.ObjectsOpts{Prefix: d.swiftPath(path), Headers: headers}
segments, err = d.Conn.Objects(d.Container + "_segments", opts) segments, err = d.Conn.Objects(d.Container+"_segments", opts)
if err != nil { if err != nil {
return bytesRead, parseError(path, err) return bytesRead, parseError(path, err)
} }
@ -287,7 +287,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
// First, we skip the existing segments that are not modified by this call // First, we skip the existing segments that are not modified by this call
for i := range segments { for i := range segments {
if offset < cursor + segments[i].Bytes { if offset < cursor+segments[i].Bytes {
break break
} }
cursor += segments[i].Bytes cursor += segments[i].Bytes
@ -297,7 +297,7 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
// We reached the end of the file but we haven't reached 'offset' yet // We reached the end of the file but we haven't reached 'offset' yet
// Therefore we add blocks of zeros // Therefore we add blocks of zeros
if offset >= currentLength { if offset >= currentLength {
for offset - currentLength >= d.ChunkSize { for offset-currentLength >= d.ChunkSize {
// Insert a block a zero // Insert a block a zero
d.Conn.ObjectPut(segmentsContainer, getSegment(), d.Conn.ObjectPut(segmentsContainer, getSegment(),
bytes.NewReader(zeroBuf), false, "", bytes.NewReader(zeroBuf), false, "",
@ -318,8 +318,8 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
} }
multi := io.MultiReader( multi := io.MultiReader(
io.LimitReader(paddingReader, offset - cursor), io.LimitReader(paddingReader, offset-cursor),
io.LimitReader(reader, d.ChunkSize - (offset - cursor)), io.LimitReader(reader, d.ChunkSize-(offset-cursor)),
) )
for { for {
@ -335,10 +335,10 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
if n < d.ChunkSize { if n < d.ChunkSize {
// We wrote all the data // We wrote all the data
if cursor + n < currentLength { if cursor+n < currentLength {
// Copy the end of the chunk // Copy the end of the chunk
headers := make(swift.Headers) headers := make(swift.Headers)
headers["Range"] = "bytes=" + strconv.FormatInt(cursor + n, 10) + "-" + strconv.FormatInt(cursor + d.ChunkSize, 10) headers["Range"] = "bytes=" + strconv.FormatInt(cursor+n, 10) + "-" + strconv.FormatInt(cursor+d.ChunkSize, 10)
file, _, err := d.Conn.ObjectOpen(d.Container, d.swiftPath(path), false, headers) file, _, err := d.Conn.ObjectOpen(d.Container, d.swiftPath(path), false, headers)
if err != nil { if err != nil {
return bytesRead, parseError(path, err) return bytesRead, parseError(path, err)
@ -348,13 +348,13 @@ func (d *driver) WriteStream(ctx context.Context, path string, offset int64, rea
} }
if n > 0 { if n > 0 {
currentSegment.Close() currentSegment.Close()
bytesRead += n - max(0, offset - cursor) bytesRead += n - max(0, offset-cursor)
} }
break break
} }
currentSegment.Close() currentSegment.Close()
bytesRead += n - max(0, offset - cursor) bytesRead += n - max(0, offset-cursor)
multi = io.MultiReader(io.LimitReader(reader, d.ChunkSize)) multi = io.MultiReader(io.LimitReader(reader, d.ChunkSize))
cursor += d.ChunkSize cursor += d.ChunkSize
partNumber++ partNumber++
@ -443,7 +443,7 @@ func (d *driver) Delete(ctx context.Context, path string) error {
if ok { if ok {
components := strings.SplitN(manifest, "/", 2) components := strings.SplitN(manifest, "/", 2)
segContainer := components[0] segContainer := components[0]
segments, err := d.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{ Prefix: components[1] }) segments, err := d.Conn.ObjectNamesAll(segContainer, &swift.ObjectsOpts{Prefix: components[1]})
if err != nil { if err != nil {
return parseError(name, err) return parseError(name, err)
} }