Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iang/morse
Simple go utility to convert from text to morse code and vice versa
https://github.com/iang/morse
Last synced: 2 days ago
JSON representation
Simple go utility to convert from text to morse code and vice versa
- Host: GitHub
- URL: https://github.com/iang/morse
- Owner: IanG
- Created: 2024-05-01T16:03:03.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-03T10:54:21.000Z (9 months ago)
- Last Synced: 2024-11-30T11:08:48.437Z (2 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Morse
## Introduction
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](https://go.dev/) 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 groupsI wanted to do all this by only using what is available in the [Go standard library](https://pkg.go.dev/std) even
though there are no doubt numerous other packages available. Its also worth pointing out that a 3rd party library
[gSpera/morse](https://github.com/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.## Tests
You can run the associated tests with:
`go test morse`
## Usage
You can run `go run main.go -h` to get help on how to use the utility
### Convert Text To Morse Code
Run`go run main.go morse --text "Hello World"`
Which will return:
`.... . .-.. .-.. --- / .-- --- .-. .-.. -..`
### Convert Morse Code To Text
Run
`go run main.go text --morse ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."`Which will return:
`HELLO WORLD`
## Observations
- The Go `regex` library does not support named capture groups at present and is discussed under
[#64108](https://github.com/golang/go/issues/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.## Tools used
- A zsh shell
- [JetBrains GoLand IDE](https://www.jetbrains.com/go/)