diff options
Diffstat (limited to 'route.go')
-rw-r--r-- | route.go | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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 |