[lxc-devel] [lxd/master] shared/api: Don't re-define fields

stgraber on Github lxc-bot at linuxcontainers.org
Thu Aug 23 20:35:49 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180823/a43a1797/attachment.bin>
-------------- next part --------------
From 41d9834550bebf41c1dd410afcf91581f3a79477 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 23 Aug 2018 16:34:05 -0400
Subject: [PATCH] shared/api: Don't re-define fields
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/response.go        | 33 ++++++++++++++-------------------
 shared/api/response.go | 13 ++++++++++++-
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/lxd/response.go b/lxd/response.go
index b33394383c..f4feb09769 100644
--- a/lxd/response.go
+++ b/lxd/response.go
@@ -68,11 +68,10 @@ func (r *syncResponse) Render(w http.ResponseWriter) error {
 	}
 
 	resp := api.ResponseRaw{
-		Response: api.Response{
-			Type:       api.SyncResponse,
-			Status:     status.String(),
-			StatusCode: int(status)},
-		Metadata: r.metadata,
+		Type:       api.SyncResponse,
+		Status:     status.String(),
+		StatusCode: int(status),
+		Metadata:   r.metadata,
 	}
 
 	return util.WriteJSON(w, resp, debug)
@@ -355,13 +354,11 @@ func (r *operationResponse) Render(w http.ResponseWriter) error {
 	}
 
 	body := api.ResponseRaw{
-		Response: api.Response{
-			Type:       api.AsyncResponse,
-			Status:     api.OperationCreated.String(),
-			StatusCode: int(api.OperationCreated),
-			Operation:  url,
-		},
-		Metadata: md,
+		Type:       api.AsyncResponse,
+		Status:     api.OperationCreated.String(),
+		StatusCode: int(api.OperationCreated),
+		Operation:  url,
+		Metadata:   md,
 	}
 
 	w.Header().Set("Location", url)
@@ -394,13 +391,11 @@ func (r *forwardedOperationResponse) Render(w http.ResponseWriter) error {
 	url := fmt.Sprintf("/%s/operations/%s", version.APIVersion, r.op.ID)
 
 	body := api.ResponseRaw{
-		Response: api.Response{
-			Type:       api.AsyncResponse,
-			Status:     api.OperationCreated.String(),
-			StatusCode: int(api.OperationCreated),
-			Operation:  url,
-		},
-		Metadata: r.op,
+		Type:       api.AsyncResponse,
+		Status:     api.OperationCreated.String(),
+		StatusCode: int(api.OperationCreated),
+		Operation:  url,
+		Metadata:   r.op,
 	}
 
 	w.Header().Set("Location", url)
diff --git a/shared/api/response.go b/shared/api/response.go
index 2bfda07d67..4f4e044977 100644
--- a/shared/api/response.go
+++ b/shared/api/response.go
@@ -6,7 +6,18 @@ import (
 
 // ResponseRaw represents a LXD operation in its original form
 type ResponseRaw struct {
-	Response `yaml:",inline"`
+	Type ResponseType `json:"type" yaml:"type"`
+
+	// Valid only for Sync responses
+	Status     string `json:"status" yaml:"status"`
+	StatusCode int    `json:"status_code" yaml:"status_code"`
+
+	// Valid only for Async responses
+	Operation string `json:"operation" yaml:"operation"`
+
+	// Valid only for Error responses
+	Code  int    `json:"error_code" yaml:"error_code"`
+	Error string `json:"error" yaml:"error"`
 
 	Metadata interface{} `json:"metadata" yaml:"metadata"`
 }


More information about the lxc-devel mailing list