refactor: stringer interface

This commit is contained in:
Inanc Gumus
2019-09-03 17:34:21 +03:00
parent fc349bd51d
commit 009398e6d4
5 changed files with 139 additions and 87 deletions

View File

@@ -11,9 +11,9 @@ import "fmt"
func main() {
store := list{
&book{product{"moby dick", 10}, 118281600},
&book{product{"odyssey", 15}, "733622400"},
&book{product{"hobbit", 25}, nil},
&book{product{"moby dick", 10}, toTimestamp(118281600)},
&book{product{"odyssey", 15}, toTimestamp("733622400")},
&book{product{"hobbit", 25}, unknown},
&puzzle{product{"rubik's cube", 5}},
&game{product{"minecraft", 20}},
&game{product{"tetris", 5}},
@@ -26,4 +26,8 @@ func main() {
// but the Print function can print it.
// it's because, the list satisfies the stringer.
fmt.Print(store)
// timestamp is useful even if it's zero.
var ts timestamp
fmt.Println(ts)
}