Documentation
¶
Index ¶
- Variables
- func All[T any](source []T, predicate func(T) bool) bool
- func Any[T any](source []T, predicate func(T) bool) bool
- func BigFloatToNumeric(f *big.Float) (pgtype.Numeric, error)
- func BindAndValidate(c echo.Context, i interface{}) error
- func BlueMsg(s string) string
- func CalculatePrice(sqrtPriceX96 *big.Int, token0Decimals, token1Decimals int32, token0IsUSD bool) *big.Float
- func ColorMethod(method string) string
- func Concat[T any](first []T, other ...[]T) []T
- func ConvertDecimalsToWei(num *pgtype.Numeric) (*big.Int, error)
- func ConvertFloat8ToDecimals(num pgtype.Float8, decimals uint64) (*big.Int, error)
- func ConvertNumericToDecimals(num *pgtype.Numeric, decimals uint8) (*big.Int, error)
- func Distinct[T comparable](source []T) []T
- func Expand[T any](generator func(idx int) T, count int) []T
- func Expand2[T any](generator func() T, count int) []T
- func Filter[T any](source []T, predicate func(T) bool) []T
- func FlatMap[T, S any](source []T, f func(T) []S) []S
- func Flatten[T any](source [][]T) []T
- func ForEach[T any](source []T, f func(T))
- func GetFunctionName(f interface{}) string
- func GroupBy[T any, K comparable](source []T, fn func(T) K) map[K][]T
- func HasDuplicates[T comparable](source []T) bool
- func HexToAddress(address string) (common.Address, error)
- func HttpErrorHandler(err error, c echo.Context)
- func IsHex(hex string) bool
- func IsHexAddress(address string) bool
- func Last[T any](source []T) T
- func Logf(foreground ForegroundColor, v ...interface{}) string
- func MagentaMsg(s string) string
- func Map[T, S any](source []T, f func(T) S) []S
- func NormalizeAddress(address string) string
- func NormalizeHex(h string) ([]byte, error)
- func RandomNumber(n int) (string, error)
- func RandomString(n int) (string, error)
- func Recover(module string, event interface{}, message string)
- func Reduce[T, S any](source []T, initial S, f func(current S, element T) S) S
- func Request(opts *RequestOption) (*http.Request, *httptest.ResponseRecorder)
- func RequestLogMiddleware() echo.MiddlewareFunc
- func Reverse[T1 any](source []T1) []T1
- func SafeExecute(ctx context.Context, fn func() error) (err error)
- func ScanBoolValue(value string) (*pgtype.Bool, error)
- func ScanNumericValue(value string) (*pgtype.Numeric, error)
- func ScanStringValue(value string) (*pgtype.Text, error)
- func ToMap[T1 any, T2 comparable](source []T1, lookup func(T1) T2, strictUniqueness ...bool) map[T2]T1
- func TryCast[T1 any, T2 any](source []T1) []T2
- func While[T any](source []T, f func(T) bool)
- func YellowMsg(s string) string
- type CustomValidator
- type ErrResponse
- type ForegroundColor
- type ListPublicResponse
- type RequestOption
- type ValidationError
- type ValidationRule
Constants ¶
This section is empty.
Variables ¶
Pre-calculate 2^96 as a big.Float for better precision
Functions ¶
func BigFloatToNumeric ¶
BigFloatToNumeric converts a big.Float to pgtype.Numeric preserving full precision including decimals
func BindAndValidate ¶
func CalculatePrice ¶
func CalculatePrice(sqrtPriceX96 *big.Int, token0Decimals, token1Decimals int32, token0IsUSD bool) *big.Float
CalculatePrice converts sqrtPriceX96 to a price with proper decimal adjustments
func ColorMethod ¶
func ConvertFloat8ToDecimals ¶
func Distinct ¶
func Distinct[T comparable](source []T) []T
Distinct returns a new slice where duplicate entries are removed
func FlatMap ¶
func FlatMap[T, S any](source []T, f func(T) []S) []S
FlatMap composes Map and Flatten
func Flatten ¶
func Flatten[T any](source [][]T) []T
Flatten flattens a slice of slices into a single slice
func ForEach ¶
func ForEach[T any](source []T, f func(T))
ForEach performs the given function on every element of the slice
func GetFunctionName ¶
func GetFunctionName(f interface{}) string
func GroupBy ¶
func GroupBy[T any, K comparable](source []T, fn func(T) K) map[K][]T
GroupBy returns a map with given items each group into a slice
func HasDuplicates ¶
func HasDuplicates[T comparable](source []T) bool
HasDuplicates returns true if a slice has duplicate entries, false otherwise.
func HttpErrorHandler ¶
func IsHexAddress ¶
func Last ¶
func Last[T any](source []T) T
Last returns the last element of a slice, panics if the slice is empty
func Logf ¶
func Logf(foreground ForegroundColor, v ...interface{}) string
func MagentaMsg ¶
func NormalizeAddress ¶
func NormalizeHex ¶
func RandomNumber ¶
func RandomString ¶
func Reduce ¶
func Reduce[T, S any](source []T, initial S, f func(current S, element T) S) S
Reduce performs a reduction to a single value of the source slice according to the given function
func Request ¶
func Request(opts *RequestOption) (*http.Request, *httptest.ResponseRecorder)
func RequestLogMiddleware ¶
func RequestLogMiddleware() echo.MiddlewareFunc
func Reverse ¶
func Reverse[T1 any](source []T1) []T1
Reverse returns a new slice in which the elements aree listed in reverse order
func SafeExecute ¶
SafeExecute runs a function with panic recovery Returns any error from the function or from a panic
func ScanNumericValue ¶
ScanValue is a generic function that converts a string value to a pgtype type
func ToMap ¶
func ToMap[T1 any, T2 comparable](source []T1, lookup func(T1) T2, strictUniqueness ...bool) map[T2]T1
ToMap returns a map from the given slice with keys associated by the lookup function. Panics if strictUniqueness is set, otherwise overrides values for colliding keys.
func TryCast ¶
TryCast tries to cast each element of the slice from type T1 to type T2. Elements get filtered out of the cast is unsuccessful.
Types ¶
type CustomValidator ¶
type CustomValidator struct {
// contains filtered or unexported fields
}
CustomValidator is type setting of third party validator
func (*CustomValidator) AddRules ¶
func (cv *CustomValidator) AddRules(rules ...ValidationRule) error
func (*CustomValidator) Validate ¶
func (cv *CustomValidator) Validate(i interface{}) error
type ErrResponse ¶
type ErrResponse struct {
Message string `json:"message"`
Metadata interface{} `json:"metadata,omitempty"`
}
type ForegroundColor ¶
type ForegroundColor int
const ( Black ForegroundColor = 30 Red ForegroundColor = 31 Green ForegroundColor = 32 Yellow ForegroundColor = 33 Blue ForegroundColor = 34 Magenta ForegroundColor = 35 Cyan ForegroundColor = 36 White ForegroundColor = 37 )
type ListPublicResponse ¶
func NewListResult ¶
func NewListResult[T any](data T, total int64) *ListPublicResponse[T]
type RequestOption ¶
type ValidationError ¶
type ValidationError struct {
Message string `json:"message"`
Metadata map[string]interface{} `json:"metadata"`
}
func (ValidationError) Error ¶
func (ve ValidationError) Error() string