Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use constants for disposition #473

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions examples/helpers/mail/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"

"github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/mail"
)

Expand Down Expand Up @@ -102,14 +101,14 @@ func kitchenSink() []byte {
a.SetContent("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12")
a.SetType("application/pdf")
a.SetFilename("balance_001.pdf")
a.SetDisposition("attachment")
a.SetDisposition(mail.DispositionAttachment)
m.AddAttachment(a)

a2 := mail.NewAttachment()
a2.SetContent("BwdW")
a2.SetType("image/png")
a2.SetFilename("banner.png")
a2.SetDisposition("inline")
a2.SetDisposition(mail.DispositionInline)
// Content-ID header is included when the attachment disposition is set to "inline"
a2.SetContentID("Banner")
m.AddAttachment(a2)
Expand Down
21 changes: 14 additions & 7 deletions helpers/mail/mail_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,21 @@ type Content struct {
Value string `json:"value,omitempty"`
}

type disposition string

const (
DispositionInline disposition = "inline"
DispositionAttachment disposition = "attachment"
)

// Attachment holds attachement information
type Attachment struct {
Content string `json:"content,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Filename string `json:"filename,omitempty"`
Disposition string `json:"disposition,omitempty"`
ContentID string `json:"content_id,omitempty"`
Content string `json:"content,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Filename string `json:"filename,omitempty"`
Disposition disposition `json:"disposition,omitempty"`
ContentID string `json:"content_id,omitempty"`
}

// Asm contains Grpip Id and int array of groups ID
Expand Down Expand Up @@ -400,7 +407,7 @@ func (a *Attachment) SetFilename(filename string) *Attachment {
}

// SetDisposition ...
func (a *Attachment) SetDisposition(disposition string) *Attachment {
func (a *Attachment) SetDisposition(disposition disposition) *Attachment {
a.Disposition = disposition
return a
}
Expand Down
2 changes: 1 addition & 1 deletion helpers/mail/mail_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func TestV3AttachmentSetContentID(t *testing.T) {
}

func TestV3AttachmentSetDisposition(t *testing.T) {
disposition := "inline"
disposition := DispositionInline
a := NewAttachment().SetDisposition(disposition)

assert.Equal(t, disposition, a.Disposition, fmt.Sprintf("Disposition should be %s, got %s", disposition, a.Disposition))
Expand Down
8 changes: 4 additions & 4 deletions use-cases/attachments-with-mailer-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/mail"
)

[]()
func main() {
// create new *SGMailV3
m := mail.NewV3Mail()
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {
a_txt.SetContent(encoded)
a_txt.SetType("text/plain")
a_txt.SetFilename("testing.txt")
a_txt.SetDisposition("attachment")
a_txt.SetDisposition(mail.DispositionAttachment)

// read/attach .pdf file
a_pdf := mail.NewAttachment()
Expand All @@ -54,7 +54,7 @@ func main() {
a_pdf.SetContent(encoded)
a_pdf.SetType("application/pdf")
a_pdf.SetFilename("testing.pdf")
a_pdf.SetDisposition("attachment")
a_pdf.SetDisposition(mail.DispositionAttachment)

// read/attach inline .jpg file
a_jpg := mail.NewAttachment()
Expand All @@ -66,7 +66,7 @@ func main() {
a_jpg.SetContent(encoded)
a_jpg.SetType("image/jpeg")
a_jpg.SetFilename("testing.jpg")
a_jpg.SetDisposition("inline")
a_jpg.SetDisposition(mail.DispositionInline)
a_jpg.SetContentID("Test Attachment")

// add `a_txt`, `a_pdf` and `a_jpg` to `m`
Expand Down
Loading