Adds a FromFile function to settings
This commit is contained in:
parent
2000747176
commit
83a5b7ce75
@ -14,6 +14,11 @@
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Settings provides a structure to interact with the settings
|
||||
// of a Ponder library
|
||||
type Settings struct {
|
||||
@ -22,3 +27,18 @@ type Settings struct {
|
||||
LilypondIncludes []string // Directories to be included when running the lilypond compiler
|
||||
OutputDir string // Directory in which all complete file are stored
|
||||
}
|
||||
|
||||
// FromFile reads a settings file in json format and returns the Settings struct
|
||||
func FromFile(path string) (*Settings, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var s *Settings
|
||||
err = json.Unmarshal(data, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user