My Go playground while learning Go. 🧑🚒
so be cautious that the codes is not sophisticated and may not follow the best practice.
Run playground simply by go test
: 🚀
go test ./...
nil_empty_playground.go
|nil_empty_playground_test.go
- check the behavior of
nil
/empty slice - check the behavior of
nil
/empty map- put new elements into nil map, PANIC!
- check the behavior of
nil
function/lambda- call nil function/lambda, PANIC!
- check the behavior of
string_playground.go
|string_playground_test.go
- check the difference between
len
andrune count
of string - conversion of
string
<=>[]rune
rune
=>string
string
<=>[]byte
byte
=>string
[]rune
<=>[]byte
- string iteration
for-range
loop iteration return RUNE value with BYTE index, NOT return byte value,
make mistakes very easily, need caution!- iterate with byte index only of string by
for-range
loop, lose bytes! NONSENSE!!
- check memory struct of string by
SizeOf
- check the difference between
goroutine_channel_playground.go
|goroutine_channel_playground_test.go
- read channel by
for-range
loop, very convenient - read channel by
comma-ok
pattern, more tedious but safe too
- read channel by
goroutine_channel_pattern_playground.go
|goroutine_channel_pattern_playground_test.go
- operation(read/write) to multiply channels with
select statement
avoid starvation/deadlock done channel pattern
aka. a channel only used to publish close eventcancel function pattern
to terminate a goroutinenilify the case channel pattern
to turning off a case in a selecttime after case pattern
to time out code
- operation(read/write) to multiply channels with
when_go_runtime_panic_playground.go
|when_go_runtime_panic_playground_test.go
array operation
panicslice operation
panicchannel operation
panicfunction value operation
, call nil function value panic- call
value receiver method
with nil point receiver panic - call
method of nil interface
panic - call
method of interface with nil value
panic pointer operation
, dereference a nil pointer panictype assertions
panic
commons.go
- in my personal opinion,
type voidT = struct{}
andvar void = voidT{}
definitions seems interesting and COOL
- in my personal opinion,