参考链接:
https://github.com/alberliu/goweb?utm_source=tuicool&utm_medium=referral
一个基于go语言开发API的工具,这个工具受到了SpringMVC的启发,结合了go语言本身的特性,整体比较简单,接下来,看看如何使用它。
下载安装:
go get github.com/alberliu/goweb
package main
import "github.com/alberliu/goweb"
type User struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
func handler(id int64, name string) User {
return User{id, name}
}
func main() {
goweb := goweb.NewGoWeb();
goweb.HandleGet("/test/{id}/{name}", handler)
goweb.ListenAndServe(":8000")
}
执行上面的代码,然后访问
url:http://localhost:8000/test/123456/alber
就可以返回下面的json数据
{
"id": 123456,
"name": "alber"
}