The Go spec states:
The comparison operators == and != (§Comparison operators) must be fully defined for operands of the key type; thus the key type must not be a struct, array or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.
I wish to create a map of hash values which come from the Hash interface, which returns []byte
, but for which all my hashes are done with the same algorithm (thereby I know that it would fit into [16]byte
). How can I provide the appropriate interface such that the map
type will allow []byte
or [16]byte
or some wrapper thereof to be used as a key?
Presently my use generates the following error:
dupes := make(map[[16]byte][]string)
finddups.go:55: invalid map key type [16]uint8
Update (Mar 2012): Go1 allows [16]byte
as key type.