-
Notifications
You must be signed in to change notification settings - Fork 462
/
config.go
39 lines (31 loc) · 880 Bytes
/
config.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
package config
import (
repo2 "github.com/filecoin-project/venus/pkg/repo"
"sync"
)
// configModule is plumbing implementation for setting and retrieving values from local config.
type ConfigModule struct { //nolint
repo repo2.Repo
lock sync.Mutex
}
// NewConfig returns a new configModule.
func NewConfigModule(repo repo2.Repo) *ConfigModule {
return &ConfigModule{repo: repo}
}
// Set sets a value in config
func (s *ConfigModule) Set(dottedKey string, jsonString string) error {
s.lock.Lock()
defer s.lock.Unlock()
cfg := s.repo.Config()
if err := cfg.Set(dottedKey, jsonString); err != nil {
return err
}
return s.repo.ReplaceConfig(cfg)
}
// Get gets a value from config
func (s *ConfigModule) Get(dottedKey string) (interface{}, error) {
return s.repo.Config().Get(dottedKey)
}
func (s *ConfigModule) API() *ConfigAPI {
return &ConfigAPI{config: s}
}