亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

go-staticcheck:應使用簡單的通道發送/接收,而不是選擇單個案例

go-staticcheck:應使用簡單的通道發送/接收,而不是選擇單個案例

Go
catspeake 2022-09-05 09:26:31
我使用的是Go 1.16.4。我正在嘗試處理這樣的代碼:func (pool *myConnPool) GetPooledConnection() (*myConnection, error) {    go func() {        conn, err := pool.createConn()        if err != nil {            return        }        pool.connections <- conn    }()    select { // <<<< golint warning here    case conn := <-pool.connections:        return pool.packConn(conn), nil    }}我得到了以下Go linter警告:在代碼中標記的點。任何人都可以解釋如何解決這個問題嗎?我對圍棋頻道還不太熟悉。should use a simple channel send/receive instead of select with a single case (S1000)
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

linter告訴你,你的使用是沒有意義的,只有一個。要解決此問題,請替換以下內容:selectcase


select {

case conn := <-pool.connections:

    return pool.packConn(conn), nil

}

跟:


conn := <-pool.connections

return pool.packConn(conn), nil

甚至:


return pool.packConn(<-pool.connections), nil


查看完整回答
反對 回復 2022-09-05
  • 1 回答
  • 0 關注
  • 1230 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號