helper

package
v1.0.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MimeTypeNOSNIFF = "nosniff"

MimeTypeNOSNIFF — значение заголовка X-Content-Type-Options для предотвращения MIME-сниффинга.

Variables

This section is empty.

Functions

func JSONError

func JSONError(w http.ResponseWriter, err *Error, code int)

JSONError отправляет ошибку в формате JSON. Устанавливает заголовки Content-Type и X-Content-Type-Options.

Пример:

helper.JSONError(w, helper.NewError("user not found"), http.StatusNotFound)

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, err string, code int)

WriteError отправляет ошибку в формате JSON или plain text в зависимости от заголовков Accept и Content-Type запроса.

Если клиент ожидает JSON (application/json), отправляет JSON-ответ. Иначе отправляет plain text через http.Error.

Пример:

helper.WriteError(w, r, "user not found", http.StatusNotFound)

Types

type Error

type Error struct {
	Message string `json:"Message"`
}

Error — структура ошибки для JSON-ответов.

func NewError

func NewError(error string) *Error

NewError создаёт новую ошибку.

func (*Error) Error

func (e *Error) Error() string

Error возвращает сообщение об ошибке. Реализует интерфейс Message.

Jump to

Keyboard shortcuts

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