1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00

chore(code): replace interface{} with any EE-6513 (#11986)

This commit is contained in:
andres-portainer 2024-06-28 14:59:28 -03:00 committed by GitHub
parent 9c4935286f
commit f0d43f941f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 231 additions and 231 deletions

View file

@ -55,7 +55,7 @@ func AddAppLabels(manifestYaml []byte, appLabels map[string]string) ([]byte, err
return manifestYaml, nil
}
postProcessYaml := func(yamlDoc interface{}) error {
postProcessYaml := func(yamlDoc any) error {
addResourceLabels(yamlDoc, appLabels)
return nil
}
@ -71,12 +71,12 @@ func AddAppLabels(manifestYaml []byte, appLabels map[string]string) ([]byte, err
// ExtractDocuments extracts all the documents from a yaml file
// Optionally post-process each document with a function, which can modify the document in place.
// Pass in nil for postProcessYaml to skip post-processing.
func ExtractDocuments(manifestYaml []byte, postProcessYaml func(interface{}) error) ([][]byte, error) {
func ExtractDocuments(manifestYaml []byte, postProcessYaml func(any) error) ([][]byte, error) {
docs := make([][]byte, 0)
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
for {
m := make(map[string]interface{})
m := make(map[string]any)
err := yamlDecoder.Decode(&m)
// if decoded document is empty
@ -113,7 +113,7 @@ func ExtractDocuments(manifestYaml []byte, postProcessYaml func(interface{}) err
// It returns an empty string if namespace is not found in the resource
func GetNamespace(manifestYaml []byte) (string, error) {
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
m := make(map[string]interface{})
m := make(map[string]any)
err := yamlDecoder.Decode(&m)
if err != nil {
return "", errors.Wrap(err, "failed to unmarshal yaml manifest when obtaining namespace")
@ -125,12 +125,12 @@ func GetNamespace(manifestYaml []byte) (string, error) {
}
if _, ok := m["metadata"]; ok {
var namespace interface{}
var namespace any
var ok bool
if strings.EqualFold(kind, "namespace") {
namespace, ok = m["metadata"].(map[string]interface{})["name"]
namespace, ok = m["metadata"].(map[string]any)["name"]
} else {
namespace, ok = m["metadata"].(map[string]interface{})["namespace"]
namespace, ok = m["metadata"].(map[string]any)["namespace"]
}
if ok {
@ -143,8 +143,8 @@ func GetNamespace(manifestYaml []byte) (string, error) {
return "", nil
}
func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
m, ok := yamlDoc.(map[string]interface{})
func addResourceLabels(yamlDoc any, appLabels map[string]string) {
m, ok := yamlDoc.(map[string]any)
if !ok {
return
}
@ -157,9 +157,9 @@ func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
for _, v := range m {
switch v := v.(type) {
case map[string]interface{}:
case map[string]any:
addResourceLabels(v, appLabels)
case []interface{}:
case []any:
for _, item := range v {
addResourceLabels(item, appLabels)
}
@ -167,15 +167,15 @@ func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
}
}
func addLabels(obj map[string]interface{}, appLabels map[string]string) {
metadata := make(map[string]interface{})
func addLabels(obj map[string]any, appLabels map[string]string) {
metadata := make(map[string]any)
if m, ok := obj["metadata"]; ok {
metadata = m.(map[string]interface{})
metadata = m.(map[string]any)
}
labels := make(map[string]string)
if l, ok := metadata["labels"]; ok {
for k, v := range l.(map[string]interface{}) {
for k, v := range l.(map[string]any) {
labels[k] = fmt.Sprintf("%v", v)
}
}