Documentation
¶
Overview ¶
Package influx 提供 InfluxDB 时序数据库集成(对标 Spring Data InfluxDB 的 InfluxDBTemplate):写入/查询封装 + 原生客户端暴露。支持 InfluxDB 2.x (及 1.8+ 的兼容模式:ServerURL 指向 /api/v2 或 8086 根地址 + 1.x token)。
Index ¶
- func SetGlobal(client *Client)
- type Client
- func (c *Client) Buckets(ctx context.Context) ([]string, error)
- func (c *Client) Client() influxdb2.Client
- func (c *Client) Close()
- func (c *Client) EnsureBucket(ctx context.Context, bucket string) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Query(ctx context.Context, bucket, flux string) ([]map[string]interface{}, error)
- func (c *Client) QueryRaw(ctx context.Context, flux string) (string, error)
- func (c *Client) Write(ctx context.Context, bucket, measurement string, ...) error
- func (c *Client) WritePoint(ctx context.Context, bucket string, point *write.Point) error
- func (c *Client) WriteRaw(ctx context.Context, bucket, lineProtocol string) error
- type Config
- type InfluxTemplate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 是 InfluxDB 模板实现。
func (*Client) EnsureBucket ¶
EnsureBucket 确保桶存在(不存在则创建;管理/初始化用)。 需要 orgID:从组织名解析。
func (*Client) Write ¶
func (c *Client) Write(ctx context.Context, bucket, measurement string, tags, fields map[string]interface{}, timestamp time.Time) error
Write 写入数据点。
func (*Client) WritePoint ¶
WritePoint 写入预构造点。
type Config ¶
type Config struct {
// ServerURL 服务地址(如 http://127.0.0.1:8086)。
ServerURL string
// Token 访问令牌(InfluxDB 2.x Token;1.x 兼容模式用 user:password 的 base64)。
Token string
// Org 组织(InfluxDB 2.x 概念)。
Org string
// Bucket 默认桶(可空,操作时显式指定)。
Bucket string
// Timeout 请求超时(默认 10s)。
Timeout time.Duration
}
Config InfluxDB 客户端配置。
type InfluxTemplate ¶
type InfluxTemplate interface {
// Ping 健康检查。
Ping(ctx context.Context) error
// Write 写入一个数据点(measurement + tags + fields + 时间戳)。
// timestamp 为零值时使用当前时间。
Write(ctx context.Context, bucket, measurement string,
tags, fields map[string]interface{}, timestamp time.Time) error
// WritePoint 写入预构造的数据点。
WritePoint(ctx context.Context, bucket string, point *write.Point) error
// WriteRaw 写入行协议(Line Protocol)原始字符串。
WriteRaw(ctx context.Context, bucket, lineProtocol string) error
// Query 执行 Flux 查询,返回记录列表(每行 map:列名 → 值)。
Query(ctx context.Context, bucket, flux string) ([]map[string]interface{}, error)
// QueryRaw 执行 Flux 查询,返回原始 CSV 文本。
QueryRaw(ctx context.Context, flux string) (string, error)
// Buckets 列出全部桶(管理用)。
Buckets(ctx context.Context) ([]string, error)
// Client 返回原生客户端(高级操作入口)。
Client() influxdb2.Client
}
InfluxTemplate 高频操作层:写入(点/行协议)/查询(Flux)/健康检查 + 原生客户端。
Click to show internal directories.
Click to hide internal directories.