2020-05-29 17:56:26 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-05-30 23:18:05 +01:00
|
|
|
"fmt"
|
2020-05-29 17:56:26 +01:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2020-05-29 23:05:37 +01:00
|
|
|
"github.com/mdiluz/rove/pkg/rove"
|
2020-05-29 17:56:26 +01:00
|
|
|
)
|
|
|
|
|
2020-05-30 23:17:59 +01:00
|
|
|
// NewRouter sets up the server mux
|
2020-05-29 17:56:26 +01:00
|
|
|
func NewRouter() (router *mux.Router) {
|
|
|
|
router = mux.NewRouter().StrictSlash(true)
|
|
|
|
|
|
|
|
// Set up the handlers
|
|
|
|
router.HandleFunc("/status", HandleStatus)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// HandleStatus handles HTTP requests to the /status endpoint
|
|
|
|
func HandleStatus(w http.ResponseWriter, r *http.Request) {
|
2020-05-30 23:18:05 +01:00
|
|
|
fmt.Printf("%s\t%s", r.Method, r.RequestURI)
|
|
|
|
|
2020-05-29 23:05:37 +01:00
|
|
|
var status = rove.ServerStatus{
|
2020-05-29 17:56:26 +01:00
|
|
|
Ready: true,
|
|
|
|
}
|
|
|
|
|
2020-05-30 23:25:40 +01:00
|
|
|
// Be a good citizen and set the header for the return
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
// Reply with the current status
|
2020-05-29 17:56:26 +01:00
|
|
|
json.NewEncoder(w).Encode(status)
|
|
|
|
}
|