What is the meaning of the usage of. ([] byte) in golang

b, ok: = val. ([] byte)

if it"s a conversion type, shouldn"t it be [] byte (val)? it"s similar to string (val)

.
Sep.02,2021

this is not a conversion type. The so-called type assertion (type assertion), simply looks at whether the type of val is [] byte


.

some val cannot directly use [] byte (val) or similar to string (val).
first of all, if the val type is uncertain, you will not be able to use a compiler similar to string (val),.
if you already know your val type, you don't have to execute b, ok: = val. ([] byte), do you?

then b, ok: = val. ([] byte), if ok is true, it means success, and b can be used.

Menu