This is a small utility which can be used to convert text into morse code and vice versa.
This utility was built as my first usage of the Go programming language and was an opportunity to understand some of its key concepts and commonly used practices such as:
- Range
- Slices
- Maps
- Function passing
- Command line parameter parsing
- Regular expressions and capture groups
I wanted to do all this by only using what is available in the Go standard library even
though there are no doubt numerous other packages available. Its also worth pointing out that a 3rd party library
gSpera/morse already exists to do text/morse transformations - however - by building
the utility it was an opportunity to understand some of Go's range
, slice
and map
operations.
You can run the associated tests with:
go test morse
You can run go run main.go -h
to get help on how to use the utility
Run
go run main.go morse --text "Hello World"
Which will return:
.... . .-.. .-.. --- / .-- --- .-. .-.. -..
Run
go run main.go text --morse ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."
Which will return:
HELLO WORLD
- The Go
regex
library does not support named capture groups at present and is discussed under #64108. Only a single repeating capture group was required for this so not being able to name it was not a serious issue. - The
flag
library is a little clunky - especially for sub-command processing.
- A zsh shell
- JetBrains GoLand IDE