forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
32 lines (27 loc) · 861 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package config
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/openshift/origin/pkg/api/latest"
)
// Set the default RESTMapper and ObjectTyper
var (
defaultMapper = latest.RESTMapper
defaultTyper = api.Scheme
)
// DecodeDataToObject decodes the JSON/YAML content into the runtime Object
// using the RESTMapper interface.
// The RESTMapper mappings are returned for the future encoding.
func DecodeDataToObject(data []byte) (obj runtime.Object, mapping *meta.RESTMapping, err error) {
version, kind, err := defaultTyper.DataVersionAndKind(data)
if err != nil {
return
}
mapping, err = defaultMapper.RESTMapping(kind, version)
if err != nil {
return
}
obj, err = mapping.Codec.Decode(data)
return
}