duanjing1023 2014-11-04 08:30
浏览 99

Golang http:多个响应.WriteHeader调用

These days I was working on send message via websoket,using Beego framework. but meet the wrong message http: multiple response.WriteHeader calls Where is the problem? Any tips would be great!

func (this *WsController) Get() {
    fmt.Println("connected")
    handler(this.Ctx.ResponseWriter, this.Ctx.Request, this);
    conn, err := upgrader.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request, nil)
    if _, ok := err.(websocket.HandshakeError); ok {
        http.Error(this.Ctx.ResponseWriter, "Not a websocket handshake", 400)
        return
    } else if err != nil {
        return
    }
    fmt.Println("connected")
    connection := consumer.New(beego.AppConfig.String("LoggregatorAddress"), &tls.Config{InsecureSkipVerify: true}, nil)

    fmt.Println("===== Tailing messages")
    msgChan, err := connection.Tail(this.Ctx.Input.Param(":appGuid"), this.Ctx.Input.Param(":token"))

    if err != nil {
        fmt.Printf("===== Error tailing: %v
", err)
    } else {
        for msg := range msgChan {
            // if  closeRealTimeLogFlag{
            //  consumer.Close()
            //  break
            // }
            if err = conn.WriteMessage(websocket.TextMessage, msg.Message); err != nil {
                fmt.Println(err)
            }
            fmt.Printf("%v 
", msg)
        }
    }

}
  • 写回答

1条回答 默认 最新

  • duanfen9090 2015-07-02 06:45
    关注

    because you write more than statusCode

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起