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"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// User is a user
|
||||
|
@ -31,15 +36,18 @@ func main() {
|
|||
|
||||
vote.GetVotesOfTheDay()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", &User{})
|
||||
s := &http.Server{Addr: "localhost" + conf.HTTP.Address, Handler: mux}
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger)
|
||||
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")
|
||||
|
||||
if err := s.ListenAndServe(); err != nil {
|
||||
panic(err)
|
||||
log.Printf("listening on '%s'", conf.HTTP.Address)
|
||||
if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil {
|
||||
panic(errors.Wrapf(err, "error while listening on '%s'", conf.HTTP.Address))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ServerHTTP is the entry point to all requests
|
||||
|
|
Loading…
Reference in New Issue