2020-09-30 06:35:07 +00:00
|
|
|
package httpserver
|
|
|
|
|
2020-09-30 07:48:56 +00:00
|
|
|
import (
|
2020-10-01 04:59:20 +00:00
|
|
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
2020-09-30 07:48:56 +00:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
2020-09-30 06:35:07 +00:00
|
|
|
|
|
|
|
func (s *server) routes() {
|
|
|
|
s.router = mux.NewRouter()
|
2020-09-30 07:48:56 +00:00
|
|
|
|
2020-09-30 08:12:59 +00:00
|
|
|
authMiddleware := s.AuthMiddleware()
|
|
|
|
|
2020-09-30 06:35:07 +00:00
|
|
|
s.router.HandleFunc("/", s.handleIndex()).Methods("GET")
|
2020-09-30 08:12:59 +00:00
|
|
|
|
|
|
|
// if you want to use a general purpose middleware (http.Handler
|
|
|
|
// wrapper) on a specific HandleFunc route, you need to take the
|
2020-09-30 08:30:21 +00:00
|
|
|
// .ServeHTTP of the http.Handler to get its HandleFunc, viz:
|
2020-10-01 04:59:20 +00:00
|
|
|
s.router.HandleFunc(
|
2020-10-01 05:25:33 +00:00
|
|
|
"/login",
|
|
|
|
authMiddleware(s.handleLogin()).ServeHTTP,
|
2020-10-01 04:59:20 +00:00
|
|
|
).Methods("GET")
|
2020-09-30 08:12:59 +00:00
|
|
|
|
2020-10-01 04:59:20 +00:00
|
|
|
s.router.HandleFunc(
|
2020-10-01 05:25:33 +00:00
|
|
|
"/.well-known/healthcheck.json",
|
|
|
|
s.handleHealthCheck(),
|
2020-10-01 04:59:20 +00:00
|
|
|
).Methods("GET")
|
|
|
|
|
|
|
|
// route that panics for testing
|
|
|
|
// CHANGEME remove this
|
|
|
|
s.router.HandleFunc(
|
2020-10-01 05:25:33 +00:00
|
|
|
"/panic",
|
|
|
|
s.handlePanic(),
|
2020-10-01 04:59:20 +00:00
|
|
|
).Methods("GET")
|
2020-09-30 07:48:56 +00:00
|
|
|
|
2020-09-30 08:30:21 +00:00
|
|
|
// the Gorilla mux .Use() takes a http.Handler wrapper func, like
|
|
|
|
// most things that deal with "middlewares" like alice et c, and
|
|
|
|
// will call ServeHTTP on it. These middlewares applied by the mux
|
|
|
|
// (you can .Use() more than one) will be applied to every request
|
|
|
|
// into the service.
|
2020-09-30 07:48:56 +00:00
|
|
|
s.router.Use(s.LoggingMiddleware())
|
2020-10-01 04:59:20 +00:00
|
|
|
|
|
|
|
// this adds a sentry reporting middleware if and only if
|
|
|
|
// sentry is enabled via setting of SENTRY_DSN in env.
|
|
|
|
if s.sentryEnabled {
|
2020-10-01 05:11:53 +00:00
|
|
|
// Options docs at
|
|
|
|
// https://docs.sentry.io/platforms/go/guides/http/
|
2020-10-01 04:59:20 +00:00
|
|
|
sentryHandler := sentryhttp.New(sentryhttp.Options{})
|
|
|
|
s.router.Use(sentryHandler.Handle)
|
|
|
|
}
|
2020-09-30 06:35:07 +00:00
|
|
|
}
|