0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-03 03:10:05 -05:00

Add global message format

This commit is contained in:
dragongoose 2023-05-22 18:11:42 -04:00
parent 2bb911111c
commit 129d731a95
No known key found for this signature in database
GPG key ID: 50DB99B921579009
2 changed files with 25 additions and 3 deletions

View file

@ -9,5 +9,26 @@ func ProxyUrl(url string) string {
encodedUrl := b64.StdEncoding.EncodeToString([]byte(url)) encodedUrl := b64.StdEncoding.EncodeToString([]byte(url))
backendUrl := os.Getenv("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
} }

View file

@ -20,8 +20,9 @@ func Routes(route *gin.Engine) {
} else { } else {
context.Error(err) context.Error(err)
} }
} else { return
context.JSON(200, data)
} }
context.JSON(200, extractor.FormatMessage(data, true))
}) })
} }