on hold: reflection decoder
This commit is contained in:
33
interfaces/reflection-decoder/_decoder_reader.go
Normal file
33
interfaces/reflection-decoder/_decoder_reader.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var store list
|
||||
|
||||
if err := json.Unmarshal(data, &store); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return store, nil
|
||||
}
|
||||
Reference in New Issue
Block a user