render

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSON

func WriteJSON(w http.ResponseWriter, obj interface{}) (err error)

WriteJSON marshals the given interface object and writes it with custom ContentType.

func WriteMsgPack

func WriteMsgPack(w http.ResponseWriter, obj interface{}) error

WriteMsgPack writes MsgPack ContentType and encodes the given interface object.

func WriteString

func WriteString(w http.ResponseWriter, format string, data []interface{}) (err error)

WriteString writes data according to its format and write custom ContentType.

Types

type Data

type Data struct {
	ContentType string
	Data        []byte
}

Data contains ContentType and bytes data.

func (Data) Render

func (r Data) Render(w http.ResponseWriter) (err error)

Render (Data) writes data with custom ContentType.

func (Data) WriteContentType

func (r Data) WriteContentType(w http.ResponseWriter)

WriteContentType (Data) writes custom ContentType.

type JSON

type JSON struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	TTL     int         `json:"ttl"`
	Data    interface{} `json:"data,omitempty"`
}

JSON contains the given interface object.

func (JSON) Render

func (r JSON) Render(w http.ResponseWriter) error

Render (JSON) writes data with custom ContentType.

func (JSON) WriteContentType

func (r JSON) WriteContentType(w http.ResponseWriter)

WriteContentType (JSON) writes JSON ContentType.

type JsonpJSON

type JsonpJSON struct {
	Callback string
	Data     interface{}
}

JsonpJSON contains the given interface object its callback.

func (JsonpJSON) Render

func (r JsonpJSON) Render(w http.ResponseWriter) (err error)

Render (JsonpJSON) marshals the given interface object and writes it and its callback with custom ContentType.

func (JsonpJSON) WriteContentType

func (r JsonpJSON) WriteContentType(w http.ResponseWriter)

WriteContentType (JsonpJSON) writes Javascript ContentType.

type MsgPack

type MsgPack struct {
	Data interface{}
}

MsgPack contains the given interface object.

func (MsgPack) Render

func (r MsgPack) Render(w http.ResponseWriter) error

Render (MsgPack) encodes the given interface object and writes data with custom ContentType.

func (MsgPack) WriteContentType

func (r MsgPack) WriteContentType(w http.ResponseWriter)

WriteContentType (MsgPack) writes MsgPack ContentType.

type ProtoBuf

type ProtoBuf struct {
	Data interface{}
}

ProtoBuf contains the given interface object.

func (ProtoBuf) Render

func (r ProtoBuf) Render(w http.ResponseWriter) error

Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.

func (ProtoBuf) WriteContentType

func (r ProtoBuf) WriteContentType(w http.ResponseWriter)

WriteContentType (ProtoBuf) writes ProtoBuf ContentType.

type Reader

type Reader struct {
	ContentType   string
	ContentLength int64
	Reader        io.Reader
	Headers       map[string]string
}

Reader contains the IO reader and its length, and custom ContentType and other headers.

func (Reader) Render

func (r Reader) Render(w http.ResponseWriter) (err error)

Render (Reader) writes data with custom ContentType and headers.

func (Reader) WriteContentType

func (r Reader) WriteContentType(w http.ResponseWriter)

WriteContentType (Reader) writes custom ContentType.

type Redirect

type Redirect struct {
	Code     int
	Request  *http.Request
	Location string
}

Redirect contains the http request reference and redirects status code and location.

func (Redirect) Render

func (r Redirect) Render(w http.ResponseWriter) error

Render (Redirect) redirects the http request to new location and writes redirect response.

func (Redirect) WriteContentType

func (r Redirect) WriteContentType(http.ResponseWriter)

WriteContentType (Redirect) don't write any ContentType.

type Render

type Render interface {
	// Render writes data with custom ContentType.
	Render(http.ResponseWriter) error
	// WriteContentType writes custom ContentType.
	WriteContentType(w http.ResponseWriter)
}

Render interface is to be implemented by JSON, XML, HTML, YAML and so on.

type String

type String struct {
	Format string
	Data   []interface{}
}

String contains the given interface object slice and its format.

func (String) Render

func (r String) Render(w http.ResponseWriter) error

Render (String) writes data with custom ContentType.

func (String) WriteContentType

func (r String) WriteContentType(w http.ResponseWriter)

WriteContentType (String) writes Plain ContentType.

type XML

type XML struct {
	Data interface{}
}

XML contains the given interface object.

func (XML) Render

func (r XML) Render(w http.ResponseWriter) error

Render (XML) encodes the given interface object and writes data with custom ContentType.

func (XML) WriteContentType

func (r XML) WriteContentType(w http.ResponseWriter)

WriteContentType (XML) writes XML ContentType for response.

type YAML

type YAML struct {
	Data interface{}
}

YAML contains the given interface object.

func (YAML) Render

func (r YAML) Render(w http.ResponseWriter) error

Render (YAML) marshals the given interface object and writes data with custom ContentType.

func (YAML) WriteContentType

func (r YAML) WriteContentType(w http.ResponseWriter)

WriteContentType (YAML) writes YAML ContentType for response.

Jump to

Keyboard shortcuts

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