utils

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Get  = httpClient.Get
	Post = httpClient.Post
	Head = httpClient.Head
)

Functions

func ErrInvalidKey

func ErrInvalidKey(k string) error

func ErrMissingKey

func ErrMissingKey(k string) error

func ErrNotFound

func ErrNotFound(k, v string) error

func HandleErr

func HandleErr(w http.ResponseWriter, r *http.Request, err error, code ...int)

HandleErr logs the error and returns an error code to the client. If code is specified, it will be used as the HTTP status code; otherwise, http.StatusInternalServerError is used.

The error is only logged but not returned to the client.

func LogDebug

func LogDebug(r *http.Request) *zerolog.Event

func LogError

func LogError(r *http.Request) *zerolog.Event

func LogInfo

func LogInfo(r *http.Request) *zerolog.Event

func LogWarn

func LogWarn(r *http.Request) *zerolog.Event

func PeriodicWS

func PeriodicWS(cfg config.ConfigInstance, w http.ResponseWriter, r *http.Request, interval time.Duration, do func(conn *websocket.Conn) error)

func RespondError

func RespondError(w http.ResponseWriter, err error, code ...int)

RespondError returns error details to the client. If code is specified, it will be used as the HTTP status code; otherwise, http.StatusBadRequest is used.

func RespondJSON

func RespondJSON(w http.ResponseWriter, r *http.Request, data any, code ...int) (canProceed bool)

func WriteBody

func WriteBody(w http.ResponseWriter, body []byte)

Types

This section is empty.

Jump to

Keyboard shortcuts

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