response

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	CONTENT_TYPE_JSON string = "application/json; charset=utf-8"
	CONTENT_TYPE_TEXT string = "text/plain; charset=utf-8"
)
View Source
const (
	JSON = JSONFormatter("")
	Text = TextFormatter("")
)

Variables

This section is empty.

Functions

func Failure

func Failure(w http.ResponseWriter, contentType string, message []byte, statusCode int)

func Success

func Success(w http.ResponseWriter, contentType string, body []byte)

Types

type ContentFormatter

type ContentFormatter interface {
	Success(w http.ResponseWriter, body any) error
	Failure(w http.ResponseWriter, body any, statusCode int) error
}

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents a wrapped error with custom message. Implements error interface and provides unwrapping capability.

func NewError

func NewError(msg string) *Error

NewError creates a new error with the specified message.

func WrapError

func WrapError(err error, msg string) *Error

WrapError wraps an existing error with additional message context. If message is empty, uses the original error's message.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message, implementing the error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error for error chain unwrapping.

type JSONFormatter

type JSONFormatter string

func (JSONFormatter) Failure

func (f JSONFormatter) Failure(w http.ResponseWriter, body any, statusCode int) error

func (JSONFormatter) Success

func (f JSONFormatter) Success(w http.ResponseWriter, body any) error

type TextFormatter

type TextFormatter string

func (TextFormatter) Failure

func (f TextFormatter) Failure(w http.ResponseWriter, body any, statusCode int) error

func (TextFormatter) Success

func (f TextFormatter) Success(w http.ResponseWriter, body any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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