码迷,mamicode.com
首页 > Web开发 > 详细

golang web framework--Martini

时间:2019-01-19 22:53:37      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:func   port   http   github   启动   pac   cli   imp   work   

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

golang web framework--Martini

标签:func   port   http   github   启动   pac   cli   imp   work   

原文地址:https://www.cnblogs.com/lanyangsh/p/10293491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!