~edwargix/tallyard

91069fa5b67c0fb5fb0f715b8ab28b14ac1e238c — David Florness 2 years ago d1052e8
Log reading and unmarshalling of elections file
2 files changed, 4 insertions(+), 2 deletions(-)

M cmd/tallyard/main.go
M election/map.go
M cmd/tallyard/main.go => cmd/tallyard/main.go +3 -1
@@ 269,12 269,14 @@ func getElections(userID id.UserID) (*election.ElectionsMap, error) {
		return nil, fmt.Errorf("couldn't stat elections file: %s", err)
	}

	log.Info("reading elections file...")
	jsonBytes, err := ioutil.ReadFile(electionsFname)
	if err != nil {
		return nil, fmt.Errorf("couldn't read elections file: %s", err)
	}

	em, err := election.ReadElectionsMapFrom(jsonBytes, userID, saveElections)
	log.Info("unmarshalling elections file...")
	em, err := election.UnmarshalElectionsMapFrom(jsonBytes, userID, saveElections)
	if err != nil {
		return nil, fmt.Errorf("couldn't read elections map: %s", err)
	}

M election/map.go => election/map.go +1 -1
@@ 41,7 41,7 @@ func NewElectionsMap(userID id.UserID, save func(*ElectionsMap)) *ElectionsMap {
	}
}

func ReadElectionsMapFrom(jsonBytes []byte, userID id.UserID, save func(*ElectionsMap)) (*ElectionsMap, error) {
func UnmarshalElectionsMapFrom(jsonBytes []byte, userID id.UserID, save func(*ElectionsMap)) (*ElectionsMap, error) {
	em := &ElectionsMap{}
	err := json.Unmarshal(jsonBytes, em)
	if err != nil {