🦈🏠🐜 Initial Commit 🐜🦈🏠

This commit is contained in:
Jason
2022-02-14 16:45:10 -05:00
commit 964ab574ea
23 changed files with 2384 additions and 0 deletions

40
http/error.go Normal file
View File

@@ -0,0 +1,40 @@
package http
import "net/http"
type appError struct {
Error error
Message string
Code int
ContentType string
}
func internalServerError(err error) *appError {
return &appError{
Error: err,
Message: "Internal server error",
Code: http.StatusInternalServerError,
}
}
func notFound(err error) *appError {
return &appError{Error: err, Code: http.StatusNotFound}
}
func badRequest(err error) *appError {
return &appError{Error: err, Code: http.StatusBadRequest}
}
func (e *appError) AsJSON() *appError {
e.ContentType = jsonMediaType
return e
}
func (e *appError) WithMessage(message string) *appError {
e.Message = message
return e
}
func (e *appError) IsJSON() bool {
return e.ContentType == jsonMediaType
}