-
Notifications
You must be signed in to change notification settings - Fork 50
/
routes.go
31 lines (27 loc) · 967 Bytes
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"net/http"
"github.com/bitrise-io/bitrise-webhooks/internal/pubsub"
"github.com/bitrise-io/bitrise-webhooks/metrics"
"github.com/bitrise-io/bitrise-webhooks/service"
"github.com/bitrise-io/bitrise-webhooks/service/hook"
"github.com/bitrise-io/bitrise-webhooks/service/root"
"gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux"
)
func setupRoutes(pubsubClient *pubsub.Client) {
r := mux.NewRouter(mux.WithServiceName("webhooks"))
//
hookClient := hook.Client{PubsubClient: pubsubClient}
r.HandleFunc("/h/{service-id}/{app-slug}/{api-token}", metrics.WrapHandlerFunc(hookClient.HTTPHandler)).
Methods("POST")
//
r.HandleFunc("/", metrics.WrapHandlerFunc(root.HTTPHandler)).
Methods("GET")
//
r.NotFoundHandler = http.HandlerFunc(metrics.WrapHandlerFunc(routeNotFoundHandler))
//
http.Handle("/", r)
}
func routeNotFoundHandler(w http.ResponseWriter, r *http.Request) {
service.RespondWithNotFoundError(w, "Not Found")
}