diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-09-30 21:30:06 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-10-01 17:20:15 +0000 |
commit | 80107dc294c86a452c6108ffca6f281b4dbb9192 (patch) | |
tree | c246b3a46307dc851a8a2866655609d42e210c23 /src/dcm/api/keyValueHandler.go | |
parent | 5e114cd8a05986b7762fb9db22a43d61bb9fe00e (diff) |
Subtle refactoring in a few functions
In DCM.
Essentially refactored two different areas:
- rename apply/terminate functions in module to clarify what they do
- split gets from getAlls in API code of the 5 DCM resource types
And cleaned up here and there.
Issue-ID: MULTICLOUD-1143
Change-Id: I9b72c77ba34a1febd5df4a339e87968ddc4a7891
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/api/keyValueHandler.go')
-rw-r--r-- | src/dcm/api/keyValueHandler.go | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/dcm/api/keyValueHandler.go b/src/dcm/api/keyValueHandler.go index a4a4f14a..69333efb 100644 --- a/src/dcm/api/keyValueHandler.go +++ b/src/dcm/api/keyValueHandler.go @@ -33,7 +33,6 @@ type keyValueHandler struct { } // CreateHandler handles creation of the key value entry in the database - func (h keyValueHandler) createHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) project := vars["project-name"] @@ -71,6 +70,30 @@ func (h keyValueHandler) createHandler(w http.ResponseWriter, r *http.Request) { } } +// getHandler handles GET operations over key-value pairs +// Returns a list of Key Values +func (h keyValueHandler) getAllHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + project := vars["project-name"] + logicalCloud := vars["logical-cloud-name"] + var ret interface{} + var err error + + ret, err = h.client.GetAllKVPairs(project, logicalCloud) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + // getHandler handle GET operations on a particular name // Returns a Key Value func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) { @@ -81,22 +104,14 @@ func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) { var ret interface{} var err error - if len(name) == 0 { - ret, err = h.client.GetAllKVPairs(project, logicalCloud) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } else { - ret, err = h.client.GetKVPair(project, logicalCloud, name) - if err != nil { - if err.Error() == "KV Pair does not exist" { - http.Error(w, err.Error(), http.StatusNotFound) - return - } - http.Error(w, err.Error(), http.StatusInternalServerError) + ret, err = h.client.GetKVPair(project, logicalCloud, name) + if err != nil { + if err.Error() == "KV Pair does not exist" { + http.Error(w, err.Error(), http.StatusNotFound) return } + http.Error(w, err.Error(), http.StatusInternalServerError) + return } w.Header().Set("Content-Type", "application/json") |