aboutsummaryrefslogtreecommitdiff
path: root/route.go
diff options
context:
space:
mode:
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