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

Should Message be an interface? #5

Closed
hobeone opened this issue Oct 27, 2014 · 4 comments
Closed

Should Message be an interface? #5

hobeone opened this issue Oct 27, 2014 · 4 comments
Labels

Comments

@hobeone
Copy link

hobeone commented Oct 27, 2014

It seems like it might be a good idea to make Message an interface in gomail rather than a concrete struct. This would allow users of the library to use the sending functionality separately from the message creation functionality.

I'm was looking at switching over my rss mailer (https://github.com/hobeone/rss2go) to use gomail and ran into this. I could rework my mailer to use gomail.Message directly but I thought that maybe this pointed out a way to make gomail better.

@alexcesaro
Copy link
Member

What kind of function do you need exactly?

The previous version of Gomail exposed a Send function. Is that the kind of function you need?

@hobeone
Copy link
Author

hobeone commented Oct 28, 2014

I had wrapped up gomail.Message in my own struct:

type Message struct {
  gomail.Message
}

to allow for validation of the message before sending (as I mention in issue #6). I can't pass this to gomail.Mailer.Send() directly as it's not the right type. I thought an interface might be better here as all the Mailer needs is something it can call Export() on. (or maybe just pass in a *mail.Message directly?)

@alexcesaro
Copy link
Member

Have you tried something like that?

package main

import "fmt"

type Message struct{}

type MessageWrapper struct {
    *Message
}

func main() {
    m := new(MessageWrapper)
    Send(m.Message)
}

func Send(m *Message) {
    fmt.Println("Message sent!")
}

http://play.golang.org/p/Pzf3_s2TIv

@hobeone
Copy link
Author

hobeone commented Oct 29, 2014

Yeah this totally works. I guess my question was more if it might make some use cases cleaner to have it be an Interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants