mirror of
https://github.com/rancher/norman.git
synced 2025-09-25 14:46:57 +00:00
Fix self link
This commit is contained in:
@@ -12,9 +12,11 @@ type SelfLink struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SelfLink) FromInternal(data map[string]interface{}) {
|
func (s *SelfLink) FromInternal(data map[string]interface{}) {
|
||||||
sl, ok := data["selfLink"].(string)
|
if data != nil {
|
||||||
if !ok || sl == "" {
|
sl, ok := data["selfLink"].(string)
|
||||||
data["selfLink"] = s.selflink(data)
|
if !ok || sl == "" {
|
||||||
|
data["selfLink"] = s.selflink(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +31,10 @@ func (s *SelfLink) ModifySchema(schema *types.Schema, schemas *types.Schemas) er
|
|||||||
|
|
||||||
func (s *SelfLink) selflink(data map[string]interface{}) string {
|
func (s *SelfLink) selflink(data map[string]interface{}) string {
|
||||||
buf := &strings.Builder{}
|
buf := &strings.Builder{}
|
||||||
name := data["name"].(string)
|
name, ok := data["name"].(string)
|
||||||
|
if !ok || name == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
apiVersion, ok := data["apiVersion"].(string)
|
apiVersion, ok := data["apiVersion"].(string)
|
||||||
if !ok || apiVersion == "v1" {
|
if !ok || apiVersion == "v1" {
|
||||||
buf.WriteString("/api/v1/")
|
buf.WriteString("/api/v1/")
|
||||||
@@ -39,7 +44,7 @@ func (s *SelfLink) selflink(data map[string]interface{}) string {
|
|||||||
buf.WriteString("/")
|
buf.WriteString("/")
|
||||||
}
|
}
|
||||||
namespace, ok := data["namespace"].(string)
|
namespace, ok := data["namespace"].(string)
|
||||||
if !ok || namespace != "" {
|
if ok && namespace != "" {
|
||||||
buf.WriteString("namespaces/")
|
buf.WriteString("namespaces/")
|
||||||
buf.WriteString(namespace)
|
buf.WriteString(namespace)
|
||||||
buf.WriteString("/")
|
buf.WriteString("/")
|
||||||
|
Reference in New Issue
Block a user