response

package
v0.0.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 4 Imported by: 0

README

response

import "github.com/agentstation/starmap/internal/server/response"

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

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 OK

func OK(w http.ResponseWriter, data any)

OK writes a successful response with 200 status.

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.

type Error

Error represents an API error with code, message, and optional details.

type Error struct {
    Code    string `json:"code"`
    Message string `json:"message"`
    Details string `json:"details,omitempty"`
}

type Response

Response represents the standardized API response structure. All endpoints return this format for consistency.

type Response struct {
    Data  any    `json:"data" swaggertype:"object"`
    Error *Error `json:"error,omitempty"`
}

func Fail
func Fail(code, message, details string) Response

Fail creates an error response.

func Success
func Success(data any) Response

Success creates a successful response with data.

Generated by gomarkdoc

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

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 OK

func OK(w http.ResponseWriter, data any)

OK writes a successful response with 200 status.

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.

type Response

type Response struct {
	Data  any    `json:"data" swaggertype:"object"`
	Error *Error `json:"error,omitempty"`
}

Response represents the standardized API response structure. All endpoints return this format for consistency.

func Fail

func Fail(code, message, details string) Response

Fail creates an error response.

func Success

func Success(data any) Response

Success creates a successful response with data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL