import (
"encoding/json"
"github.com/gorilla/mux"
+ "io/ioutil"
"net/http"
)
const (
- ReadyURL = "/ric/v1/health/ready"
- AliveURL = "/ric/v1/health/alive"
+ ReadyURL = "/ric/v1/health/ready"
+ AliveURL = "/ric/v1/health/alive"
+ ConfigURL = "/ric/v1/cm/{name}"
)
type StatusCb func() bool
// Inject default routes for health probes
r.InjectRoute(ReadyURL, readyHandler, "GET")
r.InjectRoute(AliveURL, aliveHandler, "GET")
+ r.InjectRoute(ConfigURL, configHandler, "POST")
return r
}
respondWithJSON(w, http.StatusOK, nil)
}
+func configHandler(w http.ResponseWriter, r *http.Request) {
+ xappName := mux.Vars(r)["name"]
+ if xappName == "" || r.Body == nil {
+ respondWithJSON(w, http.StatusBadRequest, nil)
+ return
+ }
+ defer r.Body.Close()
+
+ body, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ Logger.Error("ioutil.ReadAll failed: %v", err)
+ respondWithJSON(w, http.StatusInternalServerError, nil)
+ return
+ }
+
+ if err := PublishConfigChange(xappName, string(body)); err != nil {
+ respondWithJSON(w, http.StatusInternalServerError, nil)
+ return
+ }
+
+ respondWithJSON(w, http.StatusOK, nil)
+}
+
func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)