aboutsummaryrefslogtreecommitdiff
path: root/route.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-03-30 11:17:28 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-03-30 11:17:28 +0200
commit3071e59632c668696f8bf1c6d9e3bc07b61f6391 (patch)
treece807d29390f0f3590d1af0d68eee3ef9acd6921 /route.go
parentb0eac3a85d7b2ddeb82214d4d4527d0dd73f5523 (diff)
Cleanuprefactor
Diffstat (limited to 'route.go')
-rw-r--r--route.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/route.go b/route.go
index 3c83bef..93a18d3 100644
--- a/route.go
+++ b/route.go
@@ -2,7 +2,9 @@ package goxy
import (
"crypto/tls"
+ "encoding/json"
"errors"
+ "os"
)
// Route defines a set of routes including correspondent TLS certificates
@@ -16,6 +18,26 @@ func (r Route) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certificate, error)
return nil, errors.New("no cert for " + h.ServerName)
}
+// Save routes to persistent file
+func (r Route) Save(fname string) error {
+ fd, err := os.Create(fname)
+ if err != nil {
+ return err
+ }
+ defer fd.Close()
+ return json.NewEncoder(fd).Encode(r)
+}
+
+// Load routes from persistent file
+func (r *Route) Load(fname string) error {
+ fd, err := os.Open(fname)
+ if err != nil {
+ return err
+ }
+ defer fd.Close()
+ return json.NewDecoder(fd).Decode(r)
+}
+
// Entry holds routing settings
type Entry struct {
Host string // HostName