mirror of
https://github.com/rancher/norman.git
synced 2025-09-16 15:21:33 +00:00
Options to transformer
This commit is contained in:
committed by
Darren Shepherd
parent
e39bcf5ee4
commit
6753a90143
@@ -5,11 +5,11 @@ import (
|
|||||||
"github.com/rancher/norman/types/convert"
|
"github.com/rancher/norman/types/convert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransformerFunc func(apiContext *types.APIContext, data map[string]interface{}) (map[string]interface{}, error)
|
type TransformerFunc func(apiContext *types.APIContext, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error)
|
||||||
|
|
||||||
type ListTransformerFunc func(apiContext *types.APIContext, data []map[string]interface{}) ([]map[string]interface{}, error)
|
type ListTransformerFunc func(apiContext *types.APIContext, data []map[string]interface{}, opt *types.QueryOptions) ([]map[string]interface{}, error)
|
||||||
|
|
||||||
type StreamTransformerFunc func(apiContext *types.APIContext, data chan map[string]interface{}) (chan map[string]interface{}, error)
|
type StreamTransformerFunc func(apiContext *types.APIContext, data chan map[string]interface{}, opt *types.QueryOptions) (chan map[string]interface{}, error)
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
Store types.Store
|
Store types.Store
|
||||||
@@ -30,7 +30,7 @@ func (s *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id stri
|
|||||||
if s.Transformer == nil {
|
if s.Transformer == nil {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
return s.Transformer(apiContext, data)
|
return s.Transformer(apiContext, data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Watch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
|
func (s *Store) Watch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
|
||||||
@@ -40,11 +40,11 @@ func (s *Store) Watch(apiContext *types.APIContext, schema *types.Schema, opt *t
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.StreamTransformer != nil {
|
if s.StreamTransformer != nil {
|
||||||
return s.StreamTransformer(apiContext, c)
|
return s.StreamTransformer(apiContext, c, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
return convert.Chan(c, func(data map[string]interface{}) map[string]interface{} {
|
return convert.Chan(c, func(data map[string]interface{}) map[string]interface{} {
|
||||||
item, err := s.Transformer(apiContext, data)
|
item, err := s.Transformer(apiContext, data, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.ListTransformer != nil {
|
if s.ListTransformer != nil {
|
||||||
return s.ListTransformer(apiContext, data)
|
return s.ListTransformer(apiContext, data, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Transformer == nil {
|
if s.Transformer == nil {
|
||||||
@@ -68,7 +68,7 @@ func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *ty
|
|||||||
|
|
||||||
var result []map[string]interface{}
|
var result []map[string]interface{}
|
||||||
for _, item := range data {
|
for _, item := range data {
|
||||||
item, err := s.Transformer(apiContext, item)
|
item, err := s.Transformer(apiContext, item, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data
|
|||||||
if s.Transformer == nil {
|
if s.Transformer == nil {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
return s.Transformer(apiContext, data)
|
return s.Transformer(apiContext, data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
|
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
|
||||||
@@ -99,7 +99,7 @@ func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data
|
|||||||
if s.Transformer == nil {
|
if s.Transformer == nil {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
return s.Transformer(apiContext, data)
|
return s.Transformer(apiContext, data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
func (s *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
|
Reference in New Issue
Block a user