Render

render

github.com/gin-gonic/gin/render

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

Functions

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

Source: render/json.go:67

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

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

Source: render/msgpack.go:39

WriteMsgPack writes MsgPack ContentType and encodes the given interface object.

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

Source: render/text.go:33

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

Types

type AsciiJSON

Source: render/json.go:41

AsciiJSON contains the given interface object.

type AsciiJSON struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/json.go:155

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

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:179

WriteContentType (AsciiJSON) writes JSON ContentType.

type BSON

Source: render/bson.go:14

BSON contains the given interface object.

type BSON struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/bson.go:21

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

func WriteContentType(w http.ResponseWriter)

Source: render/bson.go:32

WriteContentType (BSONBuf) writes BSONBuf ContentType.

type Data

Source: render/data.go:13

Data contains ContentType and bytes data.

type Data struct {
	ContentType string
	Data        []byte
}
Fields
  • ContentType string
  • Data []byte

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

Source: render/data.go:19

Render (Data) writes data with custom ContentType.

func WriteContentType(w http.ResponseWriter)

Source: render/data.go:29

WriteContentType (Data) writes custom ContentType.

type Delims

Source: render/html.go:16

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
}
Fields
  • Left string

    Left delimiter, defaults to {{.

  • Right string

    Right delimiter, defaults to }}.

type HTML

Source: render/html.go:46

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

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

func Render(w http.ResponseWriter) error

Source: render/html.go:92

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

func WriteContentType(w http.ResponseWriter)

Source: render/html.go:105

WriteContentType (HTML) writes HTML ContentType.

type HTMLDebug

Source: render/html.go:36

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

type HTMLDebug struct {
	Files      []string
	Glob       string
	FileSystem http.FileSystem
	Patterns   []string
	Delims     Delims
	FuncMap    template.FuncMap
}
Fields
  • Files []string
  • Glob string
  • FileSystem http.FileSystem
  • Patterns []string
  • Delims Delims
  • FuncMap template.FuncMap

func Instance(name string, data any) Render

Source: render/html.go:66

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

type HTMLProduction

Source: render/html.go:30

HTMLProduction contains template reference and its delims.

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

func Instance(name string, data any) Render

Source: render/html.go:57

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

type HTMLRender

Source: render/html.go:24

HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.

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

    Instance returns an HTML instance.

type IndentedJSON

Source: render/json.go:24

IndentedJSON contains the given interface object.

type IndentedJSON struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/json.go:78

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

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:89

WriteContentType (IndentedJSON) writes JSON ContentType.

type JSON

Source: render/json.go:19

JSON contains the given interface object.

type JSON struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/json.go:57

Render (JSON) writes data with custom ContentType.

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:62

WriteContentType (JSON) writes JSON ContentType.

type JsonpJSON

Source: render/json.go:35

JsonpJSON contains the given interface object its callback.

type JsonpJSON struct {
	Callback string
	Data     any
}
Fields
  • Callback string
  • Data any

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

Source: render/json.go:117

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

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:150

WriteContentType (JsonpJSON) writes Javascript ContentType.

type MsgPack

Source: render/msgpack.go:22

MsgPack contains the given interface object.

type MsgPack struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/msgpack.go:34

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

func WriteContentType(w http.ResponseWriter)

Source: render/msgpack.go:29

WriteContentType (MsgPack) writes MsgPack ContentType.

type PDF

Source: render/pdf.go:10

PDF contains the given PDF binary data.

type PDF struct {
	Data []byte
}
Fields
  • Data []byte

func Render(w http.ResponseWriter) error

Source: render/pdf.go:17

Render (PDF) writes PDF data with custom ContentType.

func WriteContentType(w http.ResponseWriter)

Source: render/pdf.go:24

WriteContentType (PDF) writes PDF ContentType for response.

type ProtoBuf

Source: render/protobuf.go:14

ProtoBuf contains the given interface object.

type ProtoBuf struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/protobuf.go:21

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

func WriteContentType(w http.ResponseWriter)

Source: render/protobuf.go:34

WriteContentType (ProtoBuf) writes ProtoBuf ContentType.

type PureJSON

Source: render/json.go:46

PureJSON contains the given interface object.

type PureJSON struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/json.go:184

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

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:192

WriteContentType (PureJSON) writes custom ContentType.

type Reader

Source: render/reader.go:14

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
}
Fields
  • ContentType string
  • ContentLength int64
  • Reader io.Reader
  • Headers map[string]string

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

Source: render/reader.go:22

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

func WriteContentType(w http.ResponseWriter)

Source: render/reader.go:36

WriteContentType (Reader) writes custom ContentType.

type Redirect

Source: render/redirect.go:13

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

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

func Render(w http.ResponseWriter) error

Source: render/redirect.go:20

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

func WriteContentType(http.ResponseWriter)

Source: render/redirect.go:29

WriteContentType (Redirect) don't write any ContentType.

type Render

Source: render/render.go:10

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)
}
Methods
  • Render func(http.ResponseWriter) error

    Render writes data with custom ContentType.

  • WriteContentType func(w http.ResponseWriter)

    WriteContentType writes custom ContentType.

type SecureJSON

Source: render/json.go:29

SecureJSON contains the given interface object and its prefix.

type SecureJSON struct {
	Prefix string
	Data   any
}
Fields
  • Prefix string
  • Data any

func Render(w http.ResponseWriter) error

Source: render/json.go:94

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

func WriteContentType(w http.ResponseWriter)

Source: render/json.go:112

WriteContentType (SecureJSON) writes JSON ContentType.

type String

Source: render/text.go:15

String contains the given interface object slice and its format.

type String struct {
	Format string
	Data   []any
}
Fields
  • Format string
  • Data []any

func Render(w http.ResponseWriter) error

Source: render/text.go:23

Render (String) writes data with custom ContentType.

func WriteContentType(w http.ResponseWriter)

Source: render/text.go:28

WriteContentType (String) writes Plain ContentType.

type TOML

Source: render/toml.go:14

TOML contains the given interface object.

type TOML struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/toml.go:21

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

func WriteContentType(w http.ResponseWriter)

Source: render/toml.go:34

WriteContentType (TOML) writes TOML ContentType for response.

type XML

Source: render/xml.go:13

XML contains the given interface object.

type XML struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/xml.go:20

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

func WriteContentType(w http.ResponseWriter)

Source: render/xml.go:26

WriteContentType (XML) writes XML ContentType for response.

type YAML

Source: render/yaml.go:14

YAML contains the given interface object.

type YAML struct {
	Data any
}
Fields
  • Data any

func Render(w http.ResponseWriter) error

Source: render/yaml.go:21

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

func WriteContentType(w http.ResponseWriter)

Source: render/yaml.go:34

WriteContentType (YAML) writes YAML ContentType for response.