Skip to content

Commit c97e75b

Browse files
authored
Merge pull request #35 from jianxiaoguo/main
feat(gateways): add addresses field
2 parents 34d297a + 7381b84 commit c97e75b

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

cmd/gateways.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
56

7+
"github.com/drycc/controller-sdk-go/api"
68
"github.com/drycc/controller-sdk-go/gateways"
79
)
810

@@ -24,11 +26,11 @@ func (d *DryccCmd) GatewaysList(appID string, results int) error {
2426
if count == 0 {
2527
d.Println(fmt.Sprintf("No gateways found in %s app.", appID))
2628
} else {
27-
28-
table := d.getDefaultFormatTable([]string{"NAME", "LISENTER", "PORT", "PROTOCOL"})
29+
table := d.getDefaultFormatTable([]string{"NAME", "LISENTER", "PORT", "PROTOCOL", "ADDRESSES"})
2930
for _, gateway := range gateways {
31+
addresesStr := parseAddress(gateway.Addresses)
3032
for _, listener := range gateway.Listeners {
31-
table.Append([]string{gateway.Name, listener.Name, fmt.Sprint(listener.Port), listener.Protocol})
33+
table.Append([]string{gateway.Name, listener.Name, fmt.Sprint(listener.Port), listener.Protocol, addresesStr})
3234
}
3335
}
3436
table.Render()
@@ -77,3 +79,12 @@ func (d *DryccCmd) GatewaysRemove(appID, name string, port int, protocol string)
7779
d.Println("done")
7880
return nil
7981
}
82+
83+
func parseAddress(addresses []api.Address) string {
84+
var addresList []string
85+
for _, address := range addresses {
86+
addresList = append(addresList, address.Value)
87+
}
88+
addresStr := strings.Join(addresList, ",")
89+
return addresStr
90+
}

cmd/gateways_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"testing"
88

99
"github.com/drycc/controller-sdk-go/api"
10-
"github.com/drycc/workflow-cli/pkg/testutil"
1110
"github.com/stretchr/testify/assert"
11+
12+
"github.com/drycc/workflow-cli/pkg/testutil"
1213
)
1314

1415
func TestGatewaysList(t *testing.T) {
@@ -47,6 +48,12 @@ func TestGatewaysList(t *testing.T) {
4748
"protocol": "HTTPS",
4849
"allowedRoutes": {"namespaces": {"from": "All"}}
4950
}
51+
],
52+
"addresses": [
53+
{
54+
"type": "IPAddress",
55+
"value": "192.168.11.1"
56+
}
5057
]
5158
}
5259
]
@@ -56,9 +63,9 @@ func TestGatewaysList(t *testing.T) {
5663
err = cmdr.GatewaysList("foo", -1)
5764
assert.NoError(t, err)
5865

59-
assert.Equal(t, b.String(), `NAME LISENTER PORT PROTOCOL
60-
foo foo-80-http 80 HTTP
61-
foo foo-443-https 443 HTTPS
66+
assert.Equal(t, b.String(), `NAME LISENTER PORT PROTOCOL ADDRESSES
67+
foo foo-80-http 80 HTTP 192.168.11.1
68+
foo foo-443-https 443 HTTPS 192.168.11.1
6269
`, "output")
6370
}
6471

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/containerd/console v1.0.3
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
8-
github.com/drycc/controller-sdk-go v0.0.0-20231108033734-99a7fbf94e7b
8+
github.com/drycc/controller-sdk-go v0.0.0-20231124064538-8bbfc028ba6d
99
github.com/drycc/pkg v0.0.0-20230619083908-711ad2e9f1b8
1010
github.com/olekukonko/tablewriter v0.0.5
1111
github.com/stretchr/testify v1.8.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
66
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
7-
github.com/drycc/controller-sdk-go v0.0.0-20231108033734-99a7fbf94e7b h1:Z9n6Uia65mhX6oHFAZpB9UMopqmqgMyHxI+6lMFWeBs=
8-
github.com/drycc/controller-sdk-go v0.0.0-20231108033734-99a7fbf94e7b/go.mod h1:X69v0xts3XpvbcQpVeR+wwQqORPJ8ClXnYvnMoAOUHE=
7+
github.com/drycc/controller-sdk-go v0.0.0-20231124064538-8bbfc028ba6d h1:v4qJ9Wr41nP/Zj42F1hLkzTf7wtjNJOagqnbhkOVPzo=
8+
github.com/drycc/controller-sdk-go v0.0.0-20231124064538-8bbfc028ba6d/go.mod h1:X69v0xts3XpvbcQpVeR+wwQqORPJ8ClXnYvnMoAOUHE=
99
github.com/drycc/pkg v0.0.0-20230619083908-711ad2e9f1b8 h1:bTPrdjJTYxMK3T6nYk7Qa8nDbvNNxvNOdI/fgVsiuCg=
1010
github.com/drycc/pkg v0.0.0-20230619083908-711ad2e9f1b8/go.mod h1:y/6vsR0kXRg3Vxj2M/UqApU2uL43KfMDMN2SyvwF0Ek=
1111
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=

0 commit comments

Comments
 (0)