http

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 3 Imported by: 0

README

HTTP

This is a simple HTTP server powered by Fiber. With some customization to enchance the development experience and performance.

Documentation

Index

Constants

View Source
const (
	ErrorMetadataCode        = "code"
	ErrorMetadataUserMessage = "message"
)

Variables

This section is empty.

Functions

func JSONResponse added in v0.0.2

func JSONResponse(c fiber.Ctx, valSuccess *SuccessResponse, valError error) error

JSONResponse is the function that will be used to send a JSON response. For custome message, you can use gerr.Metadata to store the message. Raw error will show on your log message. Example:

 err := gerr.New("Connection Lost")
	return gerr.NewWithMetadata(err, http.Metadata(http.StatusBadRequest, "Internal Server Error"))

JSON Response:

 {
	"success": false,
	"message": "Internal Server Error",
 }

But if you want to show the raw error message to the user, you can leave ErrorMetadataUserMessage empty. Example:

 err := gerr.New("Connection Lost")
		return gerr.NewWithMetadata(err, http.Metadata(http.StatusBadRequest, ""))

JSON Response:

 {
	"success": false,
	"message": "Connection Lost",
 }

func Metadata added in v0.0.3

func Metadata(code int, message string, keyPairs ...interface{}) gerr.Metadata

HTTPMetadata is the function that will be used to create a metadata for HTTP response.

keyPairs must be in the format of key, value, key, value, ...

Types

type SuccessResponse added in v0.0.5

type SuccessResponse struct {
	StatusCode int
	Message    string
	Data       interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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