Created
November 30, 2018 16:50
-
-
Save Bebbolus/307dc966dc2a3d8a3efd8f8fdd4a33b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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