/
proxy_forward.go
68 lines (56 loc) · 1.79 KB
/
proxy_forward.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
57
58
59
60
61
62
63
64
65
66
67
68
package proxy
import "fmt"
type ProxyForward struct {
Name string
Hostname string
ProxyHostname string
LocalPort string
ForwardPort string
LocalIP string
ProxyPort string
}
// NewProxyForward returns a new proxy port-forward instance
func NewProxyForward(name, hostname, proxyHostname, localPort, forwardPort string) *ProxyForward {
proxyForward := &ProxyForward{
Name: name,
Hostname: hostname,
ProxyHostname: proxyHostname,
LocalPort: localPort,
ForwardPort: forwardPort,
}
// In case of a forward type 'proxy', just set the proxy port with
// the given forward port (proxy component will not generate one)
if proxyHostname != "" {
proxyForward.ProxyPort = forwardPort
}
return proxyForward
}
// SetLocalIP sets local attributed IP to this forward
func (p *ProxyForward) SetLocalIP(ip string) {
p.LocalIP = ip
}
// SetProxyPort sets proxy attributed port to this forward
func (p *ProxyForward) SetProxyPort(port string) {
p.ProxyPort = port
}
// GetProxifiedPorts returns the couple of proxified ports (proxy attributed port:forward port)
func (p *ProxyForward) GetProxifiedPorts() string {
return fmt.Sprintf("%s:%s", p.ProxyPort, p.ForwardPort)
}
// GetHostname returns the hostname (if defined) of this proxy forward, elsewhere uses the
// service name
func (p *ProxyForward) GetHostname() string {
if p.Hostname != "" {
return p.Hostname
}
return p.Name
}
// GetProxyHostname returns the proxy sender hostname depending on forward type
// In case of a forward type 'proxy', it will return the specified proxy hostname, elsewhere
// it will return 127.0.0.1 because other forwards forward traffic locally
func (p *ProxyForward) GetProxyHostname() string {
if p.ProxyHostname != "" {
return p.ProxyHostname
}
return "127.0.0.1"
}