|
|
|
|
|
by Mawr
1488 days ago
|
|
Great, except: 1. The type is merely a weak hint that you should check .Valid before you use the value, there's no enforcement: https://go.dev/play/p/nS8RxGujMBk It's much better when the struct members are private and the only way to access the value is through a method that returns (value, bool): if value, ok := optional.Get(); ok {
// value is valid
} else {
// value is invalid
}
This is a strong hint that you should check the bool before using the value. It's also a common go pattern - checking for existence of a key in a map is done this way.2. We have generics now. Why use type-and-sql-specific wrappers when you could use a generic Option? Example implementation: https://gist.github.com/MawrBF2/0a60da26f66b82ee87b98b03336e.... |
|