我使用的是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
- 1 回答
- 0 關注
- 1230 瀏覽
添加回答
舉報
0/150
提交
取消