forked from davecgh/go-spew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s.go
28 lines (25 loc) · 647 Bytes
/
k8s.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
package spew
import (
"fmt"
"path"
"reflect"
"strings"
)
func k8sType(d *dumpState, v reflect.Value) string {
typeStr := v.Type().String()
if strings.HasPrefix(typeStr, "v1.") {
pkgPath := v.Type().PkgPath()
k8sapi := path.Base(path.Dir(pkgPath))
typeStr = k8sapi + typeStr
d.addImport(pkgPath, k8sapi+"v1")
}
if strings.HasPrefix(typeStr, "[]v1.") {
pkgPath := v.Index(0).Type().PkgPath()
k8sapi := path.Base(path.Dir(pkgPath))
d.addImport(pkgPath, k8sapi+"v1")
typeStr = strings.Replace(typeStr, "[]v1.", fmt.Sprintf("[]%sv1.", k8sapi), 1)
}
pkgPath := v.Type().PkgPath()
d.addImport(pkgPath, "")
return typeStr
}