mirror of
https://github.com/rancher/norman.git
synced 2025-08-17 23:07:00 +00:00
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
|
package schema
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"strings"
|
||
|
|
||
|
"github.com/rancher/norman/store/empty"
|
||
|
"github.com/rancher/norman/types"
|
||
|
)
|
||
|
|
||
|
type Store struct {
|
||
|
empty.Store
|
||
|
}
|
||
|
|
||
|
func NewSchemaStore() types.Store {
|
||
|
return &Store{}
|
||
|
}
|
||
|
|
||
|
func (s *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||
|
for _, schema := range apiContext.Schemas.Schemas() {
|
||
|
if strings.EqualFold(schema.ID, id) {
|
||
|
schemaData := map[string]interface{}{}
|
||
|
|
||
|
data, err := json.Marshal(schema)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return schemaData, json.Unmarshal(data, &schemaData)
|
||
|
}
|
||
|
}
|
||
|
return nil, nil
|
||
|
}
|
||
|
|
||
|
func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
|
||
|
schemaData := []map[string]interface{}{}
|
||
|
|
||
|
data, err := json.Marshal(apiContext.Schemas.Schemas())
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if err := json.Unmarshal(data, &schemaData); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return schemaData, nil
|
||
|
}
|