https://github.com/sourcegraph/beaut
https://github.com/sourcegraph/beaut
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sourcegraph/beaut
- Owner: sourcegraph
- License: apache-2.0
- Created: 2024-06-10T12:12:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-11T01:30:30.000Z (over 1 year ago)
- Last Synced: 2025-09-30T07:34:36.349Z (4 months ago)
- Language: Go
- Size: 15.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# beaut: Convenient handling for validated types
[](https://pkg.go.dev/github.com/sourcegraph/beaut)
[](https://sourcegraph.com/github.com/sourcegraph/beaut)
In certain situations, you've already done some validation
on a type. For example, you may have checked that a path
is an absolute path, or that a string is valid UTF-8.
However, since there is no standard library support for
representing such types, maybe you continue passing that
value around as a `string` or a `[]byte`. This has a few downsides:
- Reduced dev velocity: It is not clear to the reader
which operations are safe to perform, and editing the code
becomes harder as it is unclear which invariants must be upheld.
- Poor debugging experience: Failures may appear much further downstream
in case validation was not done on all code paths.
- Performance cost: Out of defensiveness, different parts of the
code may perform the same validation redundantly.
Following the [Parse, Don't Validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)
mantra, it is useful to have a dedicated type to represent
the validation, so that it is clearer to the reader which
operations are safe to perform and which operations require
extra care.
This library exposes a few types such as `UTF8String`, `UTF8Bytes`,
`AbsolutePath` and `RelativePath` to represent common validations.