forked from vulcand/vulcand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
57 lines (48 loc) · 1.04 KB
/
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
56
57
/*Endpoints - final destination of the http request
*/
package endpoint
import (
"fmt"
"github.com/mailgun/vulcand/Godeps/_workspace/src/github.com/mailgun/vulcan/netutils"
"net/url"
)
type Endpoint interface {
GetId() string
GetUrl() *url.URL
String() string
}
type HttpEndpoint struct {
url *url.URL
id string
}
func ParseUrl(in string) (*HttpEndpoint, error) {
url, err := netutils.ParseUrl(in)
if err != nil {
return nil, err
}
return &HttpEndpoint{url: url, id: fmt.Sprintf("%s://%s", url.Scheme, url.Host)}, nil
}
func MustParseUrl(in string) *HttpEndpoint {
u, err := ParseUrl(in)
if err != nil {
panic(err)
}
return u
}
func NewHttpEndpoint(in *url.URL) (*HttpEndpoint, error) {
if in == nil {
return nil, fmt.Errorf("Provide url")
}
return &HttpEndpoint{
url: netutils.CopyUrl(in),
id: fmt.Sprintf("%s://%s", in.Scheme, in.Host)}, nil
}
func (e *HttpEndpoint) String() string {
return e.url.String()
}
func (e *HttpEndpoint) GetId() string {
return e.id
}
func (e *HttpEndpoint) GetUrl() *url.URL {
return e.url
}