草庐IT

go - "non-declaration statement outside function body"错误

coder 2024-07-14 原文

<分区>

对于我的 http func 方法,我不断收到函数主体外的非声明语句错误。我不确定为什么在我修复了一些全局变量后它一直出现。

    package main

import (
  "net/http"
  "github.com/gorilla/websocket"
)

var audioMessage   []byte
var whatType       int
var recieverReady  bool

http.HandleFunc("/send", func(w http.ResponseWriter, r *http.Request) {
  conn, _ := websocket.Upgrade(r, w)

  go func(){
        for {

      messageType, revdata, err := conn.ReadMessage()

      if recieverReady {
        audioMessage <- revdata
        whatType     <- messageType
      }
    }
    }()
})

有关go - "non-declaration statement outside function body"错误的更多相关文章

随机推荐