首页 > 其他 > 详细

golang 如何使用模版?

时间:2018-05-28 15:43:13      阅读:186      评论:0      收藏:0      [点我收藏+]
package main

import (
    "fmt"
    "net/http"
    "log"
    "html/template"
)

func main ()  {
    //实例化一个 HTTP
    app := http.NewServeMux();
    app.HandleFunc("/",func(w http.ResponseWriter,r *http.Request){
        switch r.Method {
        case "GET":
            tmpl,_ := template.ParseFiles("./View/home.html");
            tmpl.Execute(w,"Master");
        case "POST":
        case "PUT":
        case "DELETE":
        default:
        }
    });
    address := "127.0.0.1:80"
    fmt.Printf("Application: running using host(http://%s) \n",address);
    log.Fatal(http.ListenAndServe(address,app));
}

View/home.html

<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <center>
            <h1>Hello,My name is {{.}}</h1>
        </center>
    </body>
</html>

golang 如何使用模版?

原文:https://www.cnblogs.com/cheungxiongwei/p/9100326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!