aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-03-29 16:14:13 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-03-29 16:14:13 +0200
commitfa2bf59b65accbfd0ac2491d6c263ff7e7ad8f58 (patch)
tree80fe9ad2adc56708634753ba4df4376a545d3092
parent3fcb64b17e34832df64e5dbbd268e7dad4b2c240 (diff)
Switch to JSON for persistent storage
-rw-r--r--cmd/goxy/main.go2
-rw-r--r--server.go12
2 files changed, 7 insertions, 7 deletions
diff --git a/cmd/goxy/main.go b/cmd/goxy/main.go
index 7932bfa..f4ce583 100644
--- a/cmd/goxy/main.go
+++ b/cmd/goxy/main.go
@@ -9,7 +9,7 @@ import (
_ "net/http/pprof"
)
-var data = flag.String("data", "data/goxy.gob", "persistent storage file")
+var data = flag.String("data", "data/goxy.json", "persistent storage file")
func main() {
flag.Parse()
diff --git a/server.go b/server.go
index 6f0fe48..159362a 100644
--- a/server.go
+++ b/server.go
@@ -2,7 +2,7 @@ package goxy
import (
"crypto/tls"
- "encoding/gob"
+ "encoding/json"
"net/http"
"net/http/httputil"
"net/url"
@@ -33,7 +33,7 @@ func (s Server) Save() error {
return err
}
defer fd.Close()
- return gob.NewEncoder(fd).Encode(s.Route)
+ return json.NewEncoder(fd).Encode(s.Route)
}
return nil
}
@@ -46,7 +46,7 @@ func (s *Server) Load() error {
return err
}
defer fd.Close()
- return gob.NewDecoder(fd).Decode(&s.Route)
+ return json.NewDecoder(fd).Decode(&s.Route)
}
return nil
}
@@ -81,10 +81,10 @@ func (s *Server) Restore() error {
return nil
}
-func (s *Server) Start() <-chan error {
- errc := make(chan error, 3)
+func (s *Server) Start() error {
+ errc := make(chan error)
go func() { errc <- s.ListenAndServe() }()
go func() { errc <- s.ListenAndServeTLS("", "") }()
go func() { errc <- http.ListenAndServe(":http-alt", nil) }()
- return errc
+ return <-errc
}