提交 2b1ac2ac 编写于 作者: D dingbo

docs: connect go

上级 fa4f2c38
package main
import (
"database/sql"
"fmt"
"os"
"database/sql"
"fmt"
"os"
_ "github.com/taosdata/driver-go/v2/taosRestful"
_ "github.com/taosdata/driver-go/v2/taosRestful"
)
func main() {
dsn := os.Getenv("TDENGINE_GO_DSN")
taos, err := sql.Open("taosRestful", dsn)
if err != nil {
fmt.Println("failed to connect TDengine, err:", err)
return
}
_, err = taos.Exec("select server_version()")
if err != nil {
fmt.Println(err)
}
fmt.Println("connect success")
defer taos.Close()
dsn := os.Getenv("TDENGINE_GO_DSN")
taos, err := sql.Open("taosRestful", dsn)
if err != nil {
fmt.Println(err)
return
}
_, err = taos.Query("select server_version()")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("connect success")
defer taos.Close()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册