forked from influxdata/influxdb
/
flux.go
41 lines (35 loc) · 1.23 KB
/
flux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cli
import (
"context"
"github.com/influxdata/flux"
"github.com/influxdata/flux/csv"
"github.com/influxdata/flux/repl"
_ "github.com/influxdata/influxdb/flux/builtin"
"github.com/influxdata/influxdb/flux/client"
)
// QueryService represents a type capable of performing queries.
type fluxClient interface {
// Query submits a query for execution returning a results iterator.
// Cancel must be called on any returned results to free resources.
Query(ctx context.Context, req *client.ProxyRequest) (flux.ResultIterator, error)
}
// replQuerier implements the repl.Querier interface while consuming a fluxClient
type replQuerier struct {
client fluxClient
}
func (q *replQuerier) Query(ctx context.Context, deps flux.Dependencies, compiler flux.Compiler) (flux.ResultIterator, error) {
req := &client.ProxyRequest{
Compiler: compiler,
Dialect: csv.DefaultDialect(),
}
return q.client.Query(ctx, req)
}
func getFluxREPL(host string, port int, ssl bool, username, password string) (*repl.REPL, error) {
c, err := client.NewHTTP(host, port, ssl)
if err != nil {
return nil, err
}
c.Username = username
c.Password = password
return repl.New(context.Background(), flux.NewDefaultDependencies(), &replQuerier{client: c}), nil
}