Go

安装 SDK

sh

  1. go get github.com/GreptimeTeam/greptimedb-client-go

创建数据库对象

go

  1. package example
  2. import (
  3. greptime "github.com/GreptimeTeam/greptimedb-client-go"
  4. "google.golang.org/grpc"
  5. "google.golang.org/grpc/credentials/insecure"
  6. )
  7. func InitClient() *greptime.Client {
  8. options := []grpc.DialOption{
  9. grpc.WithTransportCredentials(insecure.NewCredentials()),
  10. }
  11. // To connect a database that needs authentication, for example, those on Greptime Cloud,
  12. // `Username` and `Password` are needed when connecting to a database that requires authentication.
  13. // Leave the two fields empty if connecting a database without authentication.
  14. cfg := greptime.NewCfg("127.0.0.1").
  15. WithDatabase("public"). // change to your real database
  16. WithPort(4001). // default port
  17. WithAuth("", ""). // `Username` and `Password`
  18. WithDialOptions(options...). // specify your gRPC dail options
  19. WithCallOptions() // specify your gRPC call options
  20. client, err := greptime.NewClient(cfg)
  21. if err != nil {
  22. panic("failed to init client")
  23. }
  24. return client
  25. }

请参考 Go SDK in reference 以获得更多信息.

写入数据

请参考 写入数据.

读取数据

请参考 读取数据.