-
Notifications
You must be signed in to change notification settings - Fork 52
/
endpoint.go
55 lines (45 loc) · 944 Bytes
/
endpoint.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
package endpoint
import (
"fmt"
"net/url"
"strconv"
)
const (
secureField = "is_secure"
)
type Endpoint struct {
raw *url.URL
isSecure bool
}
func ParseEndpoint(endpoint string) (*Endpoint, error) {
raw, err := url.Parse(endpoint)
if err != nil {
return nil, err
}
return &Endpoint{raw: raw, isSecure: raw.Query().Get(secureField) == "true"}, nil
}
func NewEndpoint(scheme, address string, isSecure bool) *Endpoint {
return &Endpoint{
raw: &url.URL{
Scheme: scheme,
Host: address,
RawQuery: fmt.Sprintf("%s=%s", secureField, strconv.FormatBool(isSecure)),
},
isSecure: isSecure,
}
}
func (e *Endpoint) Scheme() string {
return e.raw.Scheme
}
func (e *Endpoint) Target() string {
return "direct://" + e.raw.Host
}
func (e *Endpoint) Address() string {
return e.raw.Host
}
func (e *Endpoint) IsSecure() bool {
return e.isSecure
}
func (e *Endpoint) String() string {
return e.raw.String()
}