Documentation
¶
Index ¶
- Constants
- Variables
- func AndWhere(wheres []string) string
- func ArrGet[T any](arr []T, idx []int) (ret []T)
- func Avg[T int | float32 | float64](arr []T) (ret T)
- func Bind(ctx echo.Context, a any) error
- func CamelToSnake(s string) string
- func CheckHeaderEqual(ctx echo.Context, header, value string) bool
- func CloseToPlaceholderLimit(cnt, stride int) int
- func CollectBy[T any, R int | string](arr []T, fn func(T) R) (ret map[R]T)
- func ContainInt(sl []int, elem int) bool
- func Contains[T any](a T, b []T) bool
- func ContainsAll[T any](a, b []T) bool
- func ContainsAny[T any](a, b []T) bool
- func ContainsBy[T any](a T, b []T, fn func(a, b T) bool) bool
- func DBArrayValues[T any](array []T) string
- func DateFromToday(daysOffset int, tz TZ) time.Time
- func DateFromTodayUTC(offset int) time.Time
- func DateUTC(y, m, d int) time.Time
- func DateUTCFromTime(t time.Time) time.Time
- func Dates(startDate, endDate time.Time) (ret []time.Time)
- func DatesBetweenIncl(a, b time.Time) (ret []time.Time)
- func DatesFromToday(start, end int, tz TZ) (ret []time.Time)
- func Dedup[T any](arr []T) (ret []T)
- func EQx[T any](name string, v T) string
- func EitherRunner(tx *sqlx.Tx, db *sqlx.DB) squirrel.BaseRunner
- func EndOfDay(a time.Time) time.Time
- func EndOfMonth(a time.Time) time.Time
- func EndOfMonthOrYesterday(a time.Time) time.Time
- func EndOfWeek(a time.Time) time.Time
- func EndOfWeekOrYesterday(a time.Time) time.Time
- func ErrBadRequest(msg string) error
- func ErrForbidden(msg string) error
- func ErrInternal(msg string) error
- func ErrUnauthorized(msg string) error
- func Except[T any](base, except []T) (ret []T)
- func ExtractDBTags(input any) (tags []string, vals []any)
- func ExtractTags(input any, tagName string) (tags []string, vals []any)
- func Filter[T any](arr []T, filterFunc func(t T) bool) (ret []T)
- func FilterMap[T, R any](arr []T, fn func(t T) (R, bool)) (ret []R)
- func Filterm[K comparable, V any](m map[K]V, fn func(k K, v V) bool) (ret map[K]V)
- func FindAll[T any](arr []T, fn func(T) bool) (ret []T)
- func FindOne[T any](arr []T, fn func(T) bool) (ret T)
- func FirstN[T any](arr []T, n int) (ret []T)
- func FlatMap[T, R any](arr []T, fn func(T) []R) (ret []R)
- func Flatten[T any](arr [][]T) (ret []T)
- func ForEach[T any](arr []T, sideEffectFunc func(t T))
- func FromAnys[T any](arr []any) []T
- func GetID[T int | string](ctx echo.Context) (t T, err error)
- func GetIDsByComma[T int | string](ctx echo.Context) (ret []T, err error)
- func GetParam[T int | string](ctx echo.Context, name string) (t T, err error)
- func GetPayload[T any](ctx echo.Context) (t T, err error)
- func GetPayloads[T any](ctx echo.Context) (t []T, err error)
- func GetQuery[T int | string | bool](ctx echo.Context, name string) (t T, err error)
- func GetUniqueDirPath(dir string) string
- func HasIntersect[T any](base []T, another []T, emptyTrue bool) bool
- func Head[T any, K comparable](arr []T) (ret T)
- func HrBtw(t time.Time, min, max int) bool
- func INx[T any](name string, ins []T) string
- func In[T any](in T, space []T) bool
- func InBracket(s, left, right string) bool
- func IndexOf[T any](arr []T, equalFunc func(t T) bool) int
- func IndexesExcept[T any](sub, super []T) (ret []int)
- func IndexesOf[T any](sub, super []T) (ret []int, valid bool)
- func Intersect[T string | int | float64](a, b []T) (ret []T)
- func IsLastDayOfMonth(a time.Time) bool
- func IsStartOfMonth(a time.Time) bool
- func JoinByComma[T any](t []T) string
- func Last[T any](arr []T) (ret T)
- func LastDayOfTheMonth(date time.Time) time.Time
- func LastDayOfTheWeek(date time.Time) time.Time
- func LastMonth() time.Time
- func LastN[T any](arr []T, n int) (ret []T)
- func Map[T, R any](arr []T, mapFunc func(t T) R) (ret []R)
- func MapE[T, R any](arr []T, mapFunc func(t T) (R, error)) (ret []R, err error)
- func MapIf[T, R any](arr []T, fn func(T) R, pred func(T) bool) (ret []R)
- func MapInPlace[T any](arr []T, mapFunc func(t T) T)
- func MapInPlaceE[T any](arr []T, mapFunc func(t T) (T, error)) (err error)
- func Mapm[K comparable, V, O any](m map[K]V, fn func(k K, v V) O) (ret []O)
- func Max[T int | float32 | float64](a, b T) T
- func MaxBy[T any, R int | float64](arr []T, maxBy func(t T) R) (max R)
- func MaxDayInMonth(month int) (day int)
- func MaxTime(a, b time.Time) time.Time
- func Min[T int | float32 | float64 | uint64](a, b T) T
- func MinTime(a, b time.Time) time.Time
- func MonthFromToday(monthOffset int) time.Time
- func MonthsFromToday(start, end int) (ret []time.Time)
- func MultipleJsonbSet(fieldName string, setMap map[string]any) (ret string)
- func MustTime(str string) time.Time
- func NewLogger(from string) zerolog.Logger
- func NewLoggerWithLevel(from string, minLevel zerolog.Level) zerolog.Logger
- func NewRand() *rand.Rand
- func NotNullCount(ts ...interface{}) int
- func NowByTZ(tz TZ) time.Time
- func OkJSON(ctx echo.Context, data any) error
- func OneOf[T any](t T, arr []T) bool
- func OrDefault(value string, defaultValue string) string
- func Paginate[T any](arr []T, page Page) []T
- func Panic(err error)
- func ParamInt(ctx echo.Context, name string) (int, error)
- func ParseDBArray[T any](repr string) (ret []T, err error)
- func ParseJSONToStruct(src interface{}, dest interface{}) error
- func ParseTime(s string) (ret time.Time, err error)
- func Partition[T int | string](partitionTableName string, fullTableName string, partitionValue T) (res string)
- func PartitionTruncate(t time.Time, timeLevel AggLevel) time.Time
- func PickRandom[T any](choices []T) (ret T)
- func PostJSON[REQ, RESP any](req REQ, url string) (ret RESP, err error)
- func PostJSONWH[REQ, RESP any](req REQ, url string, extraHeader map[string]string) (ret RESP, err error)
- func Print(obj ...any)
- func RM(t time.Time) time.Time
- func RandInDayStr(dateStr string) time.Time
- func Random[T any](arr []T) T
- func RandomAlphabets(l int, lowerCase bool) string
- func RandomAlphanumeric(l int, lowerCase bool) string
- func RandomBool() bool
- func RandomFloat64(low float64, high float64) float64
- func RandomInt(low int, high int) int
- func RandomIntBetween(min, max int) int
- func RandomMomentInADay(t time.Time) time.Time
- func RandomString(low int, high int) (ret string)
- func RandomizeTime(t time.Time, parts string) time.Time
- func Range(start, end int) (ret []int)
- func ReadCSVFile(filename string) (map[string][]string, error)
- func RespCSV(ctx echo.Context, err error, csv string) error
- func RespJSON(ctx echo.Context, err error, payload any) error
- func RespNoContent(ctx echo.Context, err error) error
- func SameDate(a, b time.Time) bool
- func SelectStr(cols ...string) string
- func SetDifference[T comparable](a, b map[T]bool) (ret map[T]bool)
- func SetIntersect[T comparable](a, b map[T]bool) (ret map[T]bool)
- func SetValues[T comparable](a map[T]bool) (ret []T)
- func Shuffle[T any](arr []T)
- func SimpleFloatEqual(a, b, epsilon float64) bool
- func SliceEqual[T any](a, b []T) bool
- func SortAsStr[T any](arr []T) []T
- func SortTime(ts []time.Time)
- func StartOfDay(a time.Time) time.Time
- func StartOfMonth(a time.Time) time.Time
- func StartOfPrevMonth(a time.Time) time.Time
- func StartOfWeek(a time.Time) time.Time
- func StructDataType(s interface{}) []string
- func StructTags(s interface{}, tagName string, except map[string]any) (ret []string)
- func Sum[T int | float32 | float64](arr []T) (ret T)
- func Tail[T any](arr []T) (ret T)
- func TimeByTz(t time.Time, tz TZ) time.Time
- func TimeEqual(a, b time.Time) bool
- func TimeIncr(t time.Time, aggLevel AggLevel) (time.Time, error)
- func TimePointsFiller(ids []string, pts []time.Time) string
- func Timestamp(y, m, d, h, min, s int) time.Time
- func ToAnys[T any](arr []T) []any
- func ToDate(t time.Time) time.Time
- func ToDateUTC(t time.Time) time.Time
- func ToFloat64(x any) (val float64, err error)
- func ToMap[T comparable](arr []T) (ret map[T]bool)
- func ToMid(handler echo.HandlerFunc) echo.MiddlewareFunc
- func ToPqStrArray[T any](arr []T) (ret pq.StringArray)
- func ToStr[T any](a T) string
- func Truncate(t time.Time, timeLevel AggLevel) time.Time
- func Unique[T any](arr []T) (ret []T)
- func UniqueBy[T any](arr []T, fn func(T) string) (ret []T)
- func UniqueOf[T, R any](arr []T, fn func(T) R) (ret []R)
- func UpdateClause(headers, pks []string, mergeStrategy map[string]string) string
- func UpsertQuery(cols []string) string
- func ValueList[T any](arr []T, label string, withOrder bool) string
- func ValueListTable[T any](arr []T, label string) string
- func YesterdayByTZ(tz TZ) time.Time
- func YesterdayOf(t time.Time) time.Time
- type AggLevel
- type Checkable
- type CustomValidator
- type Decimal
- type Err
- type InsertHelper
- type Obj
- type Page
- type PaginatedResult
- type ReqCtx
- type RequestCfg
- type StrMap
- type TZ
- type TsPoint
- type TsPoints
- type TsRange
Constants ¶
const PostgresPlaceholderLimit = 65535
Variables ¶
var ( ErrNotBytes = errors.New("error not bytes") ErrCannotDeleteModelWithInvPurpose = errors.New("cannot delete model with inv purpose") )
var DBTimestamptzFormat = "2006-01-02 15:04:05Z07"
var DateFormat = time.DateOnly
var DefaultLoggingLevel = zerolog.InfoLevel
var LOG = NewLogger("default")
var NoPagination = Page{Off: true}
var Psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
var TimestamptzFormat = time.RFC3339
var Validator = validator.New()
Functions ¶
func CamelToSnake ¶
func CheckHeaderEqual ¶
func CloseToPlaceholderLimit ¶
func ContainInt ¶
func Contains ¶
check if b has at least one of element in a equality is simply by converting the type to string
func ContainsAny ¶
whether at least one of the elements in a is present in b
func ContainsBy ¶
func DBArrayValues ¶
func DateFromTodayUTC ¶
func EitherRunner ¶
func ErrBadRequest ¶
func ErrForbidden ¶
func ErrInternal ¶
func ErrUnauthorized ¶
func Except ¶
func Except[T any](base, except []T) (ret []T)
remove all items find in `except` from `base`, naive implementation with string equality
func ExtractDBTags ¶
func Filterm ¶
func Filterm[K comparable, V any](m map[K]V, fn func(k K, v V) bool) (ret map[K]V)
func GetIDsByComma ¶ added in v0.1.5
func GetPayload ¶
GetPayload takes care of marshaling the payload from request 1) if the payload was never read before, then it read the payload, and it saves within the context 2) if the payload has already been read, then it read directly from the context can only work if the http verb is NOT [GET DELETE HEAD] for payload in body
func GetPayloads ¶
func GetUniqueDirPath ¶
func HasIntersect ¶
HasIntersect check if another slices has at least one element in the base slice equality check is done by converting element to string
func Head ¶
func Head[T any, K comparable](arr []T) (ret T)
func IndexesExcept ¶
func IsLastDayOfMonth ¶
func IsStartOfMonth ¶
func JoinByComma ¶
func MapInPlace ¶
func MapInPlace[T any](arr []T, mapFunc func(t T) T)
func MapInPlaceE ¶
func Mapm ¶
func Mapm[K comparable, V, O any](m map[K]V, fn func(k K, v V) O) (ret []O)
func MaxDayInMonth ¶
func MonthFromToday ¶
func MonthsFromToday ¶
func NewLoggerWithLevel ¶
func NotNullCount ¶
func NotNullCount(ts ...interface{}) int
func ParseDBArray ¶
ParseDBArray supported type is based on the needed usecases (number, time, etc)
func ParseJSONToStruct ¶
func ParseJSONToStruct(src interface{}, dest interface{}) error
func PickRandom ¶
func PickRandom[T any](choices []T) (ret T)
func PostJSONWH ¶ added in v0.1.3
func RandInDayStr ¶
func RandomAlphabets ¶
func RandomAlphanumeric ¶
func RandomBool ¶
func RandomBool() bool
func RandomFloat64 ¶
func RandomIntBetween ¶
func RandomString ¶
func RespNoContent ¶
func SetDifference ¶
func SetDifference[T comparable](a, b map[T]bool) (ret map[T]bool)
func SetIntersect ¶
func SetIntersect[T comparable](a, b map[T]bool) (ret map[T]bool)
func SetValues ¶
func SetValues[T comparable](a map[T]bool) (ret []T)
func SimpleFloatEqual ¶
can use relative tolerance, but for now absolute tolerance is sufficient
func SliceEqual ¶
func StructDataType ¶
func StructDataType(s interface{}) []string
func StructTags ¶
func ToMap ¶
func ToMap[T comparable](arr []T) (ret map[T]bool)
func ToMid ¶
func ToMid(handler echo.HandlerFunc) echo.MiddlewareFunc
ToMid means ToMIddleware convert HandlerFunc to one type of middleware, next() is at the bottom
func ToPqStrArray ¶
func ToPqStrArray[T any](arr []T) (ret pq.StringArray)
func UpdateClause ¶
func UpsertQuery ¶
func ValueListTable ¶
func YesterdayByTZ ¶
Types ¶
type CustomValidator ¶
type Decimal ¶ added in v0.1.3
func NewDecimal ¶ added in v0.1.3
func NewDecimalF ¶ added in v0.1.3
func (Decimal) MarshalJSON ¶ added in v0.1.3
func (*Decimal) UnmarshalJSON ¶ added in v0.1.3
type Err ¶
func ErrNotFound ¶ added in v0.1.4
type InsertHelper ¶
type InsertHelper struct {
// contains filtered or unexported fields
}
func NewInsertHelper ¶
func (*InsertHelper) Add ¶
func (ih *InsertHelper) Add(args []any) (err error)
func (*InsertHelper) Finish ¶
func (ih *InsertHelper) Finish() (err error)
type Page ¶
func GetPagination ¶
type PaginatedResult ¶
type ReqCtx ¶
type ReqCtx struct { Req *http.Request Resp *httptest.ResponseRecorder Ctx echo.Context }
func NewHttpTestKit ¶
func NewHttpTestKit(engine *echo.Echo, r RequestCfg) ReqCtx