From: Vladimir Lavor Date: Tue, 13 Oct 2020 11:59:25 +0000 (+0200) Subject: Generate VPE HTTP handler X-Git-Tag: v0.4.0~36 X-Git-Url: https://gerrit.fd.io/r/gitweb?p=govpp.git;a=commitdiff_plain;h=8d4ee12e94e634b38f1dc55c830f8e222822215f Generate VPE HTTP handler * This should fix GoVPP build Change-Id: If53177253ad4a6616860aad50ce54e5944bbea6e Signed-off-by: Vladimir Lavor --- diff --git a/binapi/gen.go b/binapi/gen.go index eec87da..ed9eed7 100644 --- a/binapi/gen.go +++ b/binapi/gen.go @@ -19,3 +19,4 @@ package binapi // go generate ./binapi // //go:generate binapi-generator -input-dir=/usr/share/vpp/api -output-dir=. -gen=rpc +//go:generate binapi-generator -input-file=/usr/share/vpp/api/core/vpe.api.json -output-dir=. -gen=http diff --git a/binapi/vpe/vpe_http.ba.go b/binapi/vpe/vpe_http.ba.go new file mode 100644 index 0000000..8998c9e --- /dev/null +++ b/binapi/vpe/vpe_http.ba.go @@ -0,0 +1,245 @@ +// Code generated by GoVPP's binapi-generator. DO NOT EDIT. + +package vpe + +import ( + "encoding/json" + "io/ioutil" + "net/http" +) + +func HTTPHandler(rpc RPCService) http.Handler { + mux := http.NewServeMux() + mux.HandleFunc("/add_node_next", func(w http.ResponseWriter, req *http.Request) { + var request = new(AddNodeNext) + 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.AddNodeNext(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("/cli", func(w http.ResponseWriter, req *http.Request) { + var request = new(Cli) + 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.Cli(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("/cli_inband", func(w http.ResponseWriter, req *http.Request) { + var request = new(CliInband) + 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.CliInband(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("/control_ping", func(w http.ResponseWriter, req *http.Request) { + var request = new(ControlPing) + reply, err := rpc.ControlPing(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("/get_f64_endian_value", func(w http.ResponseWriter, req *http.Request) { + var request = new(GetF64EndianValue) + 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.GetF64EndianValue(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("/get_f64_increment_by_one", func(w http.ResponseWriter, req *http.Request) { + var request = new(GetF64IncrementByOne) + 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.GetF64IncrementByOne(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("/get_next_index", func(w http.ResponseWriter, req *http.Request) { + var request = new(GetNextIndex) + 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.GetNextIndex(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("/get_node_graph", func(w http.ResponseWriter, req *http.Request) { + var request = new(GetNodeGraph) + reply, err := rpc.GetNodeGraph(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("/get_node_index", func(w http.ResponseWriter, req *http.Request) { + var request = new(GetNodeIndex) + 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.GetNodeIndex(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("/show_threads", func(w http.ResponseWriter, req *http.Request) { + var request = new(ShowThreads) + reply, err := rpc.ShowThreads(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("/show_version", func(w http.ResponseWriter, req *http.Request) { + var request = new(ShowVersion) + reply, err := rpc.ShowVersion(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("/show_vpe_system_time", func(w http.ResponseWriter, req *http.Request) { + var request = new(ShowVpeSystemTime) + reply, err := rpc.ShowVpeSystemTime(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) +} diff --git a/cmd/govpp/main.go b/cmd/govpp/main.go index f1ad5d8..98d5078 100644 --- a/cmd/govpp/main.go +++ b/cmd/govpp/main.go @@ -174,7 +174,7 @@ func runServer(apifiles []*vppapi.File, addr string) { } vpeRPC := vpe.NewServiceClient(conn) - c := vpe.RESTHandler(vpeRPC) + c := vpe.HTTPHandler(vpeRPC) http.Handle("/", c)