The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
aeshfawre

有人用过 go 的 martini 框架么?

  •  
  •   aeshfawre · Dec 25, 2014 · 2531 views
    This topic created in 4336 days ago, the information mentioned may be changed or developed.

    用的是框架的demo,增加了一个get和post的处理

    m:=martini.Classic()
    m.Get("/add",AddTask)
    m.Post("/add",AddTask)
    
    func AddTask(res http.ResponseWriter,req *http.Request)string{
    //  req.ParseForm()
        u:=req.FormValue("u")
        p:=req.FormValue("p")
        return u+" "+p
    }
    

    这里是同样一个函数,为什么get方法和post方法的处理时间相差了100倍呢,我哪里用错了么,求教育

    [martini] Started POST /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 225.794884ms
    [martini] Started POST /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 226.507443ms
    [martini] Started GET /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 1.674314ms
    [martini] Started GET /add for 192.168.1.103:4920
    [martini] Completed 200 OK in 1.099566ms

    10 replies  •  2015-01-23 10:17:34 +08:00
    aeshfawre
    aeshfawre
    OP
    Dec 25, 2014
    1
    求关注,都没遇到过这问题么?
    tysx
    tysx
    Dec 25, 2014
    2
    完整代码呢?
    aeshfawre
    aeshfawre
    OP
    Dec 25, 2014
    3
    这个代码已经就是完整的了,import 和func main就这两行省略了,还一行 m.run
    我这里做了点分析. 发送数据包是用火车头里面的那个httppostget程序.
    在win7 64系统中发送post包,martini这边的处理时间就会200多ms
    在虚拟机的xp系统中发送post包,处理时间就是正常的,

    用httpdebugger截取了两个系统中发送的post包,是一模一样的,没区别.

    所以我猜测可能是多出来的时间是发生在发起http连接的步骤中,具体怎么样的原因就不清楚了.
    可能只是httppostget这个程序的坑吧,只是这样猜测.
    这个问题影响不大.结贴
    lyric
    lyric
    Dec 25, 2014❤️1
    4
    OS X 下差不多的性能,非 Product 环境

    [martini] Started GET /echo for 127.0.0.1:50571
    [martini] Completed 200 OK in 151.042us
    [martini] Started POST /echo for 127.0.0.1:50572
    [martini] Completed 200 OK in 254.716us
    datou552211
    datou552211
    Dec 25, 2014❤️1
    5
    难道在post里面做了crsf验证
    aeshfawre
    aeshfawre
    OP
    Dec 25, 2014
    6
    @lyric 你那里的get和post的处理时间相差不大的,我这里的是差了很多.可能只是我这里发送post包的程序有点问题
    aeshfawre
    aeshfawre
    OP
    Dec 25, 2014
    7
    @datou552211 没弄那个的
    defia
    defia
    Dec 28, 2014❤️1
    8
    @aeshfawre 你可以用 http://gin-gonic.github.io/gin/ 这个框架试试 martini比较慢的。。
    aeshfawre
    aeshfawre
    OP
    Dec 28, 2014
    9
    @defia 十分感谢,martini框架搜到的次数更多点,gin这个还真没找到过.
    l3i2
    l3i2
    Jan 23, 2015
    10
    @aeshfawre, 用PostFormValue替代FormValue试一下?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1551 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:49 · PVG 21:49 · LAX 05:49 · JFK 08:49
    ♥ Do have faith in what you're doing.