aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-04-03 19:47:03 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-04-03 19:47:03 +0200
commitfa3272edca41882027f6b22f70bc61d9a182bd0d (patch)
tree237be08335bb6f9264504193c413ff09e18ba8d7
parentadc9524911d91c68e0b5c9b2ef0f2e0bd81e5c68 (diff)
Add NewRoute
-rw-r--r--route.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/route.go b/route.go
index 19e0115..cc5bc05 100644
--- a/route.go
+++ b/route.go
@@ -63,3 +63,30 @@ func (r Routes) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintln(w, v)
}
}
+
+func NewRoute(e Entry) (Route, error) {
+ fail := func(err error) (Route, error) { return Route{}, err }
+ host, err := url.Parse(e.Host)
+ if err != nil {
+ return fail(err)
+ }
+ up, err := url.Parse(e.Upstream)
+ if err != nil {
+ return fail(err)
+ }
+ r := Route{
+ ServerName: host,
+ Upstream: up,
+ }
+ if host.Scheme == "https" {
+ if e.Cert == nil || e.Key == nil {
+ return fail(ErrNoCert)
+ }
+ cert, err := tls.X509KeyPair(e.Cert, e.Key)
+ if err != nil {
+ return fail(err)
+ }
+ r.Certificate = &cert
+ }
+ return r, nil
+}