forked from web3-storage/go-w3s-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopts.go
87 lines (75 loc) · 2.14 KB
/
opts.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package w3s
import (
"io/fs"
"time"
ds "github.com/ipfs/go-datastore"
)
// Option is an option configuring a web3.storage client.
type Option func(cfg *clientConfig) error
// WithEndpoint sets the URL of the root API when making requests (default
// https://api.web3.storage).
func WithEndpoint(endpoint string) Option {
return func(cfg *clientConfig) error {
if endpoint != "" {
cfg.endpoint = endpoint
}
return nil
}
}
// WithToken sets the auth token to use in the Authorization header when making
// requests to the API.
func WithToken(token string) Option {
return func(cfg *clientConfig) error {
cfg.token = token
return nil
}
}
// WithDatastore sets the underlying datastore to use when reading or writing
// DAG block data. The default is to use a new in-memory store per Get/Put
// request.
func WithDatastore(ds ds.Batching) Option {
return func(cfg *clientConfig) error {
if ds != nil {
cfg.ds = ds
}
return nil
}
}
// PutOption is an option configuring a call to Put.
type PutOption func(cfg *putConfig) error
// WithFs sets the file system interface for use with file operations.
func WithFs(fsys fs.FS) PutOption {
return func(cfg *putConfig) error {
if fsys != nil {
cfg.fsys = fsys
}
return nil
}
}
// WithDirname sets the root directory path, for use when the provided file is a
// directory and does NOT implement fs.ReadDirFile. The default is "", which
// will resolve to the current working directory if the file system interface is
// the default (the OS).
func WithDirname(dirname string) PutOption {
return func(cfg *putConfig) error {
cfg.dirname = dirname
return nil
}
}
// ListOption is an option configuring a call to List.
type ListOption func(cfg *listConfig) error
// WithBefore sets the time that items in the list were uploaded before.
func WithBefore(before time.Time) ListOption {
return func(cfg *listConfig) error {
cfg.before = before
return nil
}
}
// WithMaxResults sets the maximum number of results that will be available from
// the iterator.
func WithMaxResults(maxResults int) ListOption {
return func(cfg *listConfig) error {
cfg.maxResults = maxResults
return nil
}
}