2017-01-29 19:06:56 +00:00
|
|
|
package webserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/NYTimes/gziphandler"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New creates a new webserver and starts it
|
|
|
|
func New(bindAddr, webroot string) *http.Server {
|
2017-10-12 13:25:00 +00:00
|
|
|
return &http.Server{
|
2017-01-29 19:06:56 +00:00
|
|
|
Addr: bindAddr,
|
|
|
|
Handler: gziphandler.GzipHandler(http.FileServer(http.Dir(webroot))),
|
|
|
|
}
|
2017-10-12 13:25:00 +00:00
|
|
|
}
|
2017-01-29 19:06:56 +00:00
|
|
|
|
2017-10-12 13:25:00 +00:00
|
|
|
func Start(srv *http.Server) {
|
|
|
|
// service connections
|
|
|
|
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-01-29 19:06:56 +00:00
|
|
|
}
|