Improve binapi generator
[govpp.git] / binapi / ipip / ipip_rest.ba.go
diff --git a/binapi/ipip/ipip_rest.ba.go b/binapi/ipip/ipip_rest.ba.go
new file mode 100644 (file)
index 0000000..63fe220
--- /dev/null
@@ -0,0 +1,106 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package ipip
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "net/http"
+)
+
+func RESTHandler(rpc RPCService) http.Handler {
+       mux := http.NewServeMux()
+       mux.HandleFunc("/ipip_6rd_add_tunnel", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(Ipip6rdAddTunnel)
+               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.Ipip6rdAddTunnel(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("/ipip_6rd_del_tunnel", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(Ipip6rdDelTunnel)
+               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.Ipip6rdDelTunnel(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("/ipip_add_tunnel", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(IpipAddTunnel)
+               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.IpipAddTunnel(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("/ipip_del_tunnel", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(IpipDelTunnel)
+               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.IpipDelTunnel(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)
+}