commons-go/sensorconfig/model/ResultSet.go

47 lines
900 B
Go
Raw Normal View History

2018-04-12 09:38:04 +00:00
package model
import "encoding/json"
type ResultSetter interface {
AddRow(row []string)
GetMeta() map[string]json.Number
GetData() map[string]string
}
type ResultSet struct {
Item *Item `json:"item,omitempty"`
Rows [][]string `json:"rows,omitempty"`
Meta map[string]json.Number `json:"meta,omitempty"`
}
func (rs *ResultSet) AddRow(row []string) {
rs.Rows = append(rs.Rows, row)
}
func (rs *ResultSet) GetMeta() map[string]json.Number {
return rs.Meta
}
func NewResultSet(item *Item) ResultSetter {
if nil == item.MappingInfo {
item.MappingInfo = &MappingInfo{}
}
rs := &ResultSet{}
rs.Item = item
rs.Rows = make([][]string, 0)
switch item.MappingInfo.ParseDirection {
case "row":
rsr := &ResultSetRow{}
rsr.ResultSet = rs
rsr.setMeta()
return rsr
default:
rsc := &ResultSetCol{}
rsc.ResultSet = rs
rsc.setMeta()
return rsc
}
}