-
Notifications
You must be signed in to change notification settings - Fork 1
/
typeUpstream.go
63 lines (55 loc) · 1.25 KB
/
typeUpstream.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
package config
import "fmt"
type (
//UpstreamConfig container
UpstreamConfig struct {
HTTP map[string]*HTTPUpstreamConfig `json:"http"`
UnixSocket map[string]UnixSocketConfig `json:"unixSocket"`
Socket map[string]*SocketConfig `json:"socket"`
}
//HTTPUpstreamConfig http upstream config
HTTPUpstreamConfig struct {
Address string `json:"address"`
Port string `json:"port"`
Schema string `json:"schema"`
}
//UnixSocketConfig unix socket config
UnixSocketConfig struct {
FileDescriptor string `json:"fileDescriptor"`
}
//SocketConfig tcp / udp upstream config
SocketConfig struct {
Address string `json:"address"`
Port string `json:"port"`
}
)
//GetURL gets from http upstream connection string
func (hcfg *HTTPUpstreamConfig) GetURL() string {
if hcfg.Address == "" {
return ""
}
if hcfg.Schema == "" {
hcfg.Schema = "http"
}
if hcfg.Port == "" {
return fmt.Sprintf("%s%s",
hcfg.Schema,
hcfg.Address,
)
}
return fmt.Sprintf("%s%s:%s",
hcfg.Schema,
hcfg.Address,
hcfg.Port,
)
}
//GetTarget gets target address from upstream
func (scfg *SocketConfig) GetTarget() string {
if scfg.Address == "" || scfg.Port == "" {
return ""
}
return fmt.Sprintf("%s:%s",
scfg.Address,
scfg.Port,
)
}