Skip to content

Commit

Permalink
docs: add README_CN
Browse files Browse the repository at this point in the history
Signed-off-by: PennyYoon <525296438@qq.com>
Co-authored-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
Chenxulin97 and hezhangjian committed Feb 11, 2024
1 parent b343cec commit f2d04e4
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,6 +65,7 @@ if err != nil {
fmt.Println(err)
}
```

Write batch points:

```go
Expand Down
114 changes: 114 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -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

## 用法

引入客户端库:

<i><font color=gray>示例使用点引用法,用户可结合具体需要选择适合的引用方式。</font></i>

```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()
}
}
}
```

0 comments on commit f2d04e4

Please sign in to comment.