refactor: marshaler unmarshaler iface

This commit is contained in:
Inanc Gumus
2019-10-21 15:21:34 +03:00
parent 59865eac28
commit 3ac59459fd
13 changed files with 83 additions and 38 deletions

View File

@@ -7,9 +7,7 @@
package main
import (
"encoding/json"
)
import "encoding/json"
func encode() ([]byte, error) {
l := list{
@@ -17,13 +15,12 @@ func encode() ([]byte, error) {
{Title: "odyssey", Price: 15, Released: toTimestamp("733622400")},
{Title: "hobbit", Price: 25},
}
return json.MarshalIndent(l, "", "\t")
}
func decode(data []byte) (l list, err error) {
func decode(data []byte) (l list, _ error) {
if err := json.Unmarshal(data, &l); err != nil {
return nil, err
}
return l, nil
return
}