Documentation ¶
Index ¶
- Constants
- func AppendFile(data []byte, filePath string, mode int) error
- func ArrayInt64ToString(a []int64, delim string) string
- func ArrayIntToString(a []int, delim string) string
- func ArrayJsonNumberToString(a []json.Number, delim string) string
- func ArrayStringToString(a []string, delim string) string
- func BitwiseToString(bitwise int64) string
- func ClearCurrentFolder(dirPath string) error
- func ClearFile(files ...string) error
- func CopyFile(srcPath, dstPath string) error
- func CreateFilePath(filePath string) error
- func DecodeModel(input map[string]interface{}, result interface{}) error
- func Distinct[T string | int32 | int64 | float32 | float64](list []T) []T
- func DistinctStr(str string, delim string) string
- func DoubleSlice(s interface{}) []interface{}
- func Find[T any](list []T, f func(T) bool) T
- func FormatUnixToString(d int64, format DateTime) string
- func GetFromInterface(src map[string]interface{}, key string, defaultValue interface{}) interface{}
- func GetFromInterfaceV2[T any](src map[string]interface{}, key string, defaultValue T) T
- func GetFromInterfaceV3[T any](src map[string]interface{}, key string, defaultValue T, checkZeroValue ...bool) T
- func GetGormQuery(query *gorm.DB, params map[string]interface{})
- func GetHasMore(currentPage int, totalCount int, pageSize int) bool
- func GetScopePagination(value interface{}, pagination *Pagination, query *gorm.DB) func(db *gorm.DB) *gorm.DB
- func GetTotalPages(totalCount int, pageSize int) int
- func HttpClient() *http.Client
- func IndexOf[T any](list []T, f func(T) bool) int
- func IsZero(p interface{}) bool
- func MapQuantityFromTo(condition int64, res map[string]interface{}, key string) map[string]interface{}
- func Parse[T parsable](in interface{}) (out T, err error)
- func Pop[T any](list []T) (T, []T)
- func PrettyPrint(v interface{}) string
- func RemoveAt[T any](list []T, i int) []T
- func SendRequest(client *http.Client, headers map[string]string, endpoint, method string, ...) ([]byte, error)
- func Shift[T any](list []T) (T, []T)
- func Slug(s string) string
- func StringToArrayInt(str, delim string) []int
- func StringToArrayInt64(str string, delim string) []int64
- func StringToArrayString(str, delim string, trim bool) []string
- func StringToBitwiseInt64(str string) int64
- func TimeToString(t time.Time) string
- func ToPointer[T any](i T) *T
- func UnixTime(d int64) time.Time
- func Unshift[T any](list []T, x T) []T
- func ValidateEmail(email string) bool
- func ValidateStruct(s interface{}) error
- func ValidateStructCtx(ctx context.Context, s interface{}) error
- func Where[T any](list []T, f func(T) bool) []T
- func WriteFile(data []byte, filePath string) error
- func ZZip(folder string, files ...string) error
- func ZipMultipleFile(outputFile string, sourceFiles ...string) error
- func ZipSingleFile(sourceFile, outputFile string) error
- type DateTime
- type Pagination
- type PaginationQuery
- func (q *PaginationQuery) GetLimit() int
- func (q *PaginationQuery) GetOffset() int
- func (q *PaginationQuery) GetOrderBy() string
- func (q *PaginationQuery) GetPage() int
- func (q *PaginationQuery) GetQueryString() string
- func (q *PaginationQuery) GetSize() int
- func (q *PaginationQuery) SetOrderBy(orderByQuery string)
- func (q *PaginationQuery) SetPage(pageQuery string) error
- func (q *PaginationQuery) SetSize(sizeQuery string) error
Constants ¶
const ( LESS_THAN_ZERO int32 = iota + 1 EQUAL_ZERO EQUAL_ONE GREATER_THAN_ZERO GREATER_THAN_ONE GREATER_THAN_TWO GREATER_THAN_THREE GREATER_THAN_FOUR GREATER_THAN_TEN ZERO_TO_TEN ZERO_TO_TWENTY TEN_TO_TWENTY TWENTY_TO_FIFTY ZERO_TO_FIFTY ZERO_TO_HUNDRED GREATER_THAN_FIFTY GREATER_THAN_TWENTY GREATER_THAN_HUNDRED )
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶
Append to a file. Create if not exist, or append to existing file.
Mode: - 0: Before - 1: After Example: - AppendFile([]byte("Hello World"), "temp/output.txt", 2)
func ArrayInt64ToString ¶
func ArrayIntToString ¶
func ArrayStringToString ¶
func BitwiseToString ¶
func ClearCurrentFolder ¶
Clear folder removes current directory.
func CreateFilePath ¶
func DecodeModel ¶
func Distinct ¶
Distinct function remove duplicates from slice. Distinct return a new slice.
Example: newList := Distinct(oldList)
func DistinctStr ¶
func DoubleSlice ¶
func DoubleSlice(s interface{}) []interface{}
Deal with variadic functions in Go.
func Find ¶
Find function find first element based on conditions. Find return a new value T.
Example: item := Find(list, func(n name) bool {return n == "ABC"})
func FormatUnixToString ¶
func GetFromInterface ¶
Get value from interface. Return default value if key not exists or key exists with zero value.
func GetFromInterfaceV2 ¶
Get value from interface. Return default value if key not exists or key exists with zero value.
func GetFromInterfaceV3 ¶
func GetFromInterfaceV3[T any](src map[string]interface{}, key string, defaultValue T, checkZeroValue ...bool) T
Get value from interface. Return default value if key not exists or key exists with zero value (optional).
NOTE: when checkZeroValue is true, it will check if the value is zero value. When checkZeroValue is false, it only check if the key exists.
func GetGormQuery ¶
func GetScopePagination ¶
func HttpClient ¶
func IndexOf ¶
IndexOf returns the index of the first element that satisfies the condition.
Example: index := IndexOf(list, func(n name) bool {return n == "ABC"})
func IsZero ¶
func IsZero(p interface{}) bool
Detect whether a value is the zero value for its type.
func MapQuantityFromTo ¶
func Parse ¶
func Parse[T parsable](in interface{}) (out T, err error)
Number to String OR String to Number
func Pop ¶
func Pop[T any](list []T) (T, []T)
Pop removes the last element. Pop returns new slice and that element.
Example: x, a := Pop(items)
func RemoveAt ¶
RemoveAt removes the element based on index. RemoveAt returns new slice.
Example: a := RemoveAt(items, 1)
func SendRequest ¶
func Shift ¶
func Shift[T any](list []T) (T, []T)
Shift removes the first element. Shift returns new slice and that element.
Example: x, a := Shift(items)
func StringToArrayInt ¶
func StringToArrayInt64 ¶
func StringToArrayString ¶
func StringToBitwiseInt64 ¶
func TimeToString ¶
func Unshift ¶
func Unshift[T any](list []T, x T) []T
Unshift adds the specified elements to the beginning. Unshift returns new slice.
Example: items := Unshift(items, a)
func ValidateStructCtx ¶
Validate struct fields
func Where ¶
Where function filter elements based on conditions. Where return a new slice.
Example: evens := Filter(list, func(i int) bool {return i % 2 == 0})
func WriteFile ¶
Write to a file. Create if not exist, or overwrite the existing file.
Example: WriteFile([]byte("Hello World"), "temp/output.txt")
func ZipMultipleFile ¶
ZipMultipleFile zip list of sourceFile path to outputFile path
func ZipSingleFile ¶
ZipSingleFile zip the sourceFile path to outputFile path
Types ¶
type DateTime ¶
type DateTime string
const ( RFC822 DateTime = time.RFC822 Kitchen DateTime = time.Kitchen UnixDate DateTime = time.UnixDate YYYY_MM_DD DateTime = "2006-01-02" DD_MM_YYYY DateTime = "02-01-2006" YYYY_MM_DD_HH_MM_SS DateTime = "2006-01-02 15:04:05" DD_MM_YYYY_HH_MM_SS DateTime = "02-01-2006 15:04:05" UNIX = 100000000 UNIX_MILLI = 1000000000000 )
type Pagination ¶
type Pagination struct { Limit int64 `json:"limit"` Page int64 `json:"page"` SortBy string `json:"sort_by"` SortDesc int64 `json:"sort_desc"` Count int64 `json:"count"` Pages int64 `json:"pages"` Records interface{} `json:"records"` }
func NewPagination ¶
func NewPagination(limit interface{}, page interface{}, sort_by interface{}, sort_desc interface{}, with_total bool) *Pagination
func (*Pagination) GetLimit ¶
func (p *Pagination) GetLimit() int
func (*Pagination) GetOffset ¶
func (p *Pagination) GetOffset() int
func (*Pagination) GetPage ¶
func (p *Pagination) GetPage() int
func (*Pagination) GetSort ¶
func (p *Pagination) GetSort() string
type PaginationQuery ¶
type PaginationQuery struct { Size int `json:"size,omitempty"` Page int `json:"page,omitempty"` OrderBy string `json:"orderBy,omitempty"` }
Pagination query params
func GetPaginationFromCtx ¶
func GetPaginationFromCtx(c gin.Context) (*PaginationQuery, error)
nolint Get pagination query struct from
func (*PaginationQuery) GetQueryString ¶
func (q *PaginationQuery) GetQueryString() string
func (*PaginationQuery) SetOrderBy ¶
func (q *PaginationQuery) SetOrderBy(orderByQuery string)
Set order by
func (*PaginationQuery) SetPage ¶
func (q *PaginationQuery) SetPage(pageQuery string) error
Set page number
func (*PaginationQuery) SetSize ¶
func (q *PaginationQuery) SetSize(sizeQuery string) error
Set page size