I have something like
unixtime := time.Now().Unix()
unixtimeStr := string(unixtime)
soup := make([]byte, len(data) + len(nonce) + len(unixtimeStr) + len(previousHash))
copy(soup[:], data)
copy(soup[len(data):], nonce)
copy(soup[len(data) + len(nonce):], []byte(unixtimeStr))
copy(soup[len(data) + len(nonce) + len(unixtimeStr):], previousHash)
hasher := sha1.New()
hasher.Write(soup)
var hash []byte = hasher.Sum(nil)
data
, nonce
, previousHash
are of type []byte
.
I find it so dirty and unreadable!
I'd like a more object oriented coding style like
soup := data.concat(nonce).concat([]byte(unixtimeStr)).concat(previousHash)
or at least something like
soup := concat(data, nonce, ...)
How would you write this snippet?