diff --git a/settings/settings.go b/settings/settings.go index 647515a..ef7ac90 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -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 +}