-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
40 lines (32 loc) · 792 Bytes
/
web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package app
import (
"context"
"fmt"
"io"
"io/fs"
"github.com/ItsNotGoodName/smtpbridge/internal/models"
"github.com/ItsNotGoodName/smtpbridge/web"
)
// WebTestFileStore is used for testing endpoints.
type WebTestFileStore struct {
name string
url string
}
func NewWebTestFileStore(name, url string) WebTestFileStore {
return WebTestFileStore{
name: name,
url: url,
}
}
func (w WebTestFileStore) File() (fs.File, error) {
return web.FS.Open(w.name)
}
func (w WebTestFileStore) Reader(ctx context.Context, att models.Attachment) (io.ReadCloser, error) {
return w.File()
}
func (w WebTestFileStore) Path(ctx context.Context, att models.Attachment) (string, error) {
if w.url == "" {
return "", fmt.Errorf("app: url is empty")
}
return w.url + "/" + w.name, nil
}