翔云

Just try, don't shy. 最新文章请点击
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

golang web framework--Martini

Posted on 2019-01-19 22:21  翔云123456  阅读(290)  评论(0)    收藏  举报

Martini是一个功能强大的软件包,用于在Golang中快速编写模块化Web应用程序/服务。

下载

$ go get github.com/go-martini/martini

Demo

server.go

//server.go
package main

import "github.com/go-martini/martini"

func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"
  })
  m.Run()
}

启动一个HTTP server,监听3000端口。

编译和执行

$ go build server.go
$ ./server
[martini] listening on :3000 (development)
[martini] Started GET / for [::1]:57956
[martini] Completed 200 OK in 184.546µs

client请求

$ curl http://localhost:3000
Hello world!%

参考

github martini