這是我在 etcd 中的 kafka 連接資訊:
kafka://user:[email protected]:9092?mechanism=PLAIN&protocol=SASL_PLAINTEXT
當我從 etcd 獲取資訊字串時,我想獲取用戶名user、密碼passwd和主機10.10.172.222:9092。
現在如何使用 Golang 優雅地決議 Kafka 連接資訊?
uj5u.com熱心網友回復:
使用net/url圖書館
kafkaUrl := "kafka://[email protected]:9092?mechanism=PLAIN&protocol=SASL_PLAINTEXT"
u, err := url.Parse(kafkaUrl)
if err != nil {
// handle error
}
user := u.User.Username()
pass, isPassSet := u.User.Password()
host := u.Host // host or host:port
主機名和埠分開
hostname := u.Hostname()
port := u.Port()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/332958.html
