summaryrefslogtreecommitdiffstats
path: root/sms-service
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-03-06 16:18:49 -0800
committerGirish Havaldar <hg0071052@techmahindra.com>2018-03-07 04:01:39 +0000
commit6125e317c3d61c87eaa9ea4d05c2687ca117325f (patch)
tree1d71b22f5e8cd162b124786eb96305e2ed3a7eea /sms-service
parentce2498616ae1a81debadec35233d82b0ef7b8657 (diff)
Changing json encoding of response
Updating the json encoding to use Marshal This is to allow us to set the right return Header type and also return the right status codes Issue-ID: AAF-160 Change-Id: Ib260e5b8306b16069c57f6b83efcf401747ff2b6 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service')
-rw-r--r--sms-service/src/sms/handler/handler.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/sms-service/src/sms/handler/handler.go b/sms-service/src/sms/handler/handler.go
index 496b782..4456806 100644
--- a/sms-service/src/sms/handler/handler.go
+++ b/sms-service/src/sms/handler/handler.go
@@ -50,14 +50,16 @@ func (h handler) createSecretDomainHandler(w http.ResponseWriter, r *http.Reques
return
}
- err = json.NewEncoder(w).Encode(dom)
+ jdata, err := json.Marshal(dom)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+ w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
+ w.Write(jdata)
}
// deleteSecretDomainHandler deletes a secret domain with the name provided
@@ -113,12 +115,15 @@ func (h handler) getSecretHandler(w http.ResponseWriter, r *http.Request) {
return
}
- err = json.NewEncoder(w).Encode(sec)
+ jdata, err := json.Marshal(sec)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+
+ w.Header().Set("Content-Type", "application/json")
+ w.Write(jdata)
}
// listSecretHandler handles listing all secrets under a particular domain name
@@ -133,12 +138,15 @@ func (h handler) listSecretHandler(w http.ResponseWriter, r *http.Request) {
return
}
- err = json.NewEncoder(w).Encode(sec)
+ jdata, err := json.Marshal(sec)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+
+ w.Header().Set("Content-Type", "application/json")
+ w.Write(jdata)
}
// deleteSecretHandler handles deleting a secret by given domain name and secret name
@@ -170,12 +178,15 @@ func (h handler) statusHandler(w http.ResponseWriter, r *http.Request) {
}
status := backendStatus{Seal: s}
- err = json.NewEncoder(w).Encode(status)
+ jdata, err := json.Marshal(status)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+
+ w.Header().Set("Content-Type", "application/json")
+ w.Write(jdata)
}
// loginHandler handles login via password and username