2023-10-24 17:39:15 -04:00
|
|
|
package apiresponse
|
2023-08-19 15:49:57 -04:00
|
|
|
|
2023-10-24 17:39:15 -04:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
2023-08-23 15:43:10 -04:00
|
|
|
|
2023-08-19 15:49:57 -04:00
|
|
|
type Responder interface {
|
|
|
|
Respond() Responder
|
|
|
|
}
|
|
|
|
|
|
|
|
type Response struct {
|
|
|
|
StatusCode int `json:"status_code"`
|
|
|
|
Message string
|
2023-08-19 19:25:13 -04:00
|
|
|
Error string
|
2023-08-19 15:49:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r Response) Respond() Responder {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-08-22 15:24:57 -04:00
|
|
|
type SimpleResponse struct {
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r SimpleResponse) Respond() Responder {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:01:57 -04:00
|
|
|
func NotFoundResponse() (int, SimpleResponse) {
|
|
|
|
return http.StatusNotFound, SimpleResponse{
|
2023-08-22 15:24:57 -04:00
|
|
|
Message: "Not Found",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 15:43:10 -04:00
|
|
|
func NotImplementedResponse() (int, SimpleResponse) {
|
|
|
|
return http.StatusNotImplemented, SimpleResponse{
|
|
|
|
Message: "Not Implemented",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 17:39:15 -04:00
|
|
|
func InternalServerErrorResponse() (int, SimpleResponse) {
|
|
|
|
return http.StatusInternalServerError, SimpleResponse{
|
|
|
|
Message: "Internal Server Error",
|
|
|
|
}
|
|
|
|
}
|