Go

安装 SDK

sh

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

创建数据库对象

go

1. package example

3. import (
4. greptime "github.com/GreptimeTeam/greptimedb-client-go"
5. "google.golang.org/grpc"
6. "google.golang.org/grpc/credentials/insecure"
7. )

9. func InitClient() *greptime.Client {
10. options := []grpc.DialOption{
11. grpc.WithTransportCredentials(insecure.NewCredentials()),
12. }
13. // To connect a database that needs authentication, for example, those on Greptime Cloud,
14. // `Username` and `Password` are needed when connecting to a database that requires authentication.
15. // Leave the two fields empty if connecting a database without authentication.
16. cfg := greptime.NewCfg("127.0.0.1").
17. WithDatabase("public").      // change to your real database
18. WithPort(4001).              // default port
19. WithAuth("", "").            // `Username` and `Password`
20. WithDialOptions(options...). // specify your gRPC dail options
21. WithCallOptions()            // specify your gRPC call options

23. client, err := greptime.NewClient(cfg)
24. if err != nil {
25. panic("failed to init client")
26. }
27. return client
28. }

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

写入数据

请参考 写入数据.

读取数据

请参考 读取数据.