-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdynamic_table_app.go
54 lines (47 loc) · 1.13 KB
/
dynamic_table_app.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
package main
import (
"log"
"strconv"
"github.com/andrianbdn/wg-cmd/app"
"github.com/andrianbdn/wg-cmd/backend"
)
func stringRowsFromApp(app *app.App) [][]string {
rows := make([][]string, 0, len(app.State.Clients)+1)
rows = append(rows, []string{
"0001", "Server (" + app.State.Server.Interface + ")",
app.State.Server.Address4, app.State.Server.Address6,
})
err := app.State.IterateClients(func(cl *backend.Client) error {
rows = append(rows, []string{
cl.GetIPNumberString(),
cl.GetName(),
cl.GetIP4(app.State.Server),
cl.GetIP6(app.State.Server),
})
return nil
})
if err != nil {
panic(err)
}
return rows
}
func newAppDynamicTableList(app *app.App, table *DynamicTableList) DynamicTableList {
t := NewMainTable(
[]string{"#", "Name", "IPv4", "IPv6"},
stringRowsFromApp(app),
[]int{1, 3, 2, 3},
[]int{4, 20, 16, 46},
)
if table != nil {
t.CopyTableState(table)
}
return t
}
func clientFromRow(app *app.App, row []string) *backend.Client {
peerID, err := strconv.Atoi(row[0])
if err != nil {
log.Println("can't convert", row[0], "to int", err)
return nil
}
return app.State.Clients[peerID]
}