37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package scoped
import (
"strings"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
client "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, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (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.2.8-rc1

搜索帮助