https://github.com/frectonz/better-go
It's go but with try
https://github.com/frectonz/better-go
Last synced: 10 months ago
JSON representation
It's go but with try
- Host: GitHub
- URL: https://github.com/frectonz/better-go
- Owner: frectonz
- License: bsd-3-clause
- Created: 2024-04-03T16:52:27.000Z (about 2 years ago)
- Default Branch: second-try
- Last Pushed: 2024-04-18T19:15:56.000Z (about 2 years ago)
- Last Synced: 2025-04-10T23:51:22.824Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 347 MB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
# The Go Programming Language + `try` + `unwrap`
Go with slightly better error handling primitives.
Checkout the [demo](./demo) directory.
## `try`
try sugar
```golang
content, err := ioutil.ReadFile(filename)
try err or string
```
try desugared
```golang
...
if err != nil {
return make([]string, 1)[0], err
}
```
The try statement expects two values.
1. the error variable
2. the type of the return value (this is needed because go has this convention of returning the zero value of a type incase of an error)
## `unwrap`
unwrap sugar
```golang
fileContent, err := readFile("sample.txt")
unwrap err
```
unwrap desugared
```golang
...
if err != nil {
panic(err)
}
```
The unwrap statement expects one value, the error variable.
## `bababooey`
just like `try` but this doesn't need a type
```golang
content, err := ioutil.ReadFile(filename)
bababooey err
```
bababooey desugared
```golang
...
if err != nil {
return nil, err
}
```
The bababooey statement expects one value, the error variable.
## `<<<`
sugar for `append`
```golang
numbers := []int{1, 2, 3}
numbers = append(numbers, 4)
```
append desugared
```golang
numbers := []uint{1, 2, 3}
@numbers <<< 4
```
# How to run it
```
nix develop
cd src
./make.bash
```