1
0
mirror of https://github.com/rancher/steve.git synced 2025-06-26 06:52:57 +00:00
steve/pkg/table/mapper.go

45 lines
923 B
Go
Raw Normal View History

2019-08-14 18:08:34 +00:00
package table
import (
"github.com/rancher/naok/pkg/attributes"
"github.com/rancher/norman/pkg/data"
"github.com/rancher/norman/pkg/types"
)
type Column struct {
2019-08-14 18:16:37 +00:00
Name string `json:"name,omitempty"`
Field string `json:"field,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
2019-08-14 18:08:34 +00:00
}
type Table struct {
Columns []Column
Computed func(data.Object)
}
type ColumnMapper struct {
definition Table
types.EmptyMapper
}
2019-09-09 21:28:55 +00:00
func NewColumns(computed func(data.Object), columns ...Column) *ColumnMapper {
return &ColumnMapper{
definition: Table{
Columns: columns,
Computed: computed,
},
}
}
2019-08-14 18:08:34 +00:00
func (t *ColumnMapper) FromInternal(d data.Object) {
if t.definition.Computed != nil {
t.definition.Computed(d)
}
}
func (t *ColumnMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
attributes.SetColumns(schema, t.definition.Columns)
return nil
}