utils

package
v0.0.0-...-44bbc5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(hashedPassword, password string) bool

func GenerateShaToken

func GenerateShaToken(value string) string

func HashPassword

func HashPassword(password string) (string, error)

func MultiErrors

func MultiErrors(errs ...error) error

MultiErrors creates a MultiError and adds all errs to it and returns the resulting error.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the value passed in.

func Round

func Round[T float32 | float64](value T, precision int) T

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.

Types

type ErrorList

type ErrorList []error

ErrorList is a JSON that can serialise a list of errors

func (*ErrorList) MarshalJSON

func (el *ErrorList) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*ErrorList) UnmarshalJSON

func (el *ErrorList) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type HttpError

type HttpError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func HttpErrorFromError

func HttpErrorFromError(err error) *HttpError

func NewHttpError

func NewHttpError(code int, message string) *HttpError

func (*HttpError) Error

func (e *HttpError) Error() string

func (*HttpError) Is

func (e *HttpError) Is(target error) bool

func (*HttpError) Unwrap

func (e *HttpError) Unwrap() error

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 NewMultiError

func NewMultiError() *MultiError

NewMultiError returns a usable MultiError

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) Error

func (m *MultiError) Error() string

Error implements the error interface

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) Reset

func (m *MultiError) Reset()

Reset clears any previously added errors.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL