1. 程式人生 > >golang常用模塊介紹

golang常用模塊介紹

.cn 令行 implement turn creat 不支持 hello 語言包 完整

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/

golang常用模塊介紹