/
toml.go
41 lines (31 loc) · 915 Bytes
/
toml.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
package files
import (
"github.com/mosaicnetworks/monetd/src/common"
"github.com/pelletier/go-toml"
)
//LoadToml loads a Toml file and returns a tree object.
func LoadToml(tomlFile string) (*toml.Tree, error) {
config, err := toml.LoadFile(tomlFile)
if err != nil {
common.ErrorMessage("Error loading toml file: ", tomlFile)
return nil, err
}
return config, nil
}
//SaveToml writes a tree object (back) to a toml file
func SaveToml(tree *toml.Tree, tomlFile string) error {
// Open Writer
tomlStr, err := tree.ToTomlString()
if err != nil {
common.ErrorMessage("Cannot parse toml output file: ", tomlFile)
return err
}
err = WriteToFile(tomlFile, tomlStr, 0)
if err != nil {
common.ErrorMessage("Failed to write toml output file", tomlFile)
return err
}
common.DebugMessage("Written toml file: ", tomlFile)
common.DebugMessage("Characters written ", len(tomlStr))
return nil
}