summaryrefslogtreecommitdiffstats
path: root/api/dto/response.go
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-09-09 22:44:09 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-09-09 22:44:09 +0100
commitf1741a7faa9538e9b12ac60e0fbf6c7721a36059 (patch)
tree2b70b14fc20a8520718910a0cd2e0134790c6f53 /api/dto/response.go
Initial commit
Diffstat (limited to 'api/dto/response.go')
-rw-r--r--api/dto/response.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/api/dto/response.go b/api/dto/response.go
new file mode 100644
index 0000000..2c13218
--- /dev/null
+++ b/api/dto/response.go
@@ -0,0 +1,38 @@
+package dto
+
+import "fmt"
+
+type Response interface {
+ Error() string
+ Status() int
+}
+
+type OkResponse struct {
+ Code int `json:"code"`
+ Data interface{} `json:"data,omitempty"`
+}
+
+var _ Response = (*OkResponse)(nil)
+
+type ErrorResponse struct {
+ Code int `json:"code"`
+ Message string `json:"message"`
+}
+
+var _ Response = (*ErrorResponse)(nil)
+
+func (r *OkResponse) Status() int {
+ return r.Code
+}
+
+func (r *OkResponse) Error() string {
+ return fmt.Sprintf("HTTP status %d", r.Code)
+}
+
+func (r *ErrorResponse) Status() int {
+ return r.Code
+}
+
+func (r *ErrorResponse) Error() string {
+ return fmt.Sprintf("HTTP status %d: %s", r.Code, r.Message)
+}