utils

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSONIntoMap

func BindJSONIntoMap(context *gin.Context, obj map[string]interface{}) error

BindJSONIntoMap decodes json body to map, skips fields which are not in allowedFields Example usage: u.Params = make(map[string]interface{}) err := utils.BindJSONIntoMap(c, u.Params)

func CheckPathAndCreate

func CheckPathAndCreate(path string) error

CheckPathAndCreate check path if exist, fi not exist, make the path dir

func GetFileExt

func GetFileExt(file *multipart.FileHeader) string

GetFileExt returns the file name extension The extension is the suffix beginning at the final dot

func GetFileMimeTypeByExt

func GetFileMimeTypeByExt(ext string) string

GetFileMimeTypeByExt returns the file mine-type by ext

func GetFileType

func GetFileType(mimeType string) string

GetFileType returns file type in word that defined

func GetFormatDeletedAtTime

func GetFormatDeletedAtTime(d *gorm.DeletedAt, layout string) string

GetFormatDeletedAtTime get format time from grom(v2) DeletedAt

func GetFormatNullTime

func GetFormatNullTime(t *sql.NullTime, layout string) string

GetFormatNullTime get format time which could be NULL it returns empty string if the time is NULL

func GetFormatTime

func GetFormatTime(t *time.Time, layout string) string

GetFormatTime get format time include nil value

func GetReqID

func GetReqID(c *gin.Context) string

GetReqID get X-Request-Id header and return the value which is a uuid

func JSON2Map added in v0.4.0

func JSON2Map(j []byte, m *map[string]interface{}) error

JSON2Map convert JSON to map

func Map2JSON added in v0.4.0

func Map2JSON(m interface{}) ([]byte, error)

Map2JSON convert map to JSON

func PathExists

func PathExists(path string) (bool, error)

PathExists check the path if exist

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceDiffUint64

func SliceDiffUint64(slice1, slice2 []uint64) (diffslice []uint64)

SliceDiffUint64 returns diff slice of slice1 - slice2. for uint64

func SliceHas

func SliceHas(v interface{}, sl []interface{}) bool

SliceHas checks given interface if in the interface slice.

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns the intersection of slice1 and slice2.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func StringToNullTime

func StringToNullTime(layout string, timeString string) sql.NullTime

StringToNullTime changesfer a time string to mysql.NullTime

func StringToTime

func StringToTime(layout string, timeString string) time.Time

StringToTime changesfer a time string to time.Time

func SubNullTimeUnitlNowAsDay

func SubNullTimeUnitlNowAsDay(t time.Time) float64

SubNullTimeUnitlNowAsDay calculate the diff day until now

Types

type Page

type Page struct {
	ShowSize int `json:"showSize"`
	PageSize int `json:"pageSize"`

	CurrentPage int `json:"currentPage"`
	TotalPage   int `json:"totalPage"`
	TotalRecord int `json:"totalRecord"`

	NextPageNum     int   `json:"nextPageNum"`
	PreviousPageNum int   `json:"previousPageNum"`
	FirstPageNum    int   `josn:"firstPageNum"`
	LastPageNum     int   `json:"lastPageNum"`
	PageNums        []int `json:"pageNums"`
}

Page pagination

type Pagination

type Pagination struct {
	Page    *Page
	PageURL string `json:"pageURL"`
}

Pagination include page and page url

func GetPagination

func GetPagination(totalRecord, currentPage, pageSizeIn, showSizeIn int) *Pagination

GetPagination return pagiantion and default page pre url

func (*Pagination) SetPageURL

func (p *Pagination) SetPageURL(url string)

SetPageURL set page url, default is empty string

type StrTo

type StrTo string

func (StrTo) Int

func (s StrTo) Int() (int, error)

Int convert string to int

func (StrTo) MustInt

func (s StrTo) MustInt() int

MustInt convert string to int without error

func (StrTo) MustUInt32

func (s StrTo) MustUInt32() uint32

MustUInt32 convert string to uint32 without error

func (StrTo) MustUInt64

func (s StrTo) MustUInt64() uint64

MustUInt32 convert string to uint32 without error

func (StrTo) String

func (s StrTo) String() string

String convert back to string

func (StrTo) UInt32

func (s StrTo) UInt32() (uint32, error)

Int convert string to uint32

func (StrTo) UInt64

func (s StrTo) UInt64() (uint64, error)

Int convert string to uint32

Jump to

Keyboard shortcuts

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