package
0.0.0-20240228044302-56ad08b2fa1c
Repository: https://github.com/parsiya/parsia-code.git
Documentation: pkg.go.dev
# README
Gophercises - 9 - Deck of Cards
Problem
Solution
- deck/main.go: Package.
Lessons Learned
Stringer package
Stringer package can generate String()
for types. In this case, we can use it to make one for Suit
and Value
types.
go get golang.org/x/tools/cmd/stringer
- go doc with example: https://godoc.org/golang.org/x/tools/cmd/stringer
- Add the following on top of the file with the types (in this case
deck/card.go
).//go:generate stringer -type=Suit,Value
- Run
go generate
inside thedeck
directory. - It will create a file named
suit_string.go
. - Now we can call
Suit.String()
and it will return a string.