golang常用模組介紹
golang模組
一、命令列庫Cobra
Cobra提供簡單的介面來建立強大的現代化CLI介面,比如git與go工具。
Cobra同時也是一個程式, 用於建立CLI程式
https://www.jianshu.com/p/7abe7cff5384
二、client-go
Client-go是kubernetes官方釋出的呼叫K8S API的golang語言包,可以用來開發K8S的管理服務、監控服務,配合前端展示,就可以開發出一款定製化的、視覺化的管理或監控工具。目前最新版本為7.0,對應K8S的版本為1.10,訪問連結:https://github.com/kubernetes/client-go
https://www.cnblogs.com/leejack/p/9525878.html
三、hugo
Hugo是由Go語言實現的靜態網站生成器。簡單、易用、高效、易擴充套件、快速部署。
http://www.gohugo.org/
https://gohugo.io/
四、kubernetes 從入門到實踐
https://www.kancloud.cn/huyipow/kubernetes
五、jsonpatch可以找到兩個json字串的區別,然後把區別發給前端,避免全量傳輸
example:
package main import ( "fmt" "github.com/mattbaird/jsonpatch" ) var simpleA = `{"a":100, "b":200, "c":"hello"}` var simpleB = `{"a":100, "b":200, "c":"goodbye"}` func main() { patch, e := jsonpatch.CreatePatch([]byte(simpleA), []byte(simpleA)) if e != nil { fmt.Printf("Error creating JSON patch:%v", e) return } for _, operation := range patch { fmt.Printf("%s\n", operation.Json()) } }
https://github.com/mattbaird/jsonpatch
六、使用golang操作kafka:sarama及其擴充套件sarama-cluster
又因為sarama不支援consumer group,於是又使用了sarama cluster
文件:
https://godoc.org/github.com/bsm/sarama-cluster
https://godoc.org/github.com/Shopify/sarama
示例:https://github.com/bsm/sarama-cluster
https://studygolang.com/articles/8942
載入證書的示例:https://dev.to/davidsbond/golang-implementing-kafka-consumers-using-sarama-cluster-4fko
只消費一次的示例:https://blog.csdn.net/jeffrey11223/article/details/81436747
七、ssh
文件:https://godoc.org/golang.org/x/crypto/ssh#example-Client-Listen
程式碼:https://github.com/golang/crypto
https://www.jianshu.com/p/7d315f8551ad
8、errors錯誤處理介面
https://godoc.org/github.com/pkg/errors#example-New
9、Protocol類似於json,可以在多個語音之間傳輸
ProtoBuf: 是一套完整的 IDL(介面描述語言),出自Google,基於 C++ 進行的實現,開發人員可以根據 ProtoBuf 的語言規範生成多種程式語言(Golang、Python、Java 等)的介面程式碼
protobuf是Google開發出來的一個語言無關、平臺無關的資料序列化工具,在rpc或tcp通訊等很多場景都可以使用。通俗來講,如果客戶端和服務端使用的是不同的語言,那麼在服務端定義一個數據結構,通過protobuf轉化為位元組流,再傳送到客戶端解碼,就可以得到對應的資料結構
https://segmentfault.com/a/1190000009277748
https://www.jianshu.com/p/1a3f1c3031b5
https://segmentfault.com/a/1190000010477733
https://github.com/golang/protobuf
10、goole的rpc:grpc
https://github.com/grpc/grpc-go
https://grpc.io/docs/quickstart/go.html
https://grpc.io/docs/tutorials/basic/go.html
https://doc.oschina.net/grpc?t=60133
https://segmentfault.com/a/1190000016328212
https://www.jianshu.com/p/506c7c5f72be
https://www.jianshu.com/p/774b38306c30
11、golang的上下文管理context:
應用場景:在 Go http 包的 Server 中,每一個請求在都有一個對應的goroutine去處理。請求處理函式通常會啟動額外的goroutine用來訪問後端服務,比如資料庫和 RPC 服務。用來處理一個請求的goroutine通常需要訪問一些與請求特定的資料,比如終端使用者的身份認證資訊、驗證相關的 token、請求的截止時間。當一個請求被取消或超時時,所有用來處理該請求的goroutine都應該迅速退出,然後系統才能釋放這些goroutine佔用的資源
https://www.jianshu.com/p/d24bf8b6c869
https://zhuanlan.zhihu.com/p/34417106
https://deepzz.com/post/golang-context-package-notes.html
https://segmentfault.com/a/1190000006744213
https://juejin.im/post/5a6873fef265da3e317e55b6
12、檔案上傳下載:sftp
https://github.com/pkg/sftp
https://godoc.org/github.com/pkg/sftp#pkg-examples
http://www.01happy.com/golang-transfer-remote-file/