-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9af53c9
commit 5ce665a
Showing
9 changed files
with
145 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
type ImageKVs struct { | ||
Resource interface{} | ||
Keys []string | ||
} | ||
|
||
func (kvs ImageKVs) Visit(visitorFunc func(interface{}) (interface{}, bool)) { | ||
for _, key := range kvs.Keys { | ||
kvs.visitValues(kvs.Resource, key, visitorFunc) | ||
} | ||
} | ||
|
||
func (kvs ImageKVs) visitValues(obj interface{}, key string, visitorFunc func(interface{}) (interface{}, bool)) { | ||
switch typedObj := obj.(type) { | ||
case map[string]interface{}: | ||
for k, v := range typedObj { | ||
if k == key { | ||
if newVal, update := visitorFunc(v); update { | ||
typedObj[k] = newVal | ||
} | ||
} else { | ||
kvs.visitValues(typedObj[k], key, visitorFunc) | ||
} | ||
} | ||
|
||
case map[string]string: | ||
for k, v := range typedObj { | ||
if k == key { | ||
if newVal, update := visitorFunc(v); update { | ||
typedObj[k] = newVal.(string) | ||
} | ||
} else { | ||
kvs.visitValues(typedObj[k], key, visitorFunc) | ||
} | ||
} | ||
|
||
case []interface{}: | ||
for _, o := range typedObj { | ||
kvs.visitValues(o, key, visitorFunc) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters