Go語言愛好者周刊:第 97 期
這里記錄每周值得分享的 Go 語言相關(guān)內(nèi)容,周日發(fā)布。
本周刊開源(GitHub:polaris1119/golangweekly[1]),歡迎投稿,推薦或自薦文章/軟件/資源等,請提交 issue[2] 。
鑒于一些人可能沒法堅持把英文文章看完,因此,周刊中會盡可能推薦優(yōu)質(zhì)的中文文章。優(yōu)秀的英文文章,我們的 GCTT 組織會進行翻譯。
由于微信公眾號不支持外鏈,文章大量鏈接可通過文末「閱讀原文」查看。

題圖:Go 帶顏色輸出的庫 fatih/color
刊首語
應大家要求,先簡單解析下上期周刊的題目,出題者:iMarlboro[3]
package main
import (
"fmt"
"sync"
)
func main() {
var m sync.Map
m.Store("address", map[string]string{"province": "江蘇", "city": "南京"})
v, _ := m.Load("address")
fmt.Println(v["province"])
}
以下是答題投票情況:

正確答案是 B。為什么?
這道題目的關(guān)鍵是 sync.Map 相關(guān)的定義(主要看本題使用了的 Store 和 Load):
func (m *Map) Load(key interface{}) (value interface{}, ok bool)
func (m *Map) Store(key, value interface{})
看到了沒?接收的 key 和 value 都是 interface{}(返回的 value 也是 interface{}),所以,通過 Load 獲取 key 對應的 value 是一個 interface{}。fmt.Println(v["province"]) 這句相當于把 interface{} 當成 map 了,肯定報錯,必須進行類型斷言。你答對了嗎?
有些人可能不明白為什么要泛型。有了泛型,這道題目就不需要做類型斷言了。
看看本期周刊的題目。以下代碼輸出什么?
package main
import (
"fmt"
)
func hello(i *int) int {
defer func() {
*i = 19
}()
return *i
}
func main() {
i := 10
j := hello(&i)
fmt.Println(i, j)
}
資訊
1、gdu 5.0 發(fā)布[4]
帶控制臺接口的磁盤使用分析器。

2、Caire 1.3 發(fā)布[5]
使用接縫雕刻來拉伸圖像的不重要部分,從而允許在調(diào)整大小的過程中考慮圖像的內(nèi)容。
3、color 1.12.0 發(fā)布[6]
顏色文本輸出包。
4、go-elasticsearch 7.13.0 發(fā)布[7]
官方的 Go 客戶端。
5、Go 新提案[8]
bytes、strings 包增加 Cut 函數(shù)。
6、提案:將 Go 移植到中科龍芯指令架構(gòu)[9]
支持的架構(gòu)越來越多了。
誰在招 Gopher
整理近期的 Go 職位。有招聘需求可以到「Go招聘」發(fā)布!
文章
強調(diào)一下是我個人的見解以及接口在 Go 語言中的意義。
官方用的多版本管理方法。
JSON payload 實現(xiàn)簡易的請求和響應的內(nèi)省。
虛擬內(nèi)存,不用驚慌!
增加對 interface{} 的支持。
6、validator庫你知多少?govalidator了解一下
Web 開發(fā)基本必備的。
本文帶你一起探討下消息隊列消費端高吞吐的 Go 框架實現(xiàn)。
開源項目
1、revive[10]
一個旨在提供更多結(jié)構(gòu)和可配置性的 Golint 的替代品。它的速度據(jù)說有數(shù)倍提升。
2、render[11]
輕松 Render JSON,XML,二進制數(shù)據(jù)和HTML 模板響應。
3、limitio[12]
帶有 limiit 功能的 io.Reader 和 io.Writer。
4、lima[13]
Linux 中的 macOS 子系統(tǒng) lima。
5、sealer[14]
一款分布式應用打包交付運行的解決方案,阿里巴巴出品。
6、netmaker[15]
通過安全,快速,專用網(wǎng)絡連接任何計算機,并從中央服務器管理多個網(wǎng)絡。
7、forms[16]
讓表單創(chuàng)建和處理更簡單。
8、couper[17]
一種輕量級 API 網(wǎng)關(guān),旨在支持構(gòu)建和操作 API 驅(qū)動的 Web 項目的開發(fā)人員。
資源&&工具
1、go-map-schema[18]
簡單的 JSON 類型檢查。
2、cocert[19]
私鑰安全分發(fā)工具。
3、Go 編碼安全指南[20]
騰訊出品。
4、油管視頻[21]
Go 還是 Rust,看 Go 專家與 Rust 專家的圓桌辯論。
5、mtail[22]
從應用程序日志中提取 WhiteBox 監(jiān)視數(shù)據(jù)以在時間序列數(shù)據(jù)庫中收集。Google 出品。
訂閱
這個周刊每周日發(fā)布,同步更新在Go語言中文網(wǎng)[23]和微信公眾號[24]。
微信搜索"Go語言中文網(wǎng)"或者掃描二維碼,即可訂閱。
上期推薦參考資料
polaris1119/golangweekly: https://github.com/polaris1119/golangweekly
[2]提交 issue: https://github.com/polaris1119/golangweekly/issues
[3]iMarlboro: https://github.com/iMarlboro
[4]gdu 5.0 發(fā)布: https://github.com/dundee/gdu
[5]Caire 1.3 發(fā)布: https://github.com/esimov/caire
[6]color 1.12.0 發(fā)布: https://github.com/fatih/color
[7]go-elasticsearch 7.13.0 發(fā)布: https://github.com/elastic/go-elasticsearch
[8]Go 新提案: https://github.com/golang/go/issues/46336
[9]提案:將 Go 移植到中科龍芯指令架構(gòu): https://github.com/golang/go/issues/46229
[10]revive: https://github.com/mgechev/revive
[11]render: https://github.com/unrolled/render
[12]limitio: https://github.com/nanmu42/limitio
[13]lima: https://github.com/AkihiroSuda/lima
[14]sealer: https://github.com/alibaba/sealer
[15]netmaker: https://github.com/gravitl/netmaker
[16]forms: https://github.com/coscms/forms
[17]couper: https://github.com/avenga/couper
[18]go-map-schema: https://github.com/Kangaroux/go-map-schema
[19]cocert: https://github.com/Dentrax/cocert
[20]Go 編碼安全指南: https://github.com/Tencent/secguide/blob/main/Go%E5%AE%89%E5%85%A8%E6%8C%87%E5%8D%97.md
[21]油管視頻: https://www.youtube.com/watch?v=N-E-qtQhsHw
[22]mtail: https://github.com/google/mtail
[23]Go語言中文網(wǎng): https://studygolang.com/go/weekly
[24]微信公眾號: https://weixin.sogou.com/weixin?query=Go%E8%AF%AD%E8%A8%80%E4%B8%AD%E6%96%87%E7%BD%91
