一个由 faygo 创建的项目基本包含如下几部分:
- 新建框架实例
app := faygo.New("myapp", "0.1")
- 编写接口操作
type Index struct {
Id int `param:"<in:path> <required> <desc:ID> <range: 0:10>"`
Title string `param:"<in:query> <nonzero>"`
Paragraph []string `param:"<in:query> <name:p> <len: 1:10> <regexp: ^[\\w]*$>"`
Cookie string `param:"<in:cookie> <name:faygoID>"`
// Picture *multipart.FileHeader `param:"<in:formData> <name:pic> <maxmb:30>"`
}
func (i *Index) Serve(ctx *faygo.Context) error {
if ctx.CookieParam("faygoID") == "" {
ctx.SetCookie("faygoID", time.Now().String())
}
return ctx.JSON(200, i)
}
- 注册路由
app.GET("/index/:id", &Index{})
- 运行服务
faygo.Run()
- 目录
- 上一节: 1.1 安装 faygo
- 下一章: 2 创建服务