37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 994 Bytes
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-03-23 08:47 . Use new Transformer API
package preference
import (
"strings"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/api/store/userscope"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/client/management/v3"
)
const (
NamespaceID = client.PreferenceFieldNamespaceId
)
func NewStore(nsClient v1.NamespaceInterface, store types.Store) types.Store {
return userscope.NewStore(nsClient,
&transform.Store{
Store: store,
Transformer: transformer,
})
}
func transformer(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opts *types.QueryOptions) (map[string]interface{}, error) {
if data == nil {
return nil, nil
}
ns := convert.ToString(data[NamespaceID])
id := convert.ToString(data[types.ResourceFieldID])
id = strings.TrimPrefix(id, ns+":")
data[client.PreferenceFieldName] = id
data[types.ResourceFieldID] = id
return data, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.1

搜索帮助