render
import "github.com/gin-gonic/gin/render"
Functions
func WriteJSON(w http.ResponseWriter, obj any) error
WriteJSON marshals the given interface object and writes it with custom ContentType.
func WriteMsgPack(w http.ResponseWriter, obj any) error
WriteMsgPack writes MsgPack ContentType and encodes the given interface object.
func WriteString(w http.ResponseWriter, format string, data []any) (err error)
WriteString writes data according to its format and write custom ContentType.
Types
type AsciiJSON
AsciiJSON contains the given interface object.
type AsciiJSON struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (AsciiJSON) marshals the given interface object and writes it with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (AsciiJSON) writes JSON ContentType.
type BSON
BSON contains the given interface object.
type BSON struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (BSON) marshals the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (BSONBuf) writes BSONBuf ContentType.
type Data
Data contains ContentType and bytes data.
type Data struct {
ContentType string
Data []byte
}Fields
ContentType stringData []byte
func Render(w http.ResponseWriter) (err error)
Render (Data) writes data with custom ContentType.
func 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
}Fields
Left stringLeft delimiter, defaults to {{.
Right stringRight delimiter, defaults to }}.
type HTML
HTML contains template reference and its name with given interface object.
type HTML struct {
Template *template.Template
Name string
Data any
}Fields
Template *template.TemplateName stringData any
func Render(w http.ResponseWriter) error
Render (HTML) executes template and writes its result with custom ContentType for response.
func 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
FileSystem http.FileSystem
Patterns []string
Delims Delims
FuncMap template.FuncMap
}Fields
Files []stringGlob stringFileSystem http.FileSystemPatterns []stringDelims DelimsFuncMap template.FuncMap
func 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
}Fields
Template *template.TemplateDelims Delims
func 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
}Methods
Instance func(string, any) RenderInstance returns an HTML instance.
type IndentedJSON
IndentedJSON contains the given interface object.
type IndentedJSON struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (IndentedJSON) writes JSON ContentType.
type JSON
JSON contains the given interface object.
type JSON struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (JSON) writes data with custom ContentType.
func 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
}Fields
Callback stringData any
func Render(w http.ResponseWriter) (err error)
Render (JsonpJSON) marshals the given interface object and writes it and its callback with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (JsonpJSON) writes Javascript ContentType.
type MsgPack
MsgPack contains the given interface object.
type MsgPack struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (MsgPack) encodes the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (MsgPack) writes MsgPack ContentType.
type PDF
PDF contains the given PDF binary data.
type PDF struct {
Data []byte
}Fields
Data []byte
func Render(w http.ResponseWriter) error
Render (PDF) writes PDF data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (PDF) writes PDF ContentType for response.
type ProtoBuf
ProtoBuf contains the given interface object.
type ProtoBuf struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (ProtoBuf) writes ProtoBuf ContentType.
type PureJSON
PureJSON contains the given interface object.
type PureJSON struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (PureJSON) writes custom ContentType and encodes the given interface object.
func 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
}Fields
ContentType stringContentLength int64Reader io.ReaderHeaders map[string]string
func Render(w http.ResponseWriter) (err error)
Render (Reader) writes data with custom ContentType and headers.
func 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
}Fields
Code intRequest *http.RequestLocation string
func Render(w http.ResponseWriter) error
Render (Redirect) redirects the http request to new location and writes redirect response.
func 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)
}Methods
Render func(http.ResponseWriter) errorRender writes data with custom ContentType.
WriteContentType func(w http.ResponseWriter)WriteContentType writes custom ContentType.
type SecureJSON
SecureJSON contains the given interface object and its prefix.
type SecureJSON struct {
Prefix string
Data any
}Fields
Prefix stringData any
func Render(w http.ResponseWriter) error
Render (SecureJSON) marshals the given interface object and writes it with custom ContentType.
func 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
}Fields
Format stringData []any
func Render(w http.ResponseWriter) error
Render (String) writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (String) writes Plain ContentType.
type TOML
TOML contains the given interface object.
type TOML struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (TOML) marshals the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (TOML) writes TOML ContentType for response.
type XML
XML contains the given interface object.
type XML struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (XML) encodes the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (XML) writes XML ContentType for response.
type YAML
YAML contains the given interface object.
type YAML struct {
Data any
}Fields
Data any
func Render(w http.ResponseWriter) error
Render (YAML) marshals the given interface object and writes data with custom ContentType.
func WriteContentType(w http.ResponseWriter)
WriteContentType (YAML) writes YAML ContentType for response.