亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

導入`github.com/influxdb/influxdb/client/v2`包時缺少符號

導入`github.com/influxdb/influxdb/client/v2`包時缺少符號

Go
蠱毒傳說 2021-12-07 16:06:08
在 Golang 中的 google cloud 上設置 web socket,并導入在我的本地機器上運行良好的代碼在云上不起作用。我有:import "github.com/influxdb/influxdb/client/v2"并已運行go get "github.com/influxdb/influxdb/client/v2"運行 go run server.go 后,我得到:# command-line-arguments./pi_server.go:47: undefined: client.NewClient./pi_server.go:47: undefined: client.Config下面的完整代碼,不包括 const 聲明和 html:package mainimport (    "flag"    "html/template"    "log"    "net/http"    "github.com/gorilla/websocket"    "fmt"    "net/url"    "github.com/influxdb/influxdb/client/v2"    "time")var addr = flag.String("addr", "localhost:8080", "http service address")var upgrader = websocket.Upgrader{} // use default optionsfunc echo(w http.ResponseWriter, r *http.Request) {    //Influx init    u,err := url.Parse("http://localhost:8086")    checkError(err)    influx_c := client.NewClient(client.Config{            URL: u,            Username: username,            Password: password,     })    bp,err := client.NewBatchPoints(client.BatchPointsConfig{        Database:  MyDB,        Precision: "s",    })    tags := map[string]string{"my_sensor_id": my_sensor_id}    //end influx init    c, err := upgrader.Upgrade(w, r, nil)    if err != nil {        log.Print("upgrade:", err)        return    }    defer c.Close()    for {        mt, message, err := c.ReadMessage()        if err != nil {            log.Println("read:", err)            break        }        log.Printf("recv: %s", message)        /*            write to influx here        */         fields := map[string]interface{}{            "random_int":   message,            "other_stuff":  69696,        }        pt,err := client.NewPoint("test_collection", tags, fields, time.Now())        checkError(err)        bp.AddPoint(pt)        influx_c.Write(bp)        err = c.WriteMessage(mt, message)        if err != nil {            log.Println("write:", err)            break        }    }}func home(w http.ResponseWriter, r *http.Request) {    homeTemplate.Execute(w, "ws://"+r.Host+"/echo", )}
查看完整描述

2 回答

?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

在此提交之前,您的本地機器有一個 github.com/influxdb/influxdb/client/v2 版本。您的云服務器正在獲取更新版本的軟件包。


要解決此問題,請運行


go get -u github.com/influxdb/influxdb/client/v2

在本地機器上獲取最新版本的軟件包。更新應用程序代碼以使用新的函數和類型名稱:


influx_c := client.NewHTTPClient(client.HTTPConfig{

        URL: u,

        Username: username,

        Password: password,

 })


查看完整回答
反對 回復 2021-12-07
?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

搞定了,謝謝!另請注意以下代碼:


influx_c,err := client.NewHTTPClient(client.HTTPConfig{

    Addr: "http://localhost:8086",

    Username: username,

    Password: password,

})

他們將 URL 字段更改為 Addr,使用的是字符串文字而不是 net/url 對象


查看完整回答
反對 回復 2021-12-07
  • 2 回答
  • 0 關注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號