-
Notifications
You must be signed in to change notification settings - Fork 26
/
repo.go
51 lines (40 loc) · 918 Bytes
/
repo.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
package node
import (
ipfs_config "github.com/ipfs/kubo/config"
ipfs_repo "github.com/ipfs/kubo/repo"
)
var _ ipfs_repo.Repo = (*RepoMobile)(nil)
type RepoConfigPatch func(cfg *ipfs_config.Config) (err error)
type RepoMobile struct {
ipfs_repo.Repo
Path string
}
func NewRepoMobile(path string, repo ipfs_repo.Repo) *RepoMobile {
return &RepoMobile{
Repo: repo,
Path: path,
}
}
func (mr *RepoMobile) ApplyPatchs(patchs ...RepoConfigPatch) error {
cfg, err := mr.Config()
if err != nil {
return err
}
if err := ChainIpfsConfigPatch(patchs...)(cfg); err != nil {
return err
}
return mr.SetConfig(cfg)
}
func ChainIpfsConfigPatch(patchs ...RepoConfigPatch) RepoConfigPatch {
return func(cfg *ipfs_config.Config) (err error) {
for _, patch := range patchs {
if patch == nil {
continue // skip empty patch
}
if err = patch(cfg); err != nil {
return
}
}
return
}
}