Skip to content

Commit

Permalink
[ignore] Move generic util functions to utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
akinross committed Dec 2, 2024
1 parent a1d84ee commit c872235
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 0 additions & 28 deletions mso/resource_mso_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,31 +461,3 @@ func resourceMSOTemplateImport(d *schema.ResourceData, m interface{}) ([]*schema
log.Println("[DEBUG] MSO Template Resource: Import Completed", d.Id())
return []*schema.ResourceData{d}, nil
}

func getListOfStringsFromSchemaList(d *schema.ResourceData, key string) []string {
if values, ok := d.GetOk(key); ok {
return convertToListOfStrings(values.([]interface{}))
}
return nil
}

func convertToListOfStrings(values []interface{}) []string {
result := []string{}
for _, item := range values {
result = append(result, item.(string))
}
return result
}

func duplicatesInList(list []string) []string {
duplicates := []string{}
set := make(map[string]int)
for index, item := range list {
if _, ok := set[item]; ok {
duplicates = append(duplicates, item)
} else {
set[item] = index
}
}
return duplicates
}
28 changes: 28 additions & 0 deletions mso/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,31 @@ func createPortPath(path_type, static_port_pod, static_port_leaf, static_port_fe
return fmt.Sprintf("topology/%s/paths-%s/pathep-[%s]", static_port_pod, static_port_leaf, static_port_path)
}
}

func getListOfStringsFromSchemaList(d *schema.ResourceData, key string) []string {
if values, ok := d.GetOk(key); ok {
return convertToListOfStrings(values.([]interface{}))
}
return nil
}

func convertToListOfStrings(values []interface{}) []string {
result := []string{}
for _, item := range values {
result = append(result, item.(string))
}
return result
}

func duplicatesInList(list []string) []string {
duplicates := []string{}
set := make(map[string]int)
for index, item := range list {
if _, ok := set[item]; ok {
duplicates = append(duplicates, item)
} else {
set[item] = index
}
}
return duplicates
}

0 comments on commit c872235

Please sign in to comment.