From 36201858978ad9d2bea4cdc226a8980f2c97079a Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 2 Jun 2020 16:45:24 +0100 Subject: [PATCH] Simplify the response and account data info --- pkg/server/router.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/server/router.go b/pkg/server/router.go index 64a2dfb..ebf1951 100644 --- a/pkg/server/router.go +++ b/pkg/server/router.go @@ -65,6 +65,17 @@ func (s *Server) HandleStatus(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(response) } +// BasicResponse describes the minimum dataset for a response +type BasicResponse struct { + Success bool `json:"success"` + Error string `json:"error"` +} + +// BasicAccountData describes the data to be sent for an account specific post +type BasicAccountData struct { + Id string `json:"id"` +} + // RegisterData describes the data to send when registering type RegisterData struct { Name string `json:"name"` @@ -72,10 +83,9 @@ type RegisterData struct { // RegisterResponse describes the response to a register request type RegisterResponse struct { - Id string `json:"id"` + BasicResponse - Success bool `json:"success"` - Error string `json:"error"` + Id string `json:"id"` } // HandleRegister handles HTTP requests to the /register endpoint @@ -84,7 +94,9 @@ func (s *Server) HandleRegister(w http.ResponseWriter, r *http.Request) { // Set up the response var response = RegisterResponse{ - Success: false, + BasicResponse: BasicResponse{ + Success: false, + }, } // Verify we're hit with a get request