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 Nov 11, 2024
1 parent b0c0297 commit e267739
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 @@ -240,3 +240,31 @@ func getSchemaIdFromName(msoClient *client.Client, name string) (string, error)

return "", fmt.Errorf("Schema of specified name not found")
}

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 e267739

Please sign in to comment.