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:
parent
2bb911111c
commit
129d731a95
2 changed files with 25 additions and 3 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue