From 0915597b30d62fe2b2d2af633e762faf5fcac4ca Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 26 Oct 2023 17:59:31 -0700 Subject: [PATCH 1/2] Fix sending Transmission content with template_id. --- transmissions.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/transmissions.go b/transmissions.go index 17f177b..787760a 100644 --- a/transmissions.go +++ b/transmissions.go @@ -126,26 +126,19 @@ 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) - } + _, isOk := rVal["template_id"] + if isOk { + 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{}) + _, isOk := rVal["template_id"] + if isOk { + 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() From 9251d73808357222c3a5de790c1f225b82b8e4de Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Fri, 27 Oct 2023 10:33:24 -0700 Subject: [PATCH 2/2] Case insensitive op --- transmissions.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/transmissions.go b/transmissions.go index 787760a..bf020fc 100644 --- a/transmissions.go +++ b/transmissions.go @@ -126,16 +126,28 @@ func ParseRecipients(recips interface{}) (ra *[]Recipient, err error) { func ParseContent(content interface{}) (err error) { switch rVal := content.(type) { case map[string]interface{}: - _, isOk := rVal["template_id"] - if isOk { + 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: // 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{}) - _, isOk := rVal["template_id"] - if isOk { + 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`")