- The canonical way to block indefinitely is an empty select statement:
select{}
- While canonical way to loop indefinitely is an empty for statement:
for{}
Sunday, January 4, 2015
Trim strings
- To remove final nulls from strings coming from a buffer:
strings.TrimRight(myStringFromABuffer, "\x00")
- To remove new lines from string:
strings.Trim(myString, "\r\n")
strings.TrimRight(myStringFromABuffer, "\x00")
- To remove new lines from string:
strings.Trim(myString, "\r\n")
Friday, January 2, 2015
Go Channels Tips
- Read from an unbuffered channel:
blocks (use select).
- Write to an unbuffered channel:
blocks.
- Read from a buffered channel:
blocks (use select).
- Write to an buffered channel:
non blocking as long as there is space left in the buffer.
- Read from a closed channel:
non blocking, always return the zero value of the channel type.
- Write to a closed channel:
panic: runtime error: send on closed channel
- Read from a nil channel:
blocks forever.
- Write to a nil channel:
blocks forever.
blocks (use select).
- Write to an unbuffered channel:
blocks.
- Read from a buffered channel:
blocks (use select).
- Write to an buffered channel:
non blocking as long as there is space left in the buffer.
- Read from a closed channel:
non blocking, always return the zero value of the channel type.
- Write to a closed channel:
panic: runtime error: send on closed channel
- Read from a nil channel:
blocks forever.
- Write to a nil channel:
blocks forever.
Subscribe to:
Posts (Atom)