forked from filecoin-project/motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
62 lines (55 loc) · 1.51 KB
/
options.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
package motion
import (
"os"
"github.com/filecoin-project/motion/api/server"
"github.com/filecoin-project/motion/blob"
"github.com/filecoin-project/motion/wallet"
)
type (
// Option represents a configurable parameter in Motion service.
Option func(*options) error
options struct {
serverOptions []server.Option
blobStore blob.Store
wallet *wallet.Wallet
}
)
func newOptions(o ...Option) (*options, error) {
opts := &options{}
for _, apply := range o {
if err := apply(opts); err != nil {
return nil, err
}
}
if opts.blobStore == nil {
dir := os.TempDir()
logger.Warnw("No blob store is specified. Falling back on local blob store in temporary directory.", "dir", dir)
opts.blobStore = blob.NewLocalStore(dir)
}
return opts, nil
}
// WithServerOptions sets the options to be used when instantiating server.HttpServer.
// Defaults to no options.
func WithServerOptions(serverOptions ...server.Option) Option {
return func(o *options) error {
o.serverOptions = serverOptions
return nil
}
}
// WithBlobStore sets the blob.Store to use for storage and retrieval of blobs.
// Defaults to blob.LocalStore at a temporary directory.
// See: blob.NewLocalStore, os.TempDir.
func WithBlobStore(s blob.Store) Option {
return func(o *options) error {
o.blobStore = s
return nil
}
}
// WithWallet sets the wallet used by Motion to interact with FileCoin network.
// Defaults to wallet.New.
func WithWallet(w *wallet.Wallet) Option {
return func(o *options) error {
o.wallet = w
return nil
}
}