Skip to content

Commit d38604d

Browse files
authored
Merge pull request #13 from lixiaojun629/develop
bw-pkg,shared-bw,firewall,udpn and vpc
2 parents 235d315 + 54acd22 commit d38604d

23 files changed

Lines changed: 2355 additions & 299 deletions

base/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/ucloud/ucloud-sdk-go/services/pathx"
77
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
88
"github.com/ucloud/ucloud-sdk-go/services/udisk"
9+
"github.com/ucloud/ucloud-sdk-go/services/udpn"
910
"github.com/ucloud/ucloud-sdk-go/services/uhost"
1011
"github.com/ucloud/ucloud-sdk-go/services/unet"
1112
"github.com/ucloud/ucloud-sdk-go/services/vpc"
@@ -25,6 +26,7 @@ type Client struct {
2526
uhost.UHostClient
2627
unet.UNetClient
2728
vpc.VPCClient
29+
udpn.UDPNClient
2830
pathx.PathXClient
2931
udisk.UDiskClient
3032
PrivateUHostClient
@@ -37,6 +39,7 @@ func NewClient(config *ucloud.Config, credential *auth.Credential) *Client {
3739
*uhost.NewClient(config, credential),
3840
*unet.NewClient(config, credential),
3941
*vpc.NewClient(config, credential),
42+
*udpn.NewClient(config, credential),
4043
*pathx.NewClient(config, credential),
4144
*udisk.NewClient(config, credential),
4245
*puhost.NewClient(config, credential),

base/util.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,36 +175,48 @@ func displaySlice(listVal reflect.Value, fieldList []string) {
175175
for i := 0; i < listVal.Len(); i++ {
176176
elemVal := listVal.Index(i)
177177
elemType := elemVal.Type()
178-
row := make(map[string]interface{})
178+
rows := []map[string]interface{}{}
179179
for j := 0; j < elemVal.NumField(); j++ {
180180
field := elemVal.Field(j)
181181
fieldName := elemType.Field(j).Name
182182
if _, ok := showFieldMap[fieldName]; ok {
183-
row[fieldName] = field.Interface()
184183
text := fmt.Sprintf("%v", field.Interface())
185-
width := calcWidth(text)
186-
if showFieldMap[fieldName] < width {
187-
showFieldMap[fieldName] = width
184+
cells := strings.Split(text, "\n")
185+
for i, cell := range cells {
186+
width := calcWidth(cell)
187+
if showFieldMap[fieldName] < width {
188+
showFieldMap[fieldName] = width
189+
}
190+
if len(rows) == i {
191+
rows = append(rows, make(map[string]interface{}))
192+
}
193+
rows[i][fieldName] = cell
188194
}
189195
}
190196
}
191-
rowList = append(rowList, row)
197+
rowList = append(rowList, rows...)
192198
}
193199
printTable(rowList, fieldList, showFieldMap)
194200
}
195201

196202
func printTable(rowList []map[string]interface{}, fieldList []string, fieldWidthMap map[string]int) {
203+
//打印表头
197204
for _, field := range fieldList {
198205
tmpl := "%-" + strconv.Itoa(fieldWidthMap[field]+GAP) + "s"
199206
fmt.Printf(tmpl, field)
200207
}
201208
fmt.Printf("\n")
202209

210+
//打印数据
203211
for _, row := range rowList {
204212
for _, field := range fieldList {
205213
cutWidth := calcCutWidth(fmt.Sprintf("%v", row[field]))
206214
tmpl := "%-" + strconv.Itoa(fieldWidthMap[field]-cutWidth+GAP) + "v"
207-
fmt.Printf(tmpl, row[field])
215+
if row[field] != nil {
216+
fmt.Printf(tmpl, row[field])
217+
} else {
218+
fmt.Printf(tmpl, "")
219+
}
208220
}
209221
fmt.Printf("\n")
210222
}
@@ -239,6 +251,11 @@ func FormatDate(seconds int) string {
239251
return time.Unix(int64(seconds), 0).Format("2006-01-02")
240252
}
241253

254+
//FormatDateTime 格式化时间,把以秒为单位的时间戳格式化未年月日/时分秒
255+
func FormatDateTime(seconds int) string {
256+
return time.Unix(int64(seconds), 0).Format("2006-01-02/15:04:05")
257+
}
258+
242259
//RegionLabel regionlable
243260
var RegionLabel = map[string]string{
244261
"cn-bj1": "Beijing1",

0 commit comments

Comments
 (0)