...

Package render

import "github.com/gin-gonic/gin/render"
Overview
Index

Overview ▾

Index ▾

Variables
func WriteJSON(w http.ResponseWriter, obj any) error
func WriteMsgPack(w http.ResponseWriter, obj any) error
func WriteString(w http.ResponseWriter, format string, data []any) (err error)
type AsciiJSON
    func (r AsciiJSON) Render(w http.ResponseWriter) (err error)
    func (r AsciiJSON) WriteContentType(w http.ResponseWriter)
type Data
    func (r Data) Render(w http.ResponseWriter) (err error)
    func (r Data) WriteContentType(w http.ResponseWriter)
type Delims
type HTML
    func (r HTML) Render(w http.ResponseWriter) error
    func (r HTML) WriteContentType(w http.ResponseWriter)
type HTMLDebug
    func (r HTMLDebug) Instance(name string, data any) Render
type HTMLProduction
    func (r HTMLProduction) Instance(name string, data any) Render
type HTMLRender
type IndentedJSON
    func (r IndentedJSON) Render(w http.ResponseWriter) error
    func (r IndentedJSON) WriteContentType(w http.ResponseWriter)
type JSON
    func (r JSON) Render(w http.ResponseWriter) error
    func (r JSON) WriteContentType(w http.ResponseWriter)
type JsonpJSON
    func (r JsonpJSON) Render(w http.ResponseWriter) (err error)
    func (r JsonpJSON) WriteContentType(w http.ResponseWriter)
type MsgPack
    func (r MsgPack) Render(w http.ResponseWriter) error
    func (r MsgPack) WriteContentType(w http.ResponseWriter)
type ProtoBuf
    func (r ProtoBuf) Render(w http.ResponseWriter) error
    func (r ProtoBuf) WriteContentType(w http.ResponseWriter)
type PureJSON
    func (r PureJSON) Render(w http.ResponseWriter) error
    func (r PureJSON) WriteContentType(w http.ResponseWriter)
type Reader
    func (r Reader) Render(w http.ResponseWriter) (err error)
    func (r Reader) WriteContentType(w http.ResponseWriter)
type Redirect
    func (r Redirect) Render(w http.ResponseWriter) error
    func (r Redirect) WriteContentType(http.ResponseWriter)
type Render
type SecureJSON
    func (r SecureJSON) Render(w http.ResponseWriter) error
    func (r SecureJSON) WriteContentType(w http.ResponseWriter)
type String
    func (r String) Render(w http.ResponseWriter) error
    func (r String) WriteContentType(w http.ResponseWriter)
type TOML
    func (r TOML) Render(w http.ResponseWriter) error
    func (r TOML) WriteContentType(w http.ResponseWriter)
type XML
    func (r XML) Render(w http.ResponseWriter) error
    func (r XML) WriteContentType(w http.ResponseWriter)
type YAML
    func (r YAML) Render(w http.ResponseWriter) error
    func (r YAML) WriteContentType(w http.ResponseWriter)

Package files

data.go html.go json.go msgpack.go protobuf.go reader.go redirect.go render.go text.go toml.go xml.go yaml.go

Variables

var TOMLContentType = []string{"application/toml; charset=utf-8"}

func WriteJSON

func WriteJSON(w http.ResponseWriter, obj any) error

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

func WriteMsgPack

func WriteMsgPack(w http.ResponseWriter, obj any) error

WriteMsgPack writes MsgPack ContentType and encodes the given interface object.

func WriteString

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

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

type AsciiJSON

AsciiJSON contains the given interface object.

type AsciiJSON struct {
    Data any
}

func (AsciiJSON) Render

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

Render (AsciiJSON) marshals the given interface object and writes it with custom ContentType.

func (AsciiJSON) WriteContentType

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

WriteContentType (AsciiJSON) writes JSON ContentType.

type Data

Data contains ContentType and bytes data.

type Data struct {
    ContentType string
    Data        []byte
}

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 Delims

Delims represents a set of Left and Right delimiters for HTML template rendering.

type Delims struct {
    // Left delimiter, defaults to {{.
    Left string
    // Right delimiter, defaults to }}.
    Right string
}

type HTML

HTML contains template reference and its name with given interface object.

type HTML struct {
    Template *template.Template
    Name     string
    Data     any
}

func (HTML) Render

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

Render (HTML) executes template and writes its result with custom ContentType for response.

func (HTML) WriteContentType

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

WriteContentType (HTML) writes HTML ContentType.

type HTMLDebug

HTMLDebug contains template delims and pattern and function with file list.

type HTMLDebug struct {
    Files   []string
    Glob    string
    Delims  Delims
    FuncMap template.FuncMap
}

func (HTMLDebug) Instance

func (r HTMLDebug) Instance(name string, data any) Render

Instance (HTMLDebug) returns an HTML instance which it realizes Render interface.

type HTMLProduction

HTMLProduction contains template reference and its delims.

type HTMLProduction struct {
    Template *template.Template
    Delims   Delims
}

func (HTMLProduction) Instance

func (r HTMLProduction) Instance(name string, data any) Render

Instance (HTMLProduction) returns an HTML instance which it realizes Render interface.

type HTMLRender

HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.

type HTMLRender interface {
    // Instance returns an HTML instance.
    Instance(string, any) Render
}

type IndentedJSON

IndentedJSON contains the given interface object.

type IndentedJSON struct {
    Data any
}

func (IndentedJSON) Render

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

Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.

func (IndentedJSON) WriteContentType

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

WriteContentType (IndentedJSON) writes JSON ContentType.

type JSON

JSON contains the given interface object.

type JSON struct {
    Data any
}

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

JsonpJSON contains the given interface object its callback.

type JsonpJSON struct {
    Callback string
    Data     any
}

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

MsgPack contains the given interface object.

type MsgPack struct {
    Data any
}

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

ProtoBuf contains the given interface object.

type ProtoBuf struct {
    Data any
}

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 PureJSON

PureJSON contains the given interface object.

type PureJSON struct {
    Data any
}

func (PureJSON) Render

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

Render (PureJSON) writes custom ContentType and encodes the given interface object.

func (PureJSON) WriteContentType

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

WriteContentType (PureJSON) writes custom ContentType.

type Reader

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

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

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

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

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

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

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

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

type SecureJSON

SecureJSON contains the given interface object and its prefix.

type SecureJSON struct {
    Prefix string
    Data   any
}

func (SecureJSON) Render

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

Render (SecureJSON) marshals the given interface object and writes it with custom ContentType.

func (SecureJSON) WriteContentType

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

WriteContentType (SecureJSON) writes JSON ContentType.

type String

String contains the given interface object slice and its format.

type String struct {
    Format string
    Data   []any
}

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 TOML

TOML contains the given interface object.

type TOML struct {
    Data any
}

func (TOML) Render

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

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

func (TOML) WriteContentType

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

WriteContentType (TOML) writes TOML ContentType for response.

type XML

XML contains the given interface object.

type XML struct {
    Data any
}

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

YAML contains the given interface object.

type YAML struct {
    Data any
}

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.