Documentation
¶
Overview ¶
Package response provides standardized HTTP response structures and helpers for the Starmap API server. All API responses follow a consistent format with a data field for successful responses and an error field for failures.
Index ¶
- func BadRequest(w http.ResponseWriter, message, details string)
- func Created(w http.ResponseWriter, data any)
- func ErrorFromType(w http.ResponseWriter, err error)
- func InternalError(w http.ResponseWriter, err error)
- func JSON(w http.ResponseWriter, status int, resp Response)
- func MethodNotAllowed(w http.ResponseWriter, method string)
- func NotFound(w http.ResponseWriter, message, details string)
- func OK(w http.ResponseWriter, data any)
- func RateLimited(w http.ResponseWriter, message string)
- func ServiceUnavailable(w http.ResponseWriter, message string)
- func Unauthorized(w http.ResponseWriter, message, details string)
- type Error
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, message, details string)
BadRequest writes a 400 error response.
func Created ¶
func Created(w http.ResponseWriter, data any)
Created writes a successful response with 201 status.
func ErrorFromType ¶
func ErrorFromType(w http.ResponseWriter, err error)
ErrorFromType maps typed errors to appropriate HTTP responses.
func InternalError ¶
func InternalError(w http.ResponseWriter, err error)
InternalError writes a 500 error response.
func JSON ¶
func JSON(w http.ResponseWriter, status int, resp Response)
JSON writes a JSON response with the given status code.
func MethodNotAllowed ¶
func MethodNotAllowed(w http.ResponseWriter, method string)
MethodNotAllowed writes a 405 error response.
func NotFound ¶
func NotFound(w http.ResponseWriter, message, details string)
NotFound writes a 404 error response.
func RateLimited ¶
func RateLimited(w http.ResponseWriter, message string)
RateLimited writes a 429 error response.
func ServiceUnavailable ¶
func ServiceUnavailable(w http.ResponseWriter, message string)
ServiceUnavailable writes a 503 error response.
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, message, details string)
Unauthorized writes a 401 error response.
Types ¶
type Error ¶
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
Error represents an API error with code, message, and optional details.