当前位置: 移动技术网 > IT编程>脚本编程>Go语言 > [Go] gocron源码阅读-go语言web框架Macaron

[Go] gocron源码阅读-go语言web框架Macaron

2019年11月17日  | 移动技术网IT编程  | 我要评论

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>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网