utils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXIT = "exit"
	WAIT = "wait"
)
View Source
const (
	//Platform ID
	IOSPlatformID     = 1
	AndroidPlatformID = 2
	WindowsPlatformID = 3
	OSXPlatformID     = 4
	WebPlatformID     = 5
	MiniWebPlatformID = 6
	LinuxPlatformID   = 7

	//Platform string match to Platform ID
	IOSPlatformStr     = "IOS"
	AndroidPlatformStr = "Android"
	WindowsPlatformStr = "Windows"
	OSXPlatformStr     = "OSX"
	WebPlatformStr     = "Web"
	MiniWebPlatformStr = "MiniWeb"
	LinuxPlatformStr   = "Linux"

	//terminal types
	TerminalPC     = "PC"
	TerminalMobile = "Mobile"
)

设备匹配

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)
View Source
const (
	TimeFormatSecond = "2006-01-02 15:04:05"
	TimeFormatMinute = "2006-01-02 15:04"
	TimeFormatDateV1 = "2006-01-02"
	TimeFormatDateV2 = "2006_01_02"
	TimeFormatDateV3 = "20060102150405"
	TimeFormatDateV4 = "2006/01/02 - 15:04:05.000"
)

Variables

View Source
var (
	Events = make(map[string][]func(interface{}), 2)
)

Functions

func CrateDir added in v1.2.0

func CrateDir(dirs ...string) (err error)

CrateDir

func EmitAllEvent

func EmitAllEvent(arg interface{})

func EmitEvent

func EmitEvent(name string, arg interface{})

func Exists

func Exists(path string) bool

Exists checks whether the file/folder in the given path exists

func Ext

func Ext(path string) string

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.

func GetNowUnix added in v1.2.0

func GetNowUnix() int64

获取当前时间的时间戳

func GetSwitchFromOptions added in v1.2.0

func GetSwitchFromOptions(Options map[string]bool, key string) (result bool)

func GetTodayUnix

func GetTodayUnix() int64

func Int32ToString added in v1.2.0

func Int32ToString(i int32) string

func Int64ToString added in v1.2.0

func Int64ToString(i int64) string

func IntToString added in v1.2.0

func IntToString(i int) string

func InterfaceArrayToStringArray added in v1.2.0

func InterfaceArrayToStringArray(data []interface{}) (i []string)

func IsContain added in v1.2.0

func IsContain(target string, List []string) bool

judge a string whether in the string list

func JsonStringToMap added in v1.2.0

func JsonStringToMap(str string) (tempMap map[string]int32)

func JsonStringToStruct added in v1.2.0

func JsonStringToStruct(s string, args interface{}) error

The parameter[args] must be a pointer

func LocalIP

func LocalIP() (net.IP, error)

Get the local ip address

func MD5

func MD5(str string) string

func MapIntToJsonString added in v1.2.0

func MapIntToJsonString(param map[string]int32) string

func MapToJsonString added in v1.2.0

func MapToJsonString(param map[string]interface{}) string

func OffAllEvent

func OffAllEvent(name string) error

func OffEvent

func OffEvent(name string, f func(interface{})) error

func OnEvent

func OnEvent(name string, fs ...func(interface{})) error

func ParseCmdArguments

func ParseCmdArguments(s string) (arguments []string)

func PlatformIDToName added in v1.2.0

func PlatformIDToName(num int) string

func PlatformNameToClass added in v1.2.0

func PlatformNameToClass(name string) string

func PlatformNameToID added in v1.2.0

func PlatformNameToID(name string) int

func Scrypt added in v1.2.0

func Scrypt(password string) string

使用scrypt密码加密

func SetSwitchFromOptions added in v1.2.0

func SetSwitchFromOptions(options map[string]bool, key string, value bool)

func Stamp2Str added in v1.2.0

func Stamp2Str(stamp int64) string

时间戳->字符串

func Stamp2Time added in v1.2.0

func Stamp2Time(stamp int64) time.Time

时间戳->时间对象

func Str2Stamp added in v1.2.0

func Str2Stamp(formatTimeStr string) int64

*字符串->时间戳

func Str2Time added in v1.2.0

func Str2Time(formatTimeStr string) time.Time

*字符串->时间对象

func StringToInt added in v1.2.0

func StringToInt(i string) int

func StringToInt32 added in v1.2.0

func StringToInt32(i string) int32

func StringToInt64 added in v1.2.0

func StringToInt64(i string) int64

func StructToJsonBytes added in v1.2.0

func StructToJsonBytes(param interface{}) []byte

func StructToJsonString added in v1.2.0

func StructToJsonString(param interface{}) string

func Time2Stamp added in v1.2.0

func Time2Stamp(t time.Time) int64

时间对象->时间戳

func Time2Str added in v1.2.0

func Time2Str(t time.Time) string

*时间对象->字符串

func UUID

func UUID() (string, error)

func WaitEvent

func WaitEvent(sig ...os.Signal) os.Signal

Wait for the signal If the signal parameter is empty, it waits for the common termination signal

Types

type Cpu

type Cpu struct {
	Cpus  []float64 `json:"cpus"`
	Cores int       `json:"cores"`
}

func InitCPU

func InitCPU() (c Cpu, err error)

type Disk

type Disk struct {
	UsedMB      int `json:"usedMb"`
	UsedGB      int `json:"usedGb"`
	TotalMB     int `json:"totalMb"`
	TotalGB     int `json:"totalGb"`
	UsedPercent int `json:"usedPercent"`
}

func InitDisk

func InitDisk() (d Disk, err error)

type Map added in v1.2.0

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Map) Del added in v1.2.0

func (m *Map) Del(key interface{})

func (*Map) Get added in v1.2.0

func (m *Map) Get(key interface{}) interface{}

func (*Map) Len added in v1.2.0

func (m *Map) Len() int

func (*Map) LockRange added in v1.2.0

func (m *Map) LockRange(f func(interface{}, interface{}))

func (*Map) RLockRange added in v1.2.0

func (m *Map) RLockRange(f func(interface{}, interface{}))

func (*Map) Set added in v1.2.0

func (m *Map) Set(key interface{}, value interface{})

func (*Map) TestAndSet added in v1.2.0

func (m *Map) TestAndSet(key interface{}, value interface{}) interface{}

func (*Map) UnsafeDel added in v1.2.0

func (m *Map) UnsafeDel(key interface{})

func (*Map) UnsafeGet added in v1.2.0

func (m *Map) UnsafeGet(key interface{}) interface{}

func (*Map) UnsafeLen added in v1.2.0

func (m *Map) UnsafeLen() int

func (*Map) UnsafeRange added in v1.2.0

func (m *Map) UnsafeRange(f func(interface{}, interface{}))

func (*Map) UnsafeSet added in v1.2.0

func (m *Map) UnsafeSet(key interface{}, value interface{})

type Os

type Os struct {
	GOOS         string `json:"goos"`
	NumCPU       int    `json:"numCpu"`
	Compiler     string `json:"compiler"`
	GoVersion    string `json:"goVersion"`
	NumGoroutine int    `json:"numGoroutine"`
}

func InitOS

func InitOS() (o Os)

type Rrm

type Rrm struct {
	UsedMB      int `json:"usedMb"`
	TotalMB     int `json:"totalMb"`
	UsedPercent int `json:"usedPercent"`
}

func InitRAM

func InitRAM() (r Rrm, err error)

type Server

type Server struct {
	Os   Os   `json:"os"`
	Cpu  Cpu  `json:"cpu"`
	Rrm  Rrm  `json:"ram"`
	Disk Disk `json:"disk"`
}

func GetServerInfo

func GetServerInfo() (server *Server, err error)

type Timer added in v1.2.0

type Timer interface {
	AddTaskByFunc(taskName string, spec string, task func()) (cron.EntryID, error)
	AddTaskByJob(taskName string, spec string, job interface{ Run() }) (cron.EntryID, error)
	FindCron(taskName string) (*cron.Cron, bool)
	StartTask(taskName string)
	StopTask(taskName string)
	Remove(taskName string, id int)
	Clear(taskName string)
	Close()
}

func NewTimerTask added in v1.2.0

func NewTimerTask() Timer

Jump to

Keyboard shortcuts

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