Documentation
¶
Index ¶
- Constants
- Variables
- func ChanReadAll[T any](ch <-chan T) []T
- func MaskStr(s string) string
- func MaskStrNotFirst(s string) string
- func MaskStrNotFirstLast(s string) string
- func Ternary[T any](condition bool, rTrue T, rFalse T) T
- type Email
- type ErrorAlreadyDone
- type ErrorNotFound
- type ErrorRuntime
- type ErrorUnprocessable
- type ErrorValidation
Constants ¶
const EmailLengthMax = 255
const EmailLengthMin = 8 // Min 2 chars for each part + "@" and "."
Variables ¶
var EmailNil = Email{}
Functions ¶
func ChanReadAll ¶
func ChanReadAll[T any](ch <-chan T) []T
func MaskStr ¶ added in v0.2.0
MaskStr
Examples:
- "" --> ""
- "s" --> "*"
- "Secret-codE" --> "***********"
func MaskStrNotFirst ¶ added in v0.2.0
MaskStrNotFirst
Examples:
- "" --> ""
- "s" --> "s"
- "Secret-codE" --> "S**********"
func MaskStrNotFirstLast ¶ added in v0.2.0
MaskStrNotFirstLast
Examples:
- "" --> ""
- "s" --> "s"
- "se" --> "se"
- "Secret-codE" --> "S*********E"
Types ¶
type Email ¶
type Email struct {
// contains filtered or unexported fields
}
func EmailFromStringMust ¶
type ErrorAlreadyDone ¶
type ErrorAlreadyDone struct {
// contains filtered or unexported fields
}
func NewErrorAlreadyDoneFf ¶
func NewErrorAlreadyDoneFf(msg string, msgArgs ...any) ErrorAlreadyDone
NewErrorAlreadyDoneFf
Panics in case of empty arguments:
- msg
func (ErrorAlreadyDone) Error ¶
func (e ErrorAlreadyDone) Error() string
type ErrorNotFound ¶
type ErrorNotFound struct {
// contains filtered or unexported fields
}
func NewErrorNotFoundFf ¶
func NewErrorNotFoundFf(msg string, msgArgs ...any) ErrorNotFound
NewErrorNotFoundFf
Panics in case of empty arguments:
- msg
func (ErrorNotFound) Error ¶
func (e ErrorNotFound) Error() string
type ErrorRuntime ¶
type ErrorRuntime struct {
// contains filtered or unexported fields
}
ErrorRuntime
Client code should be able to distinguish business-logic errors from others. Moreover, each type of business-logic error may be handled differently. Runtime errors are typically handled uniformly (e.g: logged, reported, translated into an HTTP 500 response).
Go does not allow us to mark business-logic errors and then check that mark in the client code in a simple way, like some other OOP languages do (e.g., through inheritance and try‑catch statements), but it allows to get the same result in another way -- by wrapping all non-business-logic errors into a specific error type.
I.e:
try { ... }
catch (BusinessLogicException) { /* ... */ }
catch (Exception) { /* any other error -- in this case non-business-logic */ }
-->
switch err.(type) {
case nil:
case std.ErrorRuntime: /* any other error -- in this case non-business-logic */
default: /* ... */
}
Usage example:
package example
func SomeFunc() error {
v, err := ...
if err != nil {
return std.WrapErrorToRuntime(err, "example", "SomeFunc")
}
...
}
type MyType struct { ... }
func (m *MyType) SomeMethod() (..., error) {
...
if err != nil {
return std.WrapErrorToRuntime(err, m, "SomeMethod")
}
...
}
See WrapErrorToRuntime.
func NewErrorRuntimeFf ¶
func NewErrorRuntimeFf(msg string, msgArgs ...any) ErrorRuntime
NewErrorRuntimeFf
Panics in case of empty arguments:
- msg
func WrapErrorToRuntime ¶
func WrapErrorToRuntime(err error, methodOwner any, methodName string, methodInfo ...string) ErrorRuntime
WrapErrorToRuntime
Adds this kind of prefix to the error to imitate stack trace: "{{`methodOwner`}}.{{`methodName`}}/{{joined by "/" elements of the `methodInfo`}}".
Panics in case of empty arguments:
- err
- methodOwner
- methodName
Arguments:
- `methodOwner` -- string or any method owner instance. {{`methodOwner`}} will be replaced by the string value or method owner instance type accordingly. String value is allowed, for example, to accept package names, when a regular function is called, not a method.
- `methodName` -- name of the method / function, that was called.
- `methodInfo` -- any additional info.
func (ErrorRuntime) Error ¶
func (e ErrorRuntime) Error() string
func (ErrorRuntime) Unwrap ¶
func (e ErrorRuntime) Unwrap() error
type ErrorUnprocessable ¶
type ErrorUnprocessable struct {
// contains filtered or unexported fields
}
func NewErrorUnprocessableFf ¶
func NewErrorUnprocessableFf(msg string, msgArgs ...any) ErrorUnprocessable
NewErrorUnprocessableFf
Panics in case of empty arguments:
- msg
func (ErrorUnprocessable) Error ¶
func (e ErrorUnprocessable) Error() string
type ErrorValidation ¶
type ErrorValidation struct {
// contains filtered or unexported fields
}
func NewErrorValidationFf ¶
func NewErrorValidationFf(msg string, msgArgs ...any) ErrorValidation
NewErrorValidationFf
Panics in case of empty arguments:
- msg
func (ErrorValidation) Error ¶
func (e ErrorValidation) Error() string