common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 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 ErrorResponse

type ErrorResponse struct {
	Response     // Embed generic Response
	Code     int `json:"code,omitempty"`
}

ErrorResponse is a specific type for error responses. It embeds the generic Response and adds an optional Code field for more specific error identification. It's often useful to have error codes that your frontend can use to handle errors in a specific way

func NewErrorResponse

func NewErrorResponse(statusCode int, message string, data any) (int, ErrorResponse)

NewErrorResponse creates a new error response with the given message, optional data, and HTTP status code. It uses the ErrorResponse struct

type Response

type Response struct {
	Status  Status `json:"status"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Response is a generic struct for API responses. It includes a status, message, and optional data. The data field uses an any to allow it to hold any type of data

func NewSuccessResponse

func NewSuccessResponse(message string, data any) (int, Response)

NewSuccessResponse creates a new success response with the given message and optional data. It sets the HTTP status code to 200 OK

type Status

type Status string

Status represents the status of an API response

const (
	StatusSuccess Status = "success" // Successful API response
	StatusError   Status = "error"   // Error API response
)

Jump to

Keyboard shortcuts

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