forked from mislav/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_service.go
More file actions
43 lines (35 loc) · 750 Bytes
/
Copy pathconfig_service.go
File metadata and controls
43 lines (35 loc) · 750 Bytes
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
package github
import (
"os"
"path/filepath"
)
func newConfigService() *configService {
return &configService{
Encoder: &yamlConfigEncoder{},
Decoder: &yamlConfigDecoder{},
}
}
type configService struct {
Encoder configEncoder
Decoder configDecoder
}
func (s *configService) Save(filename string, c *Config) error {
err := os.MkdirAll(filepath.Dir(filename), 0771)
if err != nil {
return err
}
w, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
defer w.Close()
return s.Encoder.Encode(w, c)
}
func (s *configService) Load(filename string, c *Config) error {
r, err := os.Open(filename)
if err != nil {
return err
}
defer r.Close()
return s.Decoder.Decode(r, c)
}