-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Unify attachment handling API #33
Comments
I made a PR implementing these modifications. |
Note: I don't speak english, sorry any mistake.
The name is only a new name that developer want to deliver. For example, the developer can attach a file like this: AddAttachment("filepaht/aaa.txt") And the developer can use a new name for the file AddAttachment("filepaht/aaa.txt","bbb.txt") The attachment will be received like bbb.txt And, the reason this is implemented that form is because a mandatory name will confuse some developers. Send mail with attachment is attach the file only, It's weird to see an implementation where name should change. And about the mimetype, the package, with the name of file, can capture the mimeType. This not apply when attach a file from bytes and that's why these functions requires mimeType, but I think it's better remove the mimeType parameter and calculate the mimeType from name like other functions. |
One possibility would be to keep |
WIP to merge all attachment to only one Email method called Attach and use the struct File to set the attachment information. For #33
I have another idea to unify all attachment. All these methods: func (email *Email) AddAttachment(file string, name ...string) *Email
func (email *Email) AddAttachmentBase64(b64File, name string) *Email
func (email *Email) AddAttachmentData(data []byte, filename, mimeType string) *Email
func (email *Email) AddInline(file string, name ...string) *Email
func (email *Email) AddInlineBase64(b64File, name, mimeType string) *Email
func (email *Email) AddInlineData(data []byte, filename, mimeType string) *Email Replace with only one and use a struct to define the attachment. The struct: type File struct {
Filepath string
Name string
MimeType string
B64File string
Data []byte
Inline bool
} The method to unify all: func (email *Email) Attach(file File) *Email The commit cb2f478 (non tested and WIP) is based on this idea. Feel free to test. |
unify-attach branch is the branch to test this. |
Hi, @xhit |
@jlinnosa I finished the Unify attachment api. Please see the unify-attach. There are some changes in my last comment The solution, if not problem with that, will be merged with a new version v3 |
@hiendv please fill another issue and I will respond on that. |
I'm ok with that. I looked over the changes in the PR and commented on some things. |
You could add a simple shim to implement the current API with this new function so there would be no need to bump the major version. This could be just a new feature. You could then deprecate and remove the old API when releasing v3 later. |
Thanks, I will work on that maybe tomorrow. |
Added in #35 Not a breaking change. |
Like I commented in the PR, please don't keep two separate implementations for the same functionality. That could be a major hindrance in the future. |
Merge all attachment to only one Email method called Attach and use the struct File to set the attachment information. Instead to do a breaking change, maintain the old way until v3. Fix #33
Currently we have the following function signatures for adding attachments to an Email struct:
For some reason
AddAttachment
andAddInline
are variadic but only accept one name:Other functions take
name
as parameter and possibly alsomimeType
.I propose we modify all these functions to accept
name
andmimeType
. So the API would become:edit. I changed argument name
b64File
->b64Data
so it is consistent withfile
anddata
arguments.The text was updated successfully, but these errors were encountered: