Skip to content

Commit

Permalink
feat: add point and query result struct
Browse files Browse the repository at this point in the history
Signed-off-by: ZhangJian He <[email protected]>
  • Loading branch information
ZhangJian He committed Nov 23, 2023
1 parent 67526e5 commit 99cdda1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions opengemini/point.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package opengemini

import "time"

type Point struct {
Measurement string
Precision string
Time time.Time
Tags map[string]string
Fields map[string]interface{}
}

func (p *Point) AddTag(key string, value string) {
p.Tags[key] = value
}

func (p *Point) AddField(key string, value interface{}) {
p.Fields[key] = value
}

func (p *Point) SetTime(t time.Time) {
p.Time = t
}

func (p *Point) SetPrecision(precision string) {
p.Precision = precision
}

func (p *Point) SetMeasurement(name string) {
p.Measurement = name
}

type BatchPoints struct {
Points []*Point
}

func (bp *BatchPoints) AddPoint(p *Point) {
bp.Points = append(bp.Points, p)
}
13 changes: 13 additions & 0 deletions opengemini/query_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package opengemini

// SeriesResult contains the results of a series query
type SeriesResult struct {
Series []Series `json:"series,omitempty"`
Error string `json:"error,omitempty"`
}

// QueryResult is the top-level struct
type QueryResult struct {
Results []SeriesResult `json:"results,omitempty"`
Error string `json:"error,omitempty"`
}
9 changes: 9 additions & 0 deletions opengemini/series.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package opengemini

// Series defines the structure for series data
type Series struct {
Name string `json:"name,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Columns []string `json:"columns,omitempty"`
Values [][]interface{} `json:"values,omitempty"`
}

0 comments on commit 99cdda1

Please sign in to comment.