From 129d731a95b7d961f5c6a4601d7238a119844d25 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Mon, 22 May 2023 18:11:42 -0400 Subject: [PATCH] Add global message format --- extractor/utils.go | 23 ++++++++++++++++++++++- routes/users/users.go | 5 +++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/extractor/utils.go b/extractor/utils.go index 575c274..cee169d 100644 --- a/extractor/utils.go +++ b/extractor/utils.go @@ -9,5 +9,26 @@ func ProxyUrl(url string) string { encodedUrl := b64.StdEncoding.EncodeToString([]byte(url)) backendUrl := os.Getenv("URL") - return backendUrl + "/img/" + encodedUrl + return backendUrl + "/proxy/img/" + encodedUrl +} + +type ServerFormat struct { + Status string `json:"status"` + Message interface{} `json:"message"` +} + +func FormatMessage(data interface{}, ok bool) ServerFormat { + var status string + if ok { + status = "ok" + } else { + status = "error" + } + + serverFormat := ServerFormat{ + Status: status, + Message: data, + } + + return serverFormat } diff --git a/routes/users/users.go b/routes/users/users.go index ea28f01..d416756 100644 --- a/routes/users/users.go +++ b/routes/users/users.go @@ -20,8 +20,9 @@ func Routes(route *gin.Engine) { } else { context.Error(err) } - } else { - context.JSON(200, data) + return } + + context.JSON(200, extractor.FormatMessage(data, true)) }) }