aboutsummaryrefslogtreecommitdiff
path: root/route.go
diff options
context:
space:
mode:
Diffstat (limited to 'route.go')
-rw-r--r--route.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/route.go b/route.go
index c9d05e0..f66d076 100644
--- a/route.go
+++ b/route.go
@@ -8,8 +8,10 @@ import (
"net/url"
)
+// Route defines a set of routes including correspondent TLS certificates
type Route map[string]Entry
+// Entry holds routing settings
type Entry struct {
ServerName string
Upstream string
@@ -18,6 +20,7 @@ type Entry struct {
cert *tls.Certificate
}
+// GetCertificate returns certificate for SNI negotiation
func (r Route) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certificate, error) {
if e, ok := r[h.ServerName]; ok && e.cert != nil {
return e.cert, nil
@@ -25,6 +28,7 @@ func (r Route) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certificate, error)
return nil, errors.New("no cert for " + h.ServerName)
}
+// Restore and update routes from in-memory state
func (r Route) Restore() error {
mux := http.NewServeMux()
for k, v := range route {
@@ -47,9 +51,9 @@ func (r Route) Restore() error {
}
func (e Entry) String() string {
+ ret := e.ServerName + " -> " + e.Upstream
if e.cert != nil {
- return e.ServerName + " -> " + e.Upstream + " with TLS"
- } else {
- return e.ServerName + " -> " + e.Upstream
+ ret += " with TLS"
}
+ return ret
}