本文整理汇总了Golang中html/template.Must函数的典型用法代码示例。如果您正苦于以下问题:Golang Must函数的具体用法?Golang Must怎么用?Golang Must使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Must函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
ALL_METHODS = []string{GET, HEAD, POST, CONNECT, DELETE, OPTIONS, PUT, TRACE}
defaultMimeTypes = make(map[string]string)
defaultMimeTypes[".htm"] = MIME_TYPE_HTML
defaultMimeTypes[".html"] = MIME_TYPE_HTML
defaultMimeTypes[".xhtml"] = MIME_TYPE_XHTML_XML
defaultMimeTypes[".xml"] = MIME_TYPE_XML
defaultMimeTypes[".css"] = MIME_TYPE_CSS
defaultMimeTypes[".js"] = MIME_TYPE_JAVASCRIPT
defaultMimeTypes[".json"] = MIME_TYPE_JSON
defaultMimeTypes[".jpg"] = MIME_TYPE_JPEG
defaultMimeTypes[".jpeg"] = MIME_TYPE_JPEG
defaultMimeTypes[".gif"] = MIME_TYPE_GIF
defaultMimeTypes[".png"] = MIME_TYPE_PNG
defaultMimeTypes[".ico"] = MIME_TYPE_ICO
defaultMimeTypes[".swf"] = MIME_TYPE_SWF
defaultMimeTypes[".zip"] = MIME_TYPE_ZIP
defaultMimeTypes[".bz2"] = MIME_TYPE_BZIP2
defaultMimeTypes[".gz"] = MIME_TYPE_GZ
defaultMimeTypes[".tar"] = MIME_TYPE_TAR
defaultMimeTypes[".tgz"] = MIME_TYPE_GZ
defaultMimeTypes[".htc"] = MIME_TYPE_COMPONENT
defaultMimeTypes[".manifest"] = MIME_TYPE_CACHE_MANIFEST
defaultMimeTypes[".svg"] = MIME_TYPE_SVG
defaultMimeTypes[".txt"] = MIME_TYPE_TEXT_PLAIN
defaultMimeTypes[".text"] = MIME_TYPE_TEXT_PLAIN
defaultMimeTypes[".csv"] = MIME_TYPE_CSV
var err error
HTML_DIRECTORY_LISTING_SUCCESS_TEMPLATE, err = template.New("directory_listing_success").Parse(HTML_DIRECTORY_LISTING_SUCCESS_TEMPLATE_STRING)
template.Must(HTML_DIRECTORY_LISTING_SUCCESS_TEMPLATE, err)
HTML_DIRECTORY_LISTING_ERROR_TEMPLATE, err = template.New("directory_listing_error").Parse(HTML_DIRECTORY_LISTING_ERROR_TEMPLATE_STRING)
template.Must(HTML_DIRECTORY_LISTING_ERROR_TEMPLATE, err)
}
开发者ID:pomack,项目名称:webmachine.go,代码行数:35,代码来源:const.go
示例2: InitAdminTemplates
func InitAdminTemplates() {
serverPage = template.Must(template.ParseFiles("views/admin/templates/server.html"))
banlogsTempl = template.Must(template.ParseFiles("views/admin/templates/ban_logs.html"))
chatLogsTempl = template.Must(template.ParseFiles("views/admin/templates/chatlogs.html"))
lobbiesTempl = template.Must(template.ParseFiles("views/admin/templates/lobbies.html"))
adminPageTempl = template.Must(template.ParseFiles("views/admin/index.html"))
}
开发者ID:TF2Stadium,项目名称:Helen,代码行数:7,代码来源:templates.go
示例3: Login
func (c *Controller) Login() (string, error) {
var pool_tech_works int
funcMap := template.FuncMap{
"noescape": func(s string) template.HTML {
return template.HTML(s)
},
}
data, err := static.Asset("static/templates/login.html")
if err != nil {
return "", err
}
modal, err := static.Asset("static/templates/modal.html")
if err != nil {
return "", err
}
t := template.Must(template.New("template").Funcs(funcMap).Parse(string(data)))
t = template.Must(t.Parse(string(modal)))
b := new(bytes.Buffer)
// есть ли установочный пароль и был ли начально записан ключ
var setupPassword bool
if !c.Community {
setupPassword_, err := c.Single("SELECT setup_password FROM config").String()
if err != nil {
return "", err
}
myKey, err := c.GetMyPublicKey(c.MyPrefix)
if err != nil {
return "", err
}
if len(myKey) == 0 && (len(setupPassword_) > 0 || setupPassword_ == string(utils.DSha256(""))) {
setupPassword = true
}
}
//fmt.Println(c.Lang)
// проверим, не идут ли тех. работы на пуле
if len(c.NodeConfig["pool_admin_user_id"]) > 0 && c.NodeConfig["pool_admin_user_id"] != utils.Int64ToStr(c.UserId) && c.NodeConfig["pool_tech_works"] == "1" && c.Community {
pool_tech_works = 1
} else {
pool_tech_works = 0
}
err = t.ExecuteTemplate(b, "login", &loginStruct{
Lang: c.Lang,
MyModalIdName: "myModalLogin",
UserID: c.UserId,
PoolTechWorks: pool_tech_works,
SetupPassword: setupPassword,
Community: c.Community,
Desktop: utils.Desktop(),
Mobile: utils.Mobile()})
if err != nil {
return "", err
}
return b.String(), nil
}
开发者ID:dzyk,项目名称:dcoin-go,代码行数:60,代码来源:login.go
示例4: init
func init() {
http.HandleFunc("/", authOnly(root))
http.HandleFunc("/sign", authOnly(sign))
guestbookTemplate = template.Must(template.ParseFiles("tmpl/index.tmpl"))
signinTemplate = template.Must(template.ParseFiles("tmpl/signin.tmpl"))
}
开发者ID:nickdufresne,项目名称:gae-guestbook-bootstrap-go,代码行数:7,代码来源:guestbook.go
示例5: TestTemplate_FuncMap_url
func TestTemplate_FuncMap_url(t *testing.T) {
app := kocha.NewTestApp()
funcMap := template.FuncMap(app.Template.FuncMap)
func() {
tmpl := template.Must(template.New("test").Funcs(funcMap).Parse(`{{url "root"}}`))
var buf bytes.Buffer
if err := tmpl.Execute(&buf, nil); err != nil {
panic(err)
}
actual := buf.String()
expected := "/"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %q, but %q", expected, actual)
}
}()
func() {
tmpl := template.Must(template.New("test").Funcs(funcMap).Parse(`{{url "user" 713}}`))
var buf bytes.Buffer
if err := tmpl.Execute(&buf, nil); err != nil {
panic(err)
}
actual := buf.String()
expected := "/user/713"
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expect %v, but %v", expected, actual)
}
}()
}
开发者ID:naoina,项目名称:kocha,代码行数:30,代码来源:template_test.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng