From 95e8fbd5f541d4b76ec09dccb893208abf92e75d Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Fri, 18 Mar 2016 17:45:09 +0100 Subject: [PATCH] Adds function to read a score structure from a JSON file --- settings/score.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/settings/score.go b/settings/score.go index cc53232..2726ecf 100644 --- a/settings/score.go +++ b/settings/score.go @@ -14,9 +14,29 @@ package settings +import ( + "encoding/json" + "io/ioutil" +) + // Score represents the settings for a specific score file type Score struct { Name string // The name of the score in the songbook Categories []string // Categories to which the scores belong Path string // The path to the scores (uncompiled) file } + +// FromJSON reads the settings of a score from a JSON file +func FromJSON(path string) (*Score, error) { + data, err := ioutil.ReadFile(path) + if err != nil { + return nil, err + } + + var s Score + err = json.Unmarshal(data, &s) + if err != nil { + return nil, err + } + return &s, nil +}