-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuh.go
52 lines (43 loc) · 983 Bytes
/
fuh.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
41
42
43
44
45
46
47
48
49
50
51
52
package fuh
import (
"context"
"io"
"net/http"
"sync"
)
// FileInfo upload the basic information of the file
type FileInfo interface {
FullName() string
Name() string
Size() int64
}
// Uploader file upload interface
type Uploader interface {
Upload(ctx context.Context, r *http.Request, key string) ([]FileInfo, error)
}
// Storer file storage interface
type Storer interface {
Store(ctx context.Context, filename string, data io.Reader, size int64) error
}
var (
internalHandle *uploadHandle
once sync.Once
)
func uploader() *uploadHandle {
once.Do(func() {
internalHandle = &uploadHandle{}
})
return internalHandle
}
// SetConfig set the configuration parameters
func SetConfig(cfg *Config) {
uploader().cfg = cfg
}
// SetStore set storage
func SetStore(store Storer) {
uploader().store = store
}
// Upload file upload
func Upload(ctx context.Context, r *http.Request, key string) ([]FileInfo, error) {
return uploader().Upload(ctx, r, key)
}