-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint.go
More file actions
38 lines (32 loc) · 837 Bytes
/
Copy pathendpoint.go
File metadata and controls
38 lines (32 loc) · 837 Bytes
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
package main
import (
"errors"
"net/http/httputil"
"net/url"
"time"
log "github.com/sirupsen/logrus"
)
// Endpoint struct containing everything needed for a new endpoint
type Endpoint struct {
Active bool
Address *url.URL
Proxy *httputil.ReverseProxy
Registered string
Available time.Time
}
// NewEndpoint creates new endpoints to forward traffic to
func NewEndpoint(base, address string) (*Endpoint, error) {
parsedAddress, err := url.Parse(address)
if err != nil {
log.WithFields(log.Fields{"url": parsedAddress}).Error("Problem parsing URL")
return nil, errors.New("Problem parsing URL " + address)
}
e := &Endpoint{
Address: parsedAddress,
Proxy: httputil.NewSingleHostReverseProxy(parsedAddress),
Active: true,
Available: time.Now(),
Registered: base,
}
return e, nil
}