response

package
v0.0.0-...-93b1e75 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package response provides wrapper around http.ResponseWriter used inside context object, also it provides some commonly-used response payloads.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Unauthorized error response is supposed to be sent to the client on unauthorized error.
	Unauthorized = Error{Error: "unauthorized"}
	// BadRequest error response is supposed to be sent to the client on bad request error.
	BadRequest = Error{Error: "bad request"}
	// InternalError error response is supposed to be sent to the client on internal error.
	InternalError = Error{Error: "internal error"}
)
View Source
var (
	// Ok response is supposed to be sent to the client on success.
	Ok = Message{Message: "OK"}
)

Functions

This section is empty.

Types

type Error

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

Error structure provides the most basic error payload sent to the client.

func (Error) String

func (response Error) String() string

String method implements Stringer interface.

type Message

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

Message structure provides the most basic payload with message sent to the client.

func (Message) String

func (response Message) String() string

String method implements Stringer interface.

type Writer

type Writer struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Writer structure is a wrapper around http.ResponseWriter. It can be used to intercept and retrieve written http status. It is used inside context object and you won't probably use it yourself.

func (*Writer) HeaderWritten

func (w *Writer) HeaderWritten() bool

HeaderWritten method retrieves flag - is header already written or not.

func (*Writer) Reset

func (w *Writer) Reset(responseWriter http.ResponseWriter)

Reset method prepares structure for the next request.

func (*Writer) Status

func (w *Writer) Status() int

Status method retrieves written http status code.

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

Write method writes data into the response and calls WriteHeader method if header is not already written.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(status int)

WriteHeader method writes header into the response and intercepts status code.

Jump to

Keyboard shortcuts

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