Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions transmissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,31 @@ func ParseRecipients(recips interface{}) (ra *[]Recipient, err error) {
func ParseContent(content interface{}) (err error) {
switch rVal := content.(type) {
case map[string]interface{}:
for k, v := range rVal {
switch vVal := v.(type) {
case string:
if strings.EqualFold(k, "template_id") {
return nil
}
default:
return fmt.Errorf("Transmission.Content objects must contain string values, not [%T]", vVal)
var found bool
for key := range rVal {
if strings.ToLower(key) == "template_id" {
found = true
break
}
}
if found {
return nil
}
return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

case map[string]string:
for k := range rVal {
if strings.EqualFold(k, "template_id") {
return nil
// Have to duplicate logic here, we cannot add it above because it will then conflate rVal as an interface{}
// Exact error message: invalid operation: cannot index rVal (variable of type interface{})
var found bool
for key := range rVal {
if strings.ToLower(key) == "template_id" {
found = true
break
}
}
if found {
return nil
}
return fmt.Errorf("Transmission.Content objects must contain a key `template_id`")

case Content:
te := &Template{Name: "tmp", Content: rVal}
return te.Validate()
Expand Down