miguelmota / ethereum-development-with-go-book

📖 A little guide book on Ethereum Development with Go (golang)
https://goethereumbook.org
Other
1.74k stars 427 forks source link

Go doesn't "cast" types; corrected one instance as eg of change #26

Closed zeddee closed 5 years ago

zeddee commented 5 years ago

Go doesn't "cast" types — would be more accurate to describe this as a type assertion, to correctly reflect what is going on with the Go code.

Not casting because priv.Public() returns an interface, which has an underlying type of *ecdsa.PublicKey. Calling publicKey.(*ecdsa.PublicKey) doesn't perform a conversion, but instead asserts *ecdsa.PublicKey as the resulting variable's type. If *ecdsa.PublicKey is not the underlying type of the variable it is performed on, the operation panics. The underlying type of the variable the type assertion is called on never changes.

If change is ok, will make changes across the rest of the guide.

source: https://stackoverflow.com/a/19579058

miguelmota commented 5 years ago

@zeddee ah thanks for the clarification and correcting the misinformation. The change looks good

zeddee commented 5 years ago

hey @miguelmota , i've updated the PR to correct the "casting/type assertion" error messages across the guide:

from:

log.Fatal("error casting public key to ECDSA")

to:

log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
miguelmota commented 5 years ago

@zeddee merged. thanks for the PR 👍