Most of the packages in golang return response in byte ([]).
e.g if you do
exec.Command("ls").Output()
or http.Get("http://example.com")
or anything else, the response is in byte ([]).
whats the reasoning behind this?
Most of the packages in golang return response in byte ([]).
e.g if you do
exec.Command("ls").Output()
or http.Get("http://example.com")
or anything else, the response is in byte ([]).
whats the reasoning behind this?
For further actions, you may consider blocking this person and/or reporting abuse
Kuldeep Singh -
APIMatic.io -
Benjamen Pyle -
Abhishek Gupta -
Once suspended, fy09 will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, fy09 will be able to comment and publish posts again.
Once unpublished, all posts by fy09 will become hidden and only accessible to themselves.
If fy09 is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to fy.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag fy09:
Unflagging fy09 will restore default visibility to their posts.
Top comments (3)
Byte arrays and strings have some key differences, the main one being byte arrays/slices are mutable, while strings are immutable. My guess is many places byte arrays are returned have to do with that, and the ability to efficiently change the size of the array without allocating new memory. So, if you're reading from a unix socket and you don't know how much data you're going to read (the case with both the examples above) it's probably faster to use a byte array rather than re-allocate a larger string every time you read more data from the socket.
This could be misleading to people unfamiliar with Go. The underlying structure of strings are byte arrays, which is why you have to be careful when you loop over a string because it'll give you byte-by-byte not character-by-character.
Byte arrays are used because they can be unmarshalled, whereas strings cannot.
Hi Fayz, I am happy to see you are ramping up your go game. 😄