Browse Source

Added timeouts, fixed last route not sending data

master
Gisle Aune 7 years ago
parent
commit
84e21b163e
  1. 12
      router.go

12
router.go

@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strings"
"time"
"git.aiterp.net/gisle/notebook3/session"
@ -71,6 +72,7 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(404)
w.Write([]byte("Not Found: " + req.URL.Path))
}
func (router *Router) Resource(mount string, list, create Func, get, update, delete IDFunc) {
@ -82,5 +84,13 @@ func (router *Router) Static(mount string, filePath string) {
}
func (router *Router) Listen(host string, port int) error {
return http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), router)
srv := &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
Handler: router,
}
return srv.ListenAndServe()
}
Loading…
Cancel
Save