-
Notifications
You must be signed in to change notification settings - Fork 13
/
rw.go
43 lines (39 loc) · 1.01 KB
/
rw.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
package acmewrapper
import (
"errors"
"io/ioutil"
)
// ErrNotHandled is returned by read and write file callbacks if the file should be
// read from filesystem.
var ErrNotHandled = errors.New("not handled")
func (w *AcmeWrapper) loadFile(path string) ([]byte, error) {
//use custom load file callback?
if w.Config.LoadFileCallback != nil {
if b, err := w.Config.LoadFileCallback(path); err == nil {
return b, nil
} else if err != ErrNotHandled {
return nil, err
}
}
//default load from disk
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return b, nil
}
func (w *AcmeWrapper) saveFile(path string, contents []byte) error {
//use custom save file callback?
if w.Config.SaveFileCallback != nil {
if err := w.Config.SaveFileCallback(path, contents); err == nil {
return nil
} else if err != ErrNotHandled {
return err
}
}
//default save to disk (current user read+write only!)
if err := ioutil.WriteFile(path, contents, 0600); err != nil {
return err
}
return nil
}