doujiao3074 2018-08-29 19:06
浏览 929

如何发出HTTP请求以从Clickhouse数据库获取数据

I'm trying to make an HTTP request to get data from clickhouse database using Go. I don't have too much experience with it and not sure how to get the returned value by the query

This is what I have:

reader := strings.NewReader("SELECT COUNT(*) FROM system.tables WHERE database = 'local' AND name = 'persons'")
request, err := http.NewRequest("GET", "http://localhost:8123", reader)
if err != nil {
    fmt.Println(err)
}

client := &http.Client{}
resp, err := client.Do(request)
if err != nil {
    fmt.Println(err)
}

fmt.Println("The answer is: ", resp.Body)

The expected output should be a number (1 means table exist and 0 means that doesn't exist) but I'm getting in resp.Body this output:

The answer is:  &{0xc4201741c0 {0 0} false <nil> 0x6a9bb0 0x6a9b20}

Any idea to get just the value of the query?

  • 写回答

1条回答 默认 最新

  • douba3943 2018-08-30 17:06
    关注

    I had to add an extra line

    message, _ := ioutil.ReadAll(resp.Body)
    
    fmt.Println(string(message))
    

    That helped me to get what I wanted.

    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64