Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oldratlee/my-go-playground
đĻĢ my Go playground
https://github.com/oldratlee/my-go-playground
channel go goroutine panic playground rune slice string
Last synced: about 2 months ago
JSON representation
đĻĢ my Go playground
- Host: GitHub
- URL: https://github.com/oldratlee/my-go-playground
- Owner: oldratlee
- Created: 2023-01-20T14:01:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-30T11:20:51.000Z (almost 2 years ago)
- Last Synced: 2024-10-19T19:34:40.920Z (3 months ago)
- Topics: channel, go, goroutine, panic, playground, rune, slice, string
- Language: Go
- Homepage: https://github.com/oldratlee/my-go-playground
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# đĻĢ my Go playground
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`: đ
```sh
go test ./...
```## đ Playground List
- [`nil_empty_playground.go`](internal/nil_empty_playground.go) | [`nil_empty_playground_test.go`](internal/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!
- [`string_playground.go`](internal/string_playground.go) | [`string_playground_test.go`](internal/string_playground_test.go)
- check the difference between `len` and `rune 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`
- [`goroutine_channel_playground.go`](internal/goroutine_channel_playground.go) | [`goroutine_channel_playground_test.go`](internal/goroutine_channel_playground_test.go)
- read channel by `for-range` loop, very convenient
- read channel by `comma-ok` pattern, more tedious but safe too
- [`goroutine_channel_pattern_playground.go`](internal/goroutine_channel_pattern_playground.go) | [`goroutine_channel_pattern_playground_test.go`](internal/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 event
- `cancel function pattern` to terminate a goroutine
- `nilify the case channel pattern` to turning off a case in a select
- `time after case pattern` to time out code
- [`when_go_runtime_panic_playground.go`](internal/when_go_runtime_panic_playground.go) | [`when_go_runtime_panic_playground_test.go`](internal/when_go_runtime_panic_playground_test.go)
- `array operation` panic
- `slice operation` panic
- `channel operation` panic
- `function 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 panic
- `type assertions` panic## đ My common functions and go design experiments
- [`commons.go`](internal/commons.go)
- in my personal opinion,
`type voidT = struct{}` and `var void = voidT{}`
definitions seems interesting and COOL