diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2016-03-30 11:17:28 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2016-03-30 11:17:28 +0200 |
commit | 3071e59632c668696f8bf1c6d9e3bc07b61f6391 (patch) | |
tree | ce807d29390f0f3590d1af0d68eee3ef9acd6921 /route.go | |
parent | b0eac3a85d7b2ddeb82214d4d4527d0dd73f5523 (diff) |
Cleanuprefactor
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 |