-
Notifications
You must be signed in to change notification settings - Fork 343
/
local_config.go
56 lines (46 loc) · 1.23 KB
/
local_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package repo
import (
"encoding/json"
"io"
"os"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/content"
"github.com/kopia/kopia/repo/object"
)
// LocalConfig is a configuration of Kopia stored in a configuration file.
type LocalConfig struct {
Storage blob.ConnectionInfo `json:"storage"`
Caching content.CachingOptions `json:"caching"`
}
// repositoryObjectFormat describes the format of objects in a repository.
type repositoryObjectFormat struct {
content.FormattingOptions
object.Format
}
// Load reads local configuration from the specified reader.
func (lc *LocalConfig) Load(r io.Reader) error {
*lc = LocalConfig{}
return json.NewDecoder(r).Decode(lc)
}
// Save writes the configuration to the specified writer.
func (lc *LocalConfig) Save(w io.Writer) error {
b, err := json.MarshalIndent(lc, "", " ")
if err != nil {
return nil
}
_, err = w.Write(b)
return err
}
// loadConfigFromFile reads the local configuration from the specified file.
func loadConfigFromFile(fileName string) (*LocalConfig, error) {
f, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer f.Close() //nolint:errcheck
var lc LocalConfig
if err := lc.Load(f); err != nil {
return nil, err
}
return &lc, nil
}