-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
56 lines (46 loc) · 1.18 KB
/
types.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
package main
import (
"fmt"
"sync"
)
type Manager struct {
Mutex sync.RWMutex
ProxyMap map[string]*UDPProxy // map of <frontendPort:backendService:backendPort> to UDPProxy
PortsOccupied map[int]bool
}
type ProxyRecord struct {
Port int `json:"port"`
TargetPort int `json:"targetPort"`
Service string `json:"service"`
}
func (p *ProxyRecord) String() string {
return proxyNameFormat(p.Port, p.Service, p.TargetPort)
}
func (p *UDPProxy) toRecord() ProxyRecord {
return ProxyRecord{
Port: p.port,
TargetPort: p.targetPort,
Service: p.service,
}
}
func UDPProxyToRecordList(proxyMap map[string]*UDPProxy) []ProxyRecord {
var records []ProxyRecord
for _, proxy := range proxyMap {
records = append(records, proxy.toRecord())
}
return records
}
type AddProxyResponse struct {
Success bool `json:"success"`
Error string `json:"error"`
}
type RemoveProxyResponse struct {
Success bool `json:"success"`
Error string `json:"error"`
}
type IsExistProxyResponse struct {
Exist bool `json:"exist"`
}
func proxyNameFormat(port int, service string, targetPort int) string {
return fmt.Sprintf("%d:%s:%d", port, service, targetPort)
}