tools

package
v0.0.0-...-616fdc4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ZeroTime  = time.Second * 0
	OneSecond = time.Second * 1
	OneMinute = OneSecond * 60
	OneHour   = OneMinute * 60
	OneDay    = OneHour * 24
	OneWeek   = OneDay * 7
	OneYear   = OneDay * 365
)

当前页面,都是时间类型(time.Duration)的值,不做其他用途

Variables

View Source
var Validate validator

Functions

func BytesToString

func BytesToString(b []byte) string

字节数组 转 字符串

func Contain

func Contain(obj interface{}, target interface{}) bool

判断obj是否在target中,target支持的类型 array, slice, map

func CurrentTime

func CurrentTime() string

返回当前时间

func CurrentTimestamp

func CurrentTimestamp() int64

返回当前时间的时间戳

func DBPage

func DBPage(number, size int) (limit int, offset int)

MySQL数据库分页计算,传入页数和每页数量,得到sql需要的分页参数

func ExecBashShell

func ExecBashShell(cmdLine string) (string, error)

执行系统命令【linux】

func Float64ToStr

func Float64ToStr(x float64) string

func GetRootPath

func GetRootPath() (*string, error)

用于获取项目根目录的绝对路径

func GetShellTimezone

func GetShellTimezone() (int, error)

使用shell方式从系统中获取时区【MAC,linux限定】

func GetTimeZone

func GetTimeZone() int

获取当前的时区

func GetTimeZoneCity

func GetTimeZoneCity(num int) string

时区设置

func Int64ToStr

func Int64ToStr(x int64) string

func IntToStr

func IntToStr(x int) string

func MathChangeUnit

func MathChangeUnit(unit int64) string

单位转换: 传入值的单位(B)

func NetMask16to10

func NetMask16to10(str string) string

传入一个 16 进制子网掩码字符串,转换成 10 进制的子网掩码字符串

func OneMonth

func OneMonth(year int, month int) (int, time.Duration)

func ParseJsonFile

func ParseJsonFile(filename string, v interface{}) error

解析JSON文件: json文件的数据结构 和 接口对象的数据结构 必须要一致!!!

func PasswordEncryption

func PasswordEncryption(username string, password string, createAt int64) (string, error)

给密码加密,这里推荐使用用户ID。后面有空的时候我会更新一下。 这种方式加密的弊端是用户名不能修改了,否则就无法登录了。正常的用法是使用用户ID

func RandInt

func RandInt(x int) int

生成指定范围内的随机数【0到x,不包含x】

func RandRangeInt

func RandRangeInt(min, max int) int

生成指定范围内的随机数

func RandStr

func RandStr() string

生成随机字符

func ReturnJson

func ReturnJson(o interface{}) string

返回 JSON 字符串

func SetLinuxSystemTime

func SetLinuxSystemTime(tt int64) error

设置系统时间【linux】

func SetLinuxTimeZone

func SetLinuxTimeZone(tz int) error

设置系统时区【linux】

func StrMD5

func StrMD5(str string) string

func StrSHA1

func StrSHA1(str string) string

func StrSHA256

func StrSHA256(str string) string

func StrSHA512

func StrSHA512(str string) string

func StrToInt

func StrToInt(x string) (int, error)

func TimeDifference

func TimeDifference(oldTime, newTime string) int

两个时间的时间差,返回结果为秒

func TimestampToLocal

func TimestampToLocal(t int64) string

根据时间戳返回本地时间

Types

This section is empty.

Jump to

Keyboard shortcuts

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