From c2456559a66107441addb96f673191bde09d6977 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Fri, 2 Oct 2020 16:36:32 +0200 Subject: Check retval value and convert to error in generated RPC client code Change-Id: I816b4802cb5fc46239f6db0480fa4cf3645fe2f0 Signed-off-by: Ondrej Fabry --- binapi/session/session.ba.go | 4 +- binapi/session/session_rest.ba.go | 235 -------------------------------------- binapi/session/session_rpc.ba.go | 22 ++-- 3 files changed, 13 insertions(+), 248 deletions(-) delete mode 100644 binapi/session/session_rest.ba.go (limited to 'binapi/session') diff --git a/binapi/session/session.ba.go b/binapi/session/session.ba.go index 09a67b0..6bb20b8 100644 --- a/binapi/session/session.ba.go +++ b/binapi/session/session.ba.go @@ -1,7 +1,7 @@ // Code generated by GoVPP's binapi-generator. DO NOT EDIT. // versions: -// binapi-generator: v0.4.0-dev -// VPP: 20.05-release +// binapi-generator: v0.4.0 +// VPP: 20.05.1-release // source: /usr/share/vpp/api/core/session.api.json // Package session contains generated bindings for API file session.api. diff --git a/binapi/session/session_rest.ba.go b/binapi/session/session_rest.ba.go deleted file mode 100644 index 1ef2085..0000000 --- a/binapi/session/session_rest.ba.go +++ /dev/null @@ -1,235 +0,0 @@ -// Code generated by GoVPP's binapi-generator. DO NOT EDIT. - -package session - -import ( - "encoding/json" - "io/ioutil" - "net/http" -) - -func RESTHandler(rpc RPCService) http.Handler { - mux := http.NewServeMux() - mux.HandleFunc("/app_add_cert_key_pair", func(w http.ResponseWriter, req *http.Request) { - var request = new(AppAddCertKeyPair) - 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.AppAddCertKeyPair(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("/app_attach", func(w http.ResponseWriter, req *http.Request) { - var request = new(AppAttach) - 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.AppAttach(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("/app_del_cert_key_pair", func(w http.ResponseWriter, req *http.Request) { - var request = new(AppDelCertKeyPair) - 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.AppDelCertKeyPair(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("/app_namespace_add_del", func(w http.ResponseWriter, req *http.Request) { - var request = new(AppNamespaceAddDel) - 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.AppNamespaceAddDel(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("/app_worker_add_del", func(w http.ResponseWriter, req *http.Request) { - var request = new(AppWorkerAddDel) - 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.AppWorkerAddDel(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("/application_detach", func(w http.ResponseWriter, req *http.Request) { - var request = new(ApplicationDetach) - reply, err := rpc.ApplicationDetach(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("/application_tls_cert_add", func(w http.ResponseWriter, req *http.Request) { - var request = new(ApplicationTLSCertAdd) - 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.ApplicationTLSCertAdd(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("/application_tls_key_add", func(w http.ResponseWriter, req *http.Request) { - var request = new(ApplicationTLSKeyAdd) - 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.ApplicationTLSKeyAdd(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("/session_enable_disable", func(w http.ResponseWriter, req *http.Request) { - var request = new(SessionEnableDisable) - 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.SessionEnableDisable(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("/session_rule_add_del", func(w http.ResponseWriter, req *http.Request) { - var request = new(SessionRuleAddDel) - 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.SessionRuleAddDel(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/binapi/session/session_rpc.ba.go b/binapi/session/session_rpc.ba.go index 3868572..58593a0 100644 --- a/binapi/session/session_rpc.ba.go +++ b/binapi/session/session_rpc.ba.go @@ -11,7 +11,7 @@ import ( vpe "git.fd.io/govpp.git/binapi/vpe" ) -// RPCService defines RPC service session. +// RPCService defines RPC service session. type RPCService interface { AppAddCertKeyPair(ctx context.Context, in *AppAddCertKeyPair) (*AppAddCertKeyPairReply, error) AppAttach(ctx context.Context, in *AppAttach) (*AppAttachReply, error) @@ -40,7 +40,7 @@ func (c *serviceClient) AppAddCertKeyPair(ctx context.Context, in *AppAddCertKey if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) AppAttach(ctx context.Context, in *AppAttach) (*AppAttachReply, error) { @@ -49,7 +49,7 @@ func (c *serviceClient) AppAttach(ctx context.Context, in *AppAttach) (*AppAttac if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) AppDelCertKeyPair(ctx context.Context, in *AppDelCertKeyPair) (*AppDelCertKeyPairReply, error) { @@ -58,7 +58,7 @@ func (c *serviceClient) AppDelCertKeyPair(ctx context.Context, in *AppDelCertKey if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) AppNamespaceAddDel(ctx context.Context, in *AppNamespaceAddDel) (*AppNamespaceAddDelReply, error) { @@ -67,7 +67,7 @@ func (c *serviceClient) AppNamespaceAddDel(ctx context.Context, in *AppNamespace if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) AppWorkerAddDel(ctx context.Context, in *AppWorkerAddDel) (*AppWorkerAddDelReply, error) { @@ -76,7 +76,7 @@ func (c *serviceClient) AppWorkerAddDel(ctx context.Context, in *AppWorkerAddDel if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) ApplicationDetach(ctx context.Context, in *ApplicationDetach) (*ApplicationDetachReply, error) { @@ -85,7 +85,7 @@ func (c *serviceClient) ApplicationDetach(ctx context.Context, in *ApplicationDe if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) ApplicationTLSCertAdd(ctx context.Context, in *ApplicationTLSCertAdd) (*ApplicationTLSCertAddReply, error) { @@ -94,7 +94,7 @@ func (c *serviceClient) ApplicationTLSCertAdd(ctx context.Context, in *Applicati if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) ApplicationTLSKeyAdd(ctx context.Context, in *ApplicationTLSKeyAdd) (*ApplicationTLSKeyAddReply, error) { @@ -103,7 +103,7 @@ func (c *serviceClient) ApplicationTLSKeyAdd(ctx context.Context, in *Applicatio if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) SessionEnableDisable(ctx context.Context, in *SessionEnableDisable) (*SessionEnableDisableReply, error) { @@ -112,7 +112,7 @@ func (c *serviceClient) SessionEnableDisable(ctx context.Context, in *SessionEna if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) SessionRuleAddDel(ctx context.Context, in *SessionRuleAddDel) (*SessionRuleAddDelReply, error) { @@ -121,7 +121,7 @@ func (c *serviceClient) SessionRuleAddDel(ctx context.Context, in *SessionRuleAd if err != nil { return nil, err } - return out, nil + return out, api.RetvalToVPPApiError(out.Retval) } func (c *serviceClient) SessionRulesDump(ctx context.Context, in *SessionRulesDump) (RPCService_SessionRulesDumpClient, error) { -- cgit 1.2.3-korg