tango框架的action 是不是需要每个路由都要定义一个struct 然后用这个struct来做为接收器并写个get方法

tablecell · 2019-11-04 10:05:26 · 842 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2019-11-04 10:05:26 的主题,其中的信息可能已经有所发展或是发生改变。

https://github.com/lunny/tango 上面的例子

import (
    "errors"
    "github.com/lunny/tango"
)

type Action struct {
    tango.JSON
}

func (Action) Get() interface{} {
    if true {
        return map[string]string{
            "say": "Hello tango!",
        }
    }
    return errors.New("something error")
}

func main() {
    t := tango.Classic()
    t.Get("/", new(Action))
    t.Run()
}

如果Get请求有不同的路由 比如

Get /aaa

Get /bbb

都会执行到同一个方法 如果要不同的操作,是不是需要每一个路由定义一个struct 然后用这个struct来做为接收器写个get方法 ?


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

842 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传