mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 05:59:22 +00:00
30 lines
No EOL
630 B
Go
30 lines
No EOL
630 B
Go
package resource
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
yaml "gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type Resource struct {
|
|
Kind, Version, Namespace string
|
|
}
|
|
|
|
// TODO: Support multi-resources yaml files
|
|
func Read(r io.Reader) (Resource, error) {
|
|
s, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return Resource{}, err
|
|
}
|
|
|
|
resource := struct {
|
|
APIVersion string `yaml:"apiVersion"`
|
|
Kind string `yaml:"kind"`
|
|
Metadata struct {
|
|
Namespace string `yaml:"Namespace"`
|
|
} `yaml:"Metadata"`
|
|
}{}
|
|
err = yaml.Unmarshal(s, &resource)
|
|
|
|
return Resource{Kind: resource.Kind, Version: resource.APIVersion, Namespace: resource.Metadata.Namespace}, err
|
|
} |