-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
54 lines (47 loc) · 1.26 KB
/
cli.go
File metadata and controls
54 lines (47 loc) · 1.26 KB
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
53
54
package azure
import (
"fmt"
"github.com/Azure/azure-pipeline-go/pipeline"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/siddontang/go/log"
"net/url"
)
var (
CliManager Azure
accountName = ""
accountKey = ""
)
// Init 初始化操作用来
func Init(name string, key string) error {
credential, err := azblob.NewSharedKeyCredential(name, key)
if err != nil {
return err
}
// 目前处理,共用一个 pipeline
p := azblob.NewPipeline(credential, azblob.PipelineOptions{})
u, _ := url.Parse(fmt.Sprintf("https://%s.blob.core.windows.net", name))
CliManager.mu.Lock()
defer CliManager.mu.Unlock()
// init global azure
CliManager.Name = name
CliManager.Key = key
CliManager.ServiceURL = azblob.NewServiceURL(*u, p)
CliManager.IsInit = true
return nil
}
// ShowResp 直接打印 azure 的返回信息
// todo: 考虑一下此处怎么处理。
func ShowResp(response pipeline.Response, err error) {
if err != nil {
if stgErr, ok := err.(azblob.StorageError); !ok {
log.Fatal(err)
} else {
fmt.Print("Failure: " + stgErr.Response().Status + "\n")
}
} else {
if get, ok := response.(*azblob.DownloadResponse); ok {
get.Body(azblob.RetryReaderOptions{}).Close()
}
fmt.Print("Success: " + response.Response().Status + "\n")
}
}