-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgateways.go
More file actions
83 lines (70 loc) · 1.93 KB
/
gateways.go
File metadata and controls
83 lines (70 loc) · 1.93 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cmd
import (
"fmt"
"github.com/drycc/controller-sdk-go/gateways"
"github.com/olekukonko/tablewriter"
)
// GatewaysList lists gateways for the app
func (d *DryccCmd) GatewaysList(appID string, results int) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
if results == defaultLimit {
results = s.Limit
}
gateways, count, err := gateways.List(s.Client, appID, results)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Printf("=== %s Gateways\n", appID)
if count == 0 {
d.Println("Could not find any gateway")
} else {
table := tablewriter.NewWriter(d.WOut)
table.SetHeader([]string{"Name", "Lisenter", "Port", "Protocol"})
for _, gateway := range gateways {
for _, listener := range gateway.Listeners {
table.Append([]string{gateway.Name, listener.Name, fmt.Sprint(listener.Port), listener.Protocol})
}
}
table.SetAutoMergeCellsByColumnIndex([]int{0})
table.SetRowLine(true)
table.Render()
}
return nil
}
// GatewaysAdd adds a gateway to an app.
func (d *DryccCmd) GatewaysAdd(appID, name string, port int, protocol string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Adding gateway %s to %s... ", name, appID)
quit := progress(d.WOut)
err = gateways.New(s.Client, appID, name, port, protocol)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}
// GatewaysRemove removes a gateway registered with an app.
func (d *DryccCmd) GatewaysRemove(appID, name string, port int, protocol string) error {
s, appID, err := load(d.ConfigFile, appID)
if err != nil {
return err
}
d.Printf("Removing gateway %s to %s... ", name, appID)
quit := progress(d.WOut)
err = gateways.Delete(s.Client, appID, name, port, protocol)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Println("done")
return nil
}