Skip to content

Instantly share code, notes, and snippets.

@Bebbolus
Created November 30, 2018 16:50
Show Gist options
  • Save Bebbolus/307dc966dc2a3d8a3efd8f8fdd4a33b4 to your computer and use it in GitHub Desktop.
Save Bebbolus/307dc966dc2a3d8a3efd8f8fdd4a33b4 to your computer and use it in GitHub Desktop.
//ReadFromJSON function load a json file into a struct or return error
func ReadFromJSON(t interface{}, filename string) error {
jsonFile, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
err = json.Unmarshal([]byte(jsonFile), t)
if err != nil {
log.Fatalf("error: %v", err)
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment