gocron源码中使用的是马卡龙框架,下面这个就是安装这个框架,和一般的mvc框架很像
go get gopkg.in/macaron.v1
git clone https://github.com/golang/crypto.git $gopath/src/golang.org/x/crypto
监听80端口,使用模板引擎的简单例子
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 ,名字和你调用模板的名字对应
index.tmpl
<h2>{{.name}}</h2>
如对本文有疑问, 点击进行留言回复!!
网友评论