render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Success reasons
	ReasonResolved = "resolved"
	ReasonListed   = "listed"
	ReasonCreated  = "created"
	ReasonUpdated  = "updated"
	ReasonDeleted  = "deleted"
	ReasonIgnored  = "ignored"

	// Error reasons
	ReasonUnauthorized   = "unauthorized"
	ReasonForbidden      = "forbidden"
	ReasonNotFound       = "not_found"
	ReasonUserNotFound   = "user_not_found"
	ReasonBadRequest     = "bad_request"
	ReasonInternalError  = "internal_error"
	ReasonNotImplemented = "not_implemented"
	ReasonInvalidToken   = "invalid_token"
)

Reason codes for API responses

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter)

BadRequest writes error with 400 status

func BadRequestWithReason

func BadRequestWithReason(w http.ResponseWriter, reason string)

BadRequestWithReason writes error with 400 status and custom reason

func Created

func Created(w http.ResponseWriter, data interface{})

Created writes a success response with 201 status

func Error

func Error(w http.ResponseWriter, reason string, status int)

Error writes an error response with the given reason code

func Forbidden

func Forbidden(w http.ResponseWriter)

Forbidden writes error with 403 status

func InternalError

func InternalError(w http.ResponseWriter)

InternalError writes error with 500 status

func InternalErrorf

func InternalErrorf(w http.ResponseWriter, format string, a ...interface{})

InternalErrorf writes formatted error with 500 status

func NotFound

func NotFound(w http.ResponseWriter)

NotFound writes error with 404 status

func NotFoundWithReason

func NotFoundWithReason(w http.ResponseWriter, reason string)

NotFoundf writes formatted error with 404 status

func NotImplemented

func NotImplemented(w http.ResponseWriter)

NotImplemented writes error with 501 status

func OK

func OK(w http.ResponseWriter, reason string, data interface{})

OK writes a success response with 200 status and custom reason

func Paginated

func Paginated(w http.ResponseWriter, data interface{}, hasMore bool)

Paginated writes a success response with pagination info

func Success

func Success(w http.ResponseWriter, reason string, data interface{}, status int)

Success writes a success response with the given reason code

func Unauthorized

func Unauthorized(w http.ResponseWriter)

Unauthorized writes error with 401 status

func UnauthorizedWithReason

func UnauthorizedWithReason(w http.ResponseWriter, reason string)

UnauthorizedWithReason writes error with 401 status and custom reason

Types

type PaginatedResponse

type PaginatedResponse struct {
	Error   bool        `json:"error"`
	Reason  string      `json:"reason"`
	HasMore bool        `json:"has_more"`
	Data    interface{} `json:"data"`
}

PaginatedResponse represents a paginated API response

type Response

type Response struct {
	Error  bool        `json:"error"`
	Reason string      `json:"reason"`
	Data   interface{} `json:"data"`
}

Response represents a Crisp-style API response

Jump to

Keyboard shortcuts

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