2019-09-03 23:15:46 +03:00
|
|
|
// For more tutorials: https://blog.learngoprogramming.com
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 2018 Inanc Gumus
|
|
|
|
|
// Learn Go Programming Course
|
|
|
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
)
|
|
|
|
|
|
2019-09-04 16:52:53 +03:00
|
|
|
func fromFile(f *os.File) (list, error) {
|
|
|
|
|
return fromReader(f)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fromReader(r io.Reader) (list, error) {
|
|
|
|
|
data, err := ioutil.ReadAll(r)
|
2019-09-03 23:15:46 +03:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 16:52:53 +03:00
|
|
|
var store list
|
2019-09-03 23:15:46 +03:00
|
|
|
|
2019-09-04 16:52:53 +03:00
|
|
|
if err := json.Unmarshal(data, &store); err != nil {
|
2019-09-03 23:15:46 +03:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 16:52:53 +03:00
|
|
|
return store, nil
|
2019-09-03 23:15:46 +03:00
|
|
|
}
|