Size of a byte array golang

To return the number of bytes in a byte slice use the len function:

bs := make([]byte, 1000)
sz := len(bs)
// sz == 1000

If you mean the number of bytes in the underlying array use cap instead:

bs := make([]byte, 1000, 2000)
sz := cap(bs)
// sz == 2000

A byte is guaranteed to be one byte: https://golang.org/ref/spec#Size_and_alignment_guarantees.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)