forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
56 lines (47 loc) · 1.26 KB
/
Copy pathoption.go
File metadata and controls
56 lines (47 loc) · 1.26 KB
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
package api
import (
"fmt"
"github.com/ipfs/go-cid"
"github.com/textileio/powergate/ffs"
)
// PushConfigOption mutates a push configuration.
type PushConfigOption func(o *PushConfig) error
// PushConfig contains options for pushing a Cid configuration.
type PushConfig struct {
Config ffs.CidConfig
OverrideConfig bool
}
func newDefaultPushConfig(c cid.Cid, dc ffs.DefaultConfig) PushConfig {
return PushConfig{
Config: newDefaultCidConfig(c, dc),
}
}
func newDefaultCidConfig(c cid.Cid, dc ffs.DefaultConfig) ffs.CidConfig {
return ffs.CidConfig{
Cid: c,
Hot: dc.Hot,
Cold: dc.Cold,
}
}
// WithCidConfig overrides the Api default Cid configuration.
func WithCidConfig(c ffs.CidConfig) PushConfigOption {
return func(o *PushConfig) error {
o.Config = c
return nil
}
}
// WithOverride allows a new push configuration to override an existing one.
// It's used as an extra security measure to avoid unwanted configuration changes.
func WithOverride(override bool) PushConfigOption {
return func(o *PushConfig) error {
o.OverrideConfig = override
return nil
}
}
// Validate validates a PushConfig.
func (pc PushConfig) Validate() error {
if err := pc.Config.Validate(); err != nil {
return fmt.Errorf("invalid config: %s", err)
}
return nil
}