Golang http:多重响应.WriteHeader调用



这些天我一直在使用Beego框架通过webshoet发送消息。但是遇到错误的消息http:multi-response。WriteHeader调用问题出在哪里?任何提示都会很棒!

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: %vn", 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 n", msg)
        }
    }
}

因为您编写的内容多于statusCode

相关内容

  • 没有找到相关文章

最新更新