添加错误返回
不知道英文区的人能否看懂Cnglish。。。
Showing
1 changed file
with
6 additions
and
4 deletions
| ... | @@ -158,7 +158,8 @@ func (e *Email) Bytes() ([]byte, error) { | ... | @@ -158,7 +158,8 @@ func (e *Email) Bytes() ([]byte, error) { |
| 158 | 158 | ||
| 159 | // Add attach file to the send mail | 159 | // Add attach file to the send mail |
| 160 | func (e *Email) AttachFile(args ...string) (a *Attachment, err error) { | 160 | func (e *Email) AttachFile(args ...string) (a *Attachment, err error) { |
| 161 | if len(args) < 1 || len(args) > 2 { | 161 | if len(args) < 1 && len(args) > 2 { |
| 162 | err = errors.New("Must specify a file name and number of parameters can not exceed at least two") | ||
| 162 | return | 163 | return |
| 163 | } | 164 | } |
| 164 | filename := args[0] | 165 | filename := args[0] |
| ... | @@ -178,13 +179,14 @@ func (e *Email) AttachFile(args ...string) (a *Attachment, err error) { | ... | @@ -178,13 +179,14 @@ func (e *Email) AttachFile(args ...string) (a *Attachment, err error) { |
| 178 | // Attach is used to attach content from an io.Reader to the email. | 179 | // Attach is used to attach content from an io.Reader to the email. |
| 179 | // Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type. | 180 | // Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type. |
| 180 | func (e *Email) Attach(r io.Reader, filename string, args ...string) (a *Attachment, err error) { | 181 | func (e *Email) Attach(r io.Reader, filename string, args ...string) (a *Attachment, err error) { |
| 181 | if len(args) < 1 || len(args) > 2 { | 182 | if len(args) < 1 && len(args) > 2 { |
| 183 | err = errors.New("Must specify a file type and number of parameters can not exceed at least two") | ||
| 182 | return | 184 | return |
| 183 | } | 185 | } |
| 184 | c := args[0] //Content-Type | 186 | c := args[0] //Content-Type |
| 185 | id := "" | 187 | id := "" |
| 186 | if len(args) > 1 { | 188 | if len(args) > 1 { |
| 187 | id = args[1] //Content-ID | 189 | id = args[1] //Content-ID |
| 188 | } | 190 | } |
| 189 | var buffer bytes.Buffer | 191 | var buffer bytes.Buffer |
| 190 | if _, err = io.Copy(&buffer, r); err != nil { | 192 | if _, err = io.Copy(&buffer, r); err != nil { | ... | ... |
-
Please register or sign in to post a comment