I am able to fetch the Big Query table output as json through Golang server. But is there a way to fetch the schema directly instead of defining it as ColStatsRow? Also, any way to make this better.
type ColStatsRow struct {
COLUMN_NAME string `bigquery:"column_name"`
COLUMN_VALUE string `bigquery:"column_value"`
FREQUENCY int64 `bigquery:"frequency"`
}
// getOutput prints results from a query
func getOutput(w http.ResponseWriter, iter *bigquery.RowIterator) error {
var rows []ColStatsRow
for {
var row ColStatsRow
err := iter.Next(&row)
if err == iterator.Done {
out, err := json.Marshal(rows)
if err != nil {
return fmt.Errorf("error marshalling results: %v", err)
}
w.Write([]byte(out))
return nil
}
if err != nil {
return fmt.Errorf("error iterating through results: %v", err)
}
rows = append(rows, row)
}
}
Thank you.