mirror of
https://github.com/rancher/steve.git
synced 2025-09-16 07:18:28 +00:00
Initial commit
This commit is contained in:
31
pkg/server/mapper.go
Normal file
31
pkg/server/mapper.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rancher/norman/pkg/types"
|
||||
"github.com/rancher/norman/pkg/types/values"
|
||||
)
|
||||
|
||||
func newDefaultMapper() types.Mapper {
|
||||
return &defaultMapper{}
|
||||
}
|
||||
|
||||
type defaultMapper struct {
|
||||
types.EmptyMapper
|
||||
}
|
||||
|
||||
func (d *defaultMapper) FromInternal(data map[string]interface{}) {
|
||||
if _, ok := data["id"]; ok || data == nil {
|
||||
return
|
||||
}
|
||||
|
||||
name := values.GetValueN(data, "metadata", "name")
|
||||
namespace := values.GetValueN(data, "metadata", "namespace")
|
||||
|
||||
if namespace == "" {
|
||||
data["id"] = name
|
||||
} else {
|
||||
data["id"] = fmt.Sprintf("%s/%s", namespace, name)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user