Default interval and exit on server failure

master
Bel LaPointe 2018-10-09 17:42:37 -06:00
parent d30b2633aa
commit 38e1fc44d3
1 changed files with 7 additions and 3 deletions

View File

@ -27,14 +27,16 @@ func New(addr string, newItemHandler func(string, string, string, time.Duration)
func (s *Server) Serve() error {
var err error
sigc := make(chan os.Signal)
go func() {
port := s.addr
if !strings.HasPrefix(port, ":") {
port = ":" + port
}
err = http.ListenAndServe(port, s)
if err = http.ListenAndServe(port, s); err != nil {
sigc <- syscall.SIGINT
}
}()
sigc := make(chan os.Signal)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
@ -94,7 +96,9 @@ func (s *Server) newItem(w http.ResponseWriter, r *http.Request) {
Refresh string `json:"refresh"`
ItemFilter string `json:"items"`
ContentFilter string `json:"content"`
}{}
}{
Refresh: "3h",
}
if err := json.NewDecoder(r.Body).Decode(&newItemBody); err != nil {
s.bad(w, r)
return