mirror of
https://github.com/rancher/steve.git
synced 2025-07-12 06:08:24 +00:00
32 lines
589 B
Go
32 lines
589 B
Go
|
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)
|
||
|
}
|
||
|
}
|