that's exactly the right way to do it.
alternatively, you don't necessarily have to convert to string
at all - you could just trim the byte slice in place
(the bytes package has all the usual string manipulation functions
that work on []byte instead of string).
>
> So my questions:
>
> 1) What is the right way to get a string from a []byte representing a
> NULL-terminated string?
there are no NULL-terminated strings in Go unless you're calling
C or reading from something external that provides such a string.
> 2) Is it legal for go strings to contain \000 bytes? (I guess it is)
go strings are just immutable byte arrays - it's only
convention that they hold utf-8 encoded text
(apart from the fact that range on a string ranges over
code points, not bytes)
thus there's no problem with them holding 0 bytes.