util

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// DefaultPerPage .
	DefaultPerPage = 20
)
View Source
const (
	// TimeFormat .
	TimeFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func Deviation

func Deviation(randomVars []float64) float64

Deviation .

func Expectation

func Expectation(randomVars []float64) float64

Expectation .

func IntSliToSQLVarchars

func IntSliToSQLVarchars(ints []int64) string

IntSliToSQLVarchars convert int slice to string, eg: [1,2,3] -> "1,2,3"

Example
fmt.Println(IntSliToSQLVarchars([]int64{1, 2, 3}))
Output:

1,2,3

func Max

func Max(vars []int64) (maxVar int64)

Max .

func Normallization

func Normallization(randomVars []int64) []float64

Normallization .

func RandID

func RandID() int64

RandID .

func RandStr

func RandStr(size int) string

RandStr .

func SameChar

func SameChar(content string) bool

SameChar check if string consists of same characters

func StdDeviation

func StdDeviation(randomVars []float64) float64

StdDeviation .

func StrSliToSQLVarchars

func StrSliToSQLVarchars(s []string) string

StrSliToSQLVarchars convert string slice to varchar in sql syntax eg: ["default", "deleted", "modified"] -> " 'default', 'deleted', 'modified' " so that we can used it in 'SELECT * ... WHERE xxx IN ('default', 'deleted', 'modified')'

Example
fmt.Println(StrSliToSQLVarchars([]string{"default", "deleted", "modified"}))
Output:

'default','deleted','modified'

func StrToIntSli

func StrToIntSli(s string, delimiter string) ([]int64, error)

StrToIntSli convert string to int slice, eg: "1,2,3" -> [1,2,3]

Example
fmt.Println(StrToIntSli("1,2,3", ","))
Output:

[1 2 3] <nil>

func StripPrefix

func StripPrefix(s string, prefix string, suffix string) string

StripPrefix remove prefix from string if exists

Types

type JSONTime

type JSONTime time.Time

JSONTime .

func (JSONTime) Before

func (jt JSONTime) Before(t time.Time) bool

Before .

func (JSONTime) MarshalJSON

func (jt JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON .

type Pagination

type Pagination struct {
	CurPage int64
	PerPage int64
}

Pagination perform page algorithm

func (*Pagination) OffsetLimit

func (p *Pagination) OffsetLimit(total int64) (offset int64, limit int64)

OffsetLimit calculate "offset" and "start" with total_counts

func (*Pagination) Page

func (p *Pagination) Page(total int64) (from int64, to int64)

Page calculate "from", "to" with total_counts index start from 1

func (*Pagination) SimplePage

func (p *Pagination) SimplePage() (from int64, to int64)

SimplePage calculate "from", "to" without total_counts "from" index start from 1

func (*Pagination) VagueOffsetLimit

func (p *Pagination) VagueOffsetLimit() (offset int64, limit int64)

VagueOffsetLimit calculate "offset", "limit" without total_counts

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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