From 57d345c561c33a08adde7f5f4e5a6c95ec0a0e0a Mon Sep 17 00:00:00 2001 From: PennyYoon <55304072+Chenxulin97@users.noreply.github.com> Date: Sun, 11 Feb 2024 17:38:59 +0800 Subject: [PATCH] docs: add README_CN (#52) Signed-off-by: PennyYoon <525296438@qq.com> Co-authored-by: ZhangJian He --- README.md | 3 ++ README_CN.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 README_CN.md diff --git a/README.md b/README.md index 01d10c3..58956dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # opengemini-client-go opengemini-client-go is a Go client API for OpenGemini. +English | [中文简体](README_CN.md) + OpenGemini is an open-source time series database, find more about OpenGemini at https://github.com/openGemini/openGemini ## Requirements @@ -63,6 +65,7 @@ if err != nil { fmt.Println(err) } ``` + Write batch points: ```go diff --git a/README_CN.md b/README_CN.md new file mode 100644 index 0000000..fc5d0bd --- /dev/null +++ b/README_CN.md @@ -0,0 +1,114 @@ +# opengemini-client-go +opengemini-client-go 是一个基于go语言的 OpenGemini 客户端开源库 + +中文简体 | [English](README.md) + +OpenGemini 是华为云开源的一款云原生分布式时序数据库,获取更多关于 OpenGemini 的信息可点击 https://github.com/openGemini/openGemini + +## 要求 + +- Go 1.19 + +## 用法 + +引入客户端库: + +示例使用点引用法,用户可结合具体需要选择适合的引用方式。 + +```go +import . "github.com/openGemini/opengemini-client-go/opengemini" +``` + +创建客户端: + +```go +config := &Config{ + Addresses: []*Address{ + { + Host: "127.0.0.1", + Port: 8086, + }, + }, +} +client, err := NewClient(config) +if err != nil { + fmt.Println(err) +} +``` + +创建数据库: + +```go +exampleDatabase := "ExampleDatabase" +err = client.CreateDatabase(exampleDatabase) +if err != nil { + fmt.Println(err) + return +} +``` + +写入单个点: + +```go +exampleMeasurement := "ExampleMeasurement" +point := &Point{} +point.SetMeasurement(exampleMeasurement) +point.AddTag("Weather", "foggy") +point.AddField("Humidity", 87) +point.AddField("Temperature", 25) +err = client.WritePoint(exampleDatabase, point, func(err error) { + if err != nil { + fmt.Printf("write point failed for %s", err) + } +}) +if err != nil { + fmt.Println(err) +} +``` + +批量写入点: + +```go +exampleMeasurement := "ExampleMeasurement" +bp := &BatchPoints{} +var tagList []string +tagList = append(tagList, "sunny", "rainy", "windy") +for i := 0; i < 10; i++ { + p := &Point{} + p.SetMeasurement(exampleMeasurement) + p.AddTag("Weather", tagList[rand.Int31n(3)]) + p.AddField("Humidity", rand.Int31n(100)) + p.AddField("Temperature", rand.Int31n(40)) + p.SetTime(time.Now()) + bp.AddPoint(p) + time.Sleep(time.Nanosecond) +} +err = client.WriteBatchPoints(exampleDatabase, bp) +if err != nil { + fmt.Println(err) +} +``` + +执行查询: + +```go +q := Query{ + Database: exampleDatabase, + Command: "select * from " + exampleMeasurement, +} +res, err := client.Query(q) +if err != nil { + fmt.Println(err) +} +for _, r := range res.Results { + for _, s := range r.Series { + for _, v := range s.Values { + for _, i := range v { + fmt.Print(i) + fmt.Print(" | ") + } + fmt.Println() + } + } +} +```