Gin 渲染模板的方式

方式1:Go 标准库 “html/template”, template.ParseFiles() 方式2:“github.com/gin-gonic/gin”,gin.HTML()

一、Go 标准库 “html/template”

直接加载 login/inex.html Handler.go

// GetIndex

// @Tags 首页

// @contact.name Allan

// @Success 200 {string} 首页

// @Router /index [get]

func (app *Config) GetIndex(c *gin.Context) {

idx, err := template.ParseFiles("login/index.html")

if err != nil {

panic(err)

}

idx.Execute(c.Writer, "首页")

}

login/index.html