Add api package serving our api routes using gorilla/mux

This commit is contained in:
Felix Auringer
2021-04-26 12:29:31 +02:00
parent 08eb05e00f
commit 38ecc02a79
5 changed files with 32 additions and 18 deletions

17
api/api.go Normal file
View File

@ -0,0 +1,17 @@
package api
import "github.com/gorilla/mux"
// NewRouter returns an HTTP handler (net.Handler) which can then
// be used by the net/http package to serve the api of our API.
// We use gorilla/mux because it is more convenient than net/http,
// e.g. when extracting path parameters.
func NewRouter() *mux.Router {
router := mux.NewRouter()
// this can later be restricted to a specific host with
// `router.Host(...)` and to HTTPS with `router.Schemes("https")`
v1 := router.PathPrefix("/api/v1").Subrouter()
v1.HandleFunc("/health", Health).Methods("GET")
return v1
}