Hashing a struct twice

Hello, I have a simple struct and I want to compute the double hash of it if the first hash is even, else compute only a single hash. My current code is as follows:

package main

import (


type Person struct {
	FirstName string
	LastName  string

func main() {
	var p = Person{"firstnamefirstnamefirstnamefirstname", "lastnamelastnamelastnamelastnamelastname"}

	s := fmt.Sprintf("%v", p)
	hash := blake2b.Sum256([]byte(s))
	zz := new(big.Int)

	fmt.Printf("%T\n", zz)
	fmt.Printf("%T\n", zz.Bytes)
	if zz.Bit(0) == 0 {
		hash = blake2b.Sum256(zz.Bytes)

However I’m getting an error at the last line:
cannot use zz.Bytes (type func() []byte) as type []byte in argument to blake2b.Sum256
I’m not sure how to fix it, can someone help? Thanks in advance…


zz.Bytes is a func (method) so you would need to add parenthesis.
hash = blake2b.Sum256(zz.Bytes())


Still learning the tricks of Go… Thanks a lot!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.