-
Notifications
You must be signed in to change notification settings - Fork 797
/
exported.go
52 lines (45 loc) · 1.67 KB
/
exported.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build go1.18
// +build go1.18
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
package exported
import (
"errors"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"strconv"
"strings"
)
const SnapshotTimeFormat = "2006-01-02T15:04:05.0000000Z07:00"
// HTTPRange defines a range of bytes within an HTTP resource, starting at offset and
// ending at offset+count. A zero-value HTTPRange indicates the entire resource. An HTTPRange
// which has an offset and zero value count indicates from the offset to the resource's end.
type HTTPRange = blob.HTTPRange
// FormatHTTPRange converts an HTTPRange to its string format.
func FormatHTTPRange(r HTTPRange) *string {
if r.Offset == 0 && r.Count == 0 {
return nil // No specified range
}
endOffset := "" // if count == CountToEnd (0)
if r.Count > 0 {
endOffset = strconv.FormatInt((r.Offset+r.Count)-1, 10)
}
dataRange := fmt.Sprintf("bytes=%v-%s", r.Offset, endOffset)
return &dataRange
}
func ConvertToDFSError(err error) error {
if err == nil {
return nil
}
var responseErr *azcore.ResponseError
isRespErr := errors.As(err, &responseErr)
if isRespErr {
responseErr.ErrorCode = strings.Replace(responseErr.ErrorCode, "blob", "path", -1)
responseErr.ErrorCode = strings.Replace(responseErr.ErrorCode, "Blob", "Path", -1)
responseErr.ErrorCode = strings.Replace(responseErr.ErrorCode, "container", "filesystem", -1)
responseErr.ErrorCode = strings.Replace(responseErr.ErrorCode, "Container", "FileSystem", -1)
return responseErr
}
return err
}