|
@ -4,6 +4,7 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"git.aiterp.net/gisle/notebook3/session" |
|
|
"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.Header().Set("Content-Type", "text/plain; charset=utf-8") |
|
|
w.WriteHeader(404) |
|
|
w.WriteHeader(404) |
|
|
|
|
|
w.Write([]byte("Not Found: " + req.URL.Path)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (router *Router) Resource(mount string, list, create Func, get, update, delete IDFunc) { |
|
|
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 { |
|
|
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() |
|
|
} |
|
|
} |