api

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int    // HTTP status code
	ErrorCode  string // Custom error code
	Message    string // Error message
}

APIError is a structure for storing API error information

func BadRequestError

func BadRequestError(message string) *APIError

BadRequestError creates an APIError instance representing a BadRequest

func InternalServerError

func InternalServerError(message string) *APIError

InternalServerError creates an APIError instance representing an InternalServer error

func NewAPIError

func NewAPIError(statusCode int, errorCode, message string) *APIError

NewAPIError creates an instance of APIError

func NotFoundError

func NotFoundError(message string) *APIError

NotFoundError creates an APIError instance representing a NotFound

func UnauthorizedError

func UnauthorizedError(message string) *APIError

UnauthorizedError creates an APIError instance representing an Unauthorized

func (*APIError) Error

func (e *APIError) Error() string

Error method implements the error interface

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Response is a basic structure for API response

func NewErrorResponse

func NewErrorResponse(message string) Response

Create an error response

func NewSuccessResponse

func NewSuccessResponse(data interface{}) Response

Create a successful response

Jump to

Keyboard shortcuts

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