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

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>

猜你喜欢

转载自www.cnblogs.com/taoshihan/p/11872721.html
go