You've already forked email-api-client
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 20s
34 lines
581 B
Go
34 lines
581 B
Go
package client
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func NewAttachmentFromFileContent(fileName string, f []byte) (*FileAttachment, error) {
|
|
base64.StdEncoding.Encode(f, f)
|
|
|
|
return &FileAttachment{
|
|
Filename: fileName,
|
|
Content: string(f),
|
|
}, nil
|
|
}
|
|
|
|
func NewAttachmentFromFilePath(filePath string) (*FileAttachment, error) {
|
|
f, err := os.Open(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func(f *os.File) {
|
|
_ = f.Close()
|
|
}(f)
|
|
|
|
content, err := io.ReadAll(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return NewAttachmentFromFileContent(filePath, content)
|
|
}
|