forked from openGemini/opengemini-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add point and query result struct (openGemini#14)
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
- Loading branch information
ZhangJian He
authored
Nov 23, 2023
1 parent
67526e5
commit ad23261
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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) { | ||
if p.Tags == nil { | ||
p.Tags = make(map[string]string) | ||
} | ||
p.Tags[key] = value | ||
} | ||
|
||
func (p *Point) AddField(key string, value interface{}) { | ||
if p.Fields == nil { | ||
p.Fields = make(map[string]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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |