html

package
v0.51.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package html 提供输出 HTML 内容的解码函数

srv := NewServer()
tpl := template.ParseFiles(...)
srv.Mimetypes().Add("text/html", html.Marshal, nil)

func handle(ctx *web.Context) Responser {
    return Object(200, html.Tpl(tpl, "index", map[string]interface{}{...}), nil)
}

Index

Constants

View Source
const Mimetype = "text/html"

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any) ([]byte, error)

Marshal 针对 HTML 内容的解码实现

参数 v 可以是以下几种类型:

  • string 或是 []byte 将内容作为 HTML 内容直接输出
  • *Template 编译模板内容并输出
  • 其它情况下则是返回错误。

func Unmarshal added in v0.51.1

func Unmarshal(data []byte, v any) error

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template 传递给 Marshal 的参数

func Tpl

func Tpl(tpl *template.Template, name string, data any) *Template

Tpl 声明 *Template 实例

name 表示需要引用的模板名称; data 则是传递给该模板的所有变量;

Jump to

Keyboard shortcuts

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