Documentation
¶
Index ¶
- func ComparePassword(hashedPassword, password string) bool
- func GenerateShaToken(value string) string
- func HashPassword(password string) (string, error)
- func MultiErrors(errs ...error) error
- func Ptr[T any](v T) *T
- func Round[T float32 | float64](value T, precision int) T
- func UserIdFromContext(ctx context.Context) int
- func UserIdToContext(ctx context.Context, userId int) context.Context
- type ErrorList
- type HttpError
- type MultiError
- func (m *MultiError) Add(err error) bool
- func (m *MultiError) Err() error
- func (m *MultiError) Error() string
- func (m *MultiError) ErrorStrings() []string
- func (m *MultiError) Errors() (errs []error)
- func (m *MultiError) Is(err error) bool
- func (m *MultiError) Reset()
- func (m *MultiError) Unwrap() []error
- type MultiErrorer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComparePassword ¶
func GenerateShaToken ¶
func HashPassword ¶
func MultiErrors ¶
MultiErrors creates a MultiError and adds all errs to it and returns the resulting error.
func Round ¶
Round rounds a float to a specified precision. The precision argument is the number of decimal places to round to. For example, Round(1.2345, 2) returns 1.23. The value argument can be a float32 or float64. The return value is the rounded float to the T type.
func UserIdFromContext ¶
UserIdFromContext returns the user_id from the context.
Types ¶
type ErrorList ¶
type ErrorList []error
ErrorList is a JSON that can serialise a list of errors
func (*ErrorList) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (*ErrorList) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError is an error type which allows multiple errors to be added and returned as single error. This is useful in the case where errors aren't fatal, and you want the combination to be returned at a later date.
func (*MultiError) Add ¶
func (m *MultiError) Add(err error) bool
Add adds the given error if it's not nil and returns true, otherwise it returns false.
func (*MultiError) Err ¶
func (m *MultiError) Err() error
Err returns either: * nil - if no errors where added * the added error - if only one error was added * itself - otherwise
func (*MultiError) ErrorStrings ¶
func (m *MultiError) ErrorStrings() []string
ErrorStrings returns a string array of errors
func (*MultiError) Errors ¶
func (m *MultiError) Errors() (errs []error)
Errors returns a flattened list of all errors the MultiError contains
func (*MultiError) Is ¶
func (m *MultiError) Is(err error) bool
func (*MultiError) Unwrap ¶
func (m *MultiError) Unwrap() []error
Unwrap allows errors.Is to unwrap a MultiError's list of errors
type MultiErrorer ¶
type MultiErrorer interface {
Errors() []error
}
MultiErrorer is an interface that defines objects that returns multiple errors