Improve binapi generator
[govpp.git] / binapi / vrrp / vrrp_rest.ba.go
diff --git a/binapi/vrrp/vrrp_rest.ba.go b/binapi/vrrp/vrrp_rest.ba.go
new file mode 100644 (file)
index 0000000..35cedfe
--- /dev/null
@@ -0,0 +1,106 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package vrrp
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "net/http"
+)
+
+func RESTHandler(rpc RPCService) http.Handler {
+       mux := http.NewServeMux()
+       mux.HandleFunc("/vrrp_vr_add_del", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(VrrpVrAddDel)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.VrrpVrAddDel(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/vrrp_vr_set_peers", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(VrrpVrSetPeers)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.VrrpVrSetPeers(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/vrrp_vr_start_stop", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(VrrpVrStartStop)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.VrrpVrStartStop(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/vrrp_vr_track_if_add_del", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(VrrpVrTrackIfAddDel)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.VrrpVrTrackIfAddDel(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       return http.HandlerFunc(mux.ServeHTTP)
+}