-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
44 lines (35 loc) · 905 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
40
41
42
43
44
package mockups
import (
"errors"
"os"
"github.com/pushbits/server/internal/configuration"
"github.com/pushbits/server/internal/log"
)
// ReadConfig copies the given filename to the current folder and parses it as a config file. RemoveFile indicates whether to remove the copied file or not
func ReadConfig(filename string, removeFile bool) (config *configuration.Configuration, err error) {
defer func() {
if r := recover(); r != nil {
log.L.Println(r)
err = errors.New("paniced while reading config")
}
}()
if filename == "" {
return nil, errors.New("empty filename")
}
file, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
err = os.WriteFile("config.yml", file, 0o644)
if err != nil {
return nil, err
}
config = configuration.Get()
if removeFile {
err = os.Remove("config.yml")
if err != nil {
return nil, err
}
}
return config, nil
}