encoder

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: 4 Imported by: 0

Documentation

Overview

Package encoder provides response encoding functionality for the context package. Feed encoder interface implementation into the context object when you reset it, and it will be used to encode response.

Typical usage:

enc := encoder.JSON
ctx.Reset(..., enc, ...)
// ...
if err := ctx.Encode(w, http.StatusOK, data); err != nil {
    ctx.Logger().Error(err.Error())
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// HTML encoder writes provided data into response as html text.
	HTML = Func(encodeHTML)
)
View Source
var (
	// JSON encoder writes provided data into response as json payload.
	JSON = Func(encodeJSON)
)
View Source
var (
	// Plain encoder writes provided data into response as plain text.
	Plain = Func(encodePlain)
)

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Encode(http.ResponseWriter, int, interface{}) error
}

Encoder interface that encodes arbitrary data and writes the result into http response.

type Func

type Func func(http.ResponseWriter, int, interface{}) error

Func is the function that implements Encoder interface by calling itself on Encode method.

func (Func) Encode

func (f Func) Encode(w http.ResponseWriter, status int, data interface{}) error

Encode method implements Encoder interface by calling the function itself.

Jump to

Keyboard shortcuts

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