-
Notifications
You must be signed in to change notification settings - Fork 80
/
s3.go
67 lines (57 loc) · 1.52 KB
/
s3.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package s3
import (
config "github.com/bittorrent/go-btfs-config"
"github.com/bittorrent/go-btfs/s3/api/handlers"
"github.com/bittorrent/go-btfs/s3/api/providers"
"github.com/bittorrent/go-btfs/s3/api/routers"
"github.com/bittorrent/go-btfs/s3/api/server"
"github.com/bittorrent/go-btfs/s3/api/services/accesskey"
"github.com/bittorrent/go-btfs/s3/api/services/object"
"github.com/bittorrent/go-btfs/s3/api/services/sign"
"github.com/bittorrent/go-btfs/s3/ctxmu"
"github.com/bittorrent/go-btfs/transaction/storage"
"sync"
)
var (
ps *providers.Providers
once sync.Once
)
func InitProviders(stateStore storage.StateStorer) (err error) {
once.Do(func() {
var (
sstore providers.StateStorer
fstore providers.FileStorer
)
sstore = providers.NewStorageStateStoreProxy(stateStore)
fstore, err = providers.NewBtfsAPI()
if err != nil {
return
}
ps = providers.NewProviders(sstore, fstore)
})
return
}
func GetProviders() *providers.Providers {
return ps
}
func NewServer(cfg config.S3CompatibleAPI) *server.Server {
// global multiple keys read write lock
lock := ctxmu.NewDefaultMultiCtxRWMutex()
// services
sigsvc := sign.NewService()
acksvc := accesskey.NewService(ps, accesskey.WithLock(lock))
objsvc := object.NewService(ps, object.WithLock(lock))
// handlers
hs := handlers.NewHandlers(
acksvc, sigsvc, objsvc,
handlers.WithHeaders(cfg.HTTPHeaders),
)
// routers
rs := routers.NewRouters(hs)
// server
svr := server.NewServer(
rs,
server.WithAddress(cfg.Address),
)
return svr
}