refactor: marshaler unmarshaler iface
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user