Martini是一个功能强大的软件包,用于在Golang中快速编写模块化Web应用程序/服务。
$ go get github.com/go-martini/martini
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!%