use go-chi
This commit is contained in:
parent
86c2cf49f0
commit
cbd85b5326
22
server.go
22
server.go
|
@ -8,6 +8,11 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi"
|
||||||
|
"github.com/go-chi/chi/middleware"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// User is a user
|
// User is a user
|
||||||
|
@ -31,15 +36,18 @@ func main() {
|
||||||
|
|
||||||
vote.GetVotesOfTheDay()
|
vote.GetVotesOfTheDay()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
r := chi.NewRouter()
|
||||||
mux.Handle("/", &User{})
|
r.Use(middleware.Logger)
|
||||||
s := &http.Server{Addr: "localhost" + conf.HTTP.Address, Handler: mux}
|
r.Use(middleware.Recoverer)
|
||||||
|
r.Use(middleware.Timeout(60 * time.Second))
|
||||||
|
r.Handle("/", &User{})
|
||||||
|
r.Handle("/results", &User{})
|
||||||
|
|
||||||
log.Print("\nready: listening on localhost" + conf.HTTP.Address + "\n")
|
log.Printf("listening on '%s'", conf.HTTP.Address)
|
||||||
|
if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil {
|
||||||
if err := s.ListenAndServe(); err != nil {
|
panic(errors.Wrapf(err, "error while listening on '%s'", conf.HTTP.Address))
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerHTTP is the entry point to all requests
|
// ServerHTTP is the entry point to all requests
|
||||||
|
|
Loading…
Reference in New Issue