dongyumiao5210 2016-01-26 04:54
浏览 304
已采纳

导入github.com/influxdb/influxdb/client/v2包时缺少符号

Setting up a web socket on google cloud in Golang, and import code that works fine on my local machine does not work on the cloud.

I have:

import "github.com/influxdb/influxdb/client/v2"

and have run

go get "github.com/influxdb/influxdb/client/v2"

Upon running go run server.go I get:

# command-line-arguments
./pi_server.go:47: undefined: client.NewClient
./pi_server.go:47: undefined: client.Config

Full code below, excluding const declarations and html:

package main

import (
    "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 options

func 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", )
}

func main() {


    flag.Parse()
    log.SetFlags(0)
    http.HandleFunc("/echo", echo)
    http.HandleFunc("/", home)
    log.Fatal(http.ListenAndServe(*addr, nil))
}
  • 写回答

2条回答 默认 最新

  • dongliuzhuan1219 2016-01-26 05:08
    关注

    You local machine has a version of github.com/influxdb/influxdb/client/v2 before this commit. Your cloud server is fetching a more recent version of the package.

    To fix the issue, run

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

    on your local machine to get the latest version of the package. Update the application code to use the new function and type names:

    influx_c := client.NewHTTPClient(client.HTTPConfig{
            URL: u,
            Username: username,
            Password: password,
     })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题