gocron源码中使用的是马卡龙框架,下面这个就是安装这个框架,和通常的MVC框架很像
go get gopkg.in/macaron.v1
git clone https://github.com/golang/crypto.git $GOPATH/src/golang.org/x/cryptohtml
监听80端口,使用模板引擎的简单例子git
package main import "gopkg.in/macaron.v1" func main() { m := macaron.Classic() //使用模板引擎 m.Use(macaron.Renderer()) m.Get("/", func(ctx *macaron.Context) { ctx.Data["Name"] = "taoshihan" ctx.HTML(200, "index") // 200 为响应码 }) m.Run("0.0.0.0", 80) }
在当前目录下建立 templates/ , xxx.tmpl ,名字和你调用模板的名字对应github
index.tmplgolang
<h2>{{.Name}}</h2>