resp

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fail

func Fail(w http.ResponseWriter, r *Exception, abort ...bool)

Fail handles failure responses.

func Success

func Success(w http.ResponseWriter, data ...any)

Success handles success responses.

func WithStatusCode added in v0.1.5

func WithStatusCode(w http.ResponseWriter, statusCode int, data ...any)

WithStatusCode handles success responses with custom status code.

Types

type Exception

type Exception struct {
	Status  int    `json:"status,omitempty"`  // HTTP status
	Code    int    `json:"code,omitempty"`    // Business code
	Message string `json:"message,omitempty"` // Message
	Errors  any    `json:"errors,omitempty"`  // Validation errors
	Data    any    `json:"data,omitempty"`    // Response data
}

Exception represents the response structure.

func AlreadyExists

func AlreadyExists(message string, data ...any) *Exception

AlreadyExists indicates that the resource already exists.

func BadRequest

func BadRequest(message string, data ...any) *Exception

BadRequest indicates a bad request.

func Conflict

func Conflict(message string, data ...any) *Exception

Conflict indicates a conflict error.

func DBQuery

func DBQuery(message string, data ...any) *Exception

DBQuery indicates a database query error.

func Forbidden

func Forbidden(message string, data ...any) *Exception

Forbidden indicates access is forbidden.

func Gone added in v0.1.5

func Gone(message string, data ...any) *Exception

Gone indicates a gone error.

func InternalServer

func InternalServer(message string, data ...any) *Exception

InternalServer indicates a server error.

func NotAllowed

func NotAllowed(message string, data ...any) *Exception

NotAllowed indicates a not allowed error.

func NotExists

func NotExists(message string, data ...any) *Exception

NotExists indicates that the resource does not exist.

func NotFound

func NotFound(message string, data ...any) *Exception

NotFound indicates that the requested resource is not found.

func ServiceUnavailable added in v0.1.4

func ServiceUnavailable(message string, data ...any) *Exception

ServiceUnavailable indicates a service is unavailable.

func Transactions

func Transactions(message string, data ...any) *Exception

Transactions indicates a transaction processing failure.

func UnAuthorized

func UnAuthorized(message string, data ...any) *Exception

UnAuthorized indicates that the request is unauthorized.

Jump to

Keyboard shortcuts

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