gogmagog/routes/routes.go
Deepak 262321a1e2
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Adds auth route that checks username and password
2021-01-12 12:43:45 -06:00

31 lines
846 B
Go

package routes
import (
"encoding/json"
"gitea.deepak.science/deepak/gogmagog/models"
"github.com/go-chi/chi"
"net/http"
)
// NewRouter returns a router powered by the provided model.
func NewRouter(m *models.Model) http.Handler {
router := chi.NewRouter()
router.MethodNotAllowed(methodNotAllowedHandler)
router.NotFound(notFoundHandler)
router.Mount("/plans", newPlanRouter(m))
router.Mount("/actions", newActionRouter(m))
router.Mount("/auth", newAuthRouter(m))
router.Mount("/health", newHealthRouter(m))
router.Get("/ping", ping)
return router
}
func ping(w http.ResponseWriter, r *http.Request) {
// A very simple health check.
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(map[string]string{"ping": "pong"}); err != nil {
serverError(w, err)
}
}