resp

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 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.

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 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 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