36 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-01-26 08:50 . Move sub repos to pkg/
package scoped
import (
"strings"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/client/management/v3"
)
type Store struct {
types.Store
key string
}
func NewScopedStore(key string, store types.Store) *Store {
return &Store{
Store: &transform.Store{
Store: store,
Transformer: func(apiContext *types.APIContext, data map[string]interface{}) (map[string]interface{}, error) {
if data == nil {
return data, nil
}
v := convert.ToString(data[key])
if !strings.HasSuffix(v, ":"+convert.ToString(data[client.ProjectFieldNamespaceId])) {
data[key] = data[client.ProjectFieldNamespaceId]
}
data[client.ProjectFieldNamespaceId] = nil
return data, nil
},
},
key: key,
}
}
func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
if data != nil {
parts := strings.Split(convert.ToString(data[s.key]), ":")
data["namespaceId"] = parts[len(parts)-1]
}
return s.Store.Create(apiContext, schema, data)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha14

搜索帮助

344bd9b3 5694891 D2dac590 5694891