Files
influx-cli/clients/bucket_schema/nsjson.go
Sam Arnold 9747d05ae1 refactor: expose generated code and client business logic to share with Kapacitor (#103)
* refactor: take clients out of internal

* refactor: move stdio to pkg

* Move internal/api to api

* refactor: final changes for Kapacitor to access shared functionality

* chore: regenerate mocks

* fix: bad automated refactor

* chore: extra formatting not caught by make fmt
2021-05-25 10:05:01 -04:00

29 lines
587 B
Go

package bucket_schema
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"github.com/influxdata/influx-cli/v2/api"
)
func decodeNDJson(r io.Reader) ([]api.MeasurementSchemaColumn, error) {
scan := bufio.NewScanner(r)
var rows []api.MeasurementSchemaColumn
n := 1
for scan.Scan() {
if line := bytes.TrimSpace(scan.Bytes()); len(line) > 0 {
var row api.MeasurementSchemaColumn
if err := json.Unmarshal(line, &row); err != nil {
return nil, fmt.Errorf("error decoding JSON at line %d: %w", n, err)
}
rows = append(rows, row)
}
n++
}
return rows, nil
}