-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket.go
68 lines (59 loc) · 1.39 KB
/
bucket.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"fmt"
"net/http"
"os"
"strconv"
"time"
"github.com/tencentyun/cos-go-sdk-v5"
)
func bucket() []cos.Bucket {
c = cos.NewClient(nil, &http.Client{
Timeout: 100 * time.Second,
Transport: &cos.AuthorizationTransport{
SecretID: conf.SecretID,
SecretKey: conf.SecretKey,
SessionToken: conf.SessionToken,
},
})
Resp, _, err := c.Service.Get(context.Background())
if err != nil {
panic(err)
}
// fmt.Printf("\033[7m> %-3s%-20s%-20s\033[0m\n", "No", "Bucket Name", "Bucket Region")
// for i, b := range Resp.Buckets {
// fmt.Printf(" %-3d%-20s%-20s\n", i, b.Name, b.Region)
// }
return Resp.Buckets
}
func SelectBucket() {
buck := bucket()
blen := len(buck)
for {
var tmp string
fmt.Printf("\033[7m> %-3s%-20s%-20s\033[0m\n", "No", "Bucket Name", "Bucket Region")
for i, b := range buck {
fmt.Printf(" %-3d%-20s%-20s\033[0m\n", i, b.Name, b.Region)
}
fmt.Printf("\033[32m> 选择你使用的存储桶(0, 1, ... or e): \033[0m")
fmt.Scan(&tmp)
if tmp == "e" {
os.Exit(0)
}
num, err := strconv.Atoi(tmp)
if num < blen && err == nil {
fmt.Printf("%25s\n", "")
fmt.Printf("\033[32m> 选中存储桶 %d, %s\033[0m\n", num, buck[num].Name)
conf.Bucket = buck[num].Name
conf.Region = buck[num].Region
SaveConfig()
os.Exit(0)
}
}
}
// func test() {
// buck := bucket()
// blen := len(buck)
// for
// }