-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheme.go
49 lines (41 loc) · 893 Bytes
/
scheme.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
package gosupport
import "fmt"
type SchemeInfo struct {
Protocol string `json:"protocol"` //协议,如:http、https、tcp
Host string `json:"host"`
Port int `json:"port"`
}
func (m SchemeInfo) ToString() string {
s := ""
if m.Protocol != "" {
s += m.Protocol + "://"
}
s += m.Host
if m.Port > 0 {
s = fmt.Sprintf("%s:%d", s, m.Port)
}
return s
}
type SchemeInfoOption func(info *SchemeInfo)
func NewSchemeInfo(opts ...SchemeInfoOption) *SchemeInfo {
schmeInfo := new(SchemeInfo)
for _, opt := range opts {
opt(schmeInfo)
}
return schmeInfo
}
func WithSchemeInfoProtocol(s string) SchemeInfoOption {
return func(m *SchemeInfo) {
m.Protocol = s
}
}
func WithSchemeInfoHost(s string) SchemeInfoOption {
return func(m *SchemeInfo) {
m.Host = s
}
}
func WithSchemeInfoPort(d int) SchemeInfoOption {
return func(m *SchemeInfo) {
m.Port = d
}
}