Files
learngo/interfaces/reflection-decoder/_decoder_reader.go

34 lines
542 B
Go
Raw Normal View History

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"
)
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
}
var store list
2019-09-03 23:15:46 +03:00
if err := json.Unmarshal(data, &store); err != nil {
2019-09-03 23:15:46 +03:00
return nil, err
}
return store, nil
2019-09-03 23:15:46 +03:00
}