Tools

package module
v0.0.0-...-85536b9 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCharset = "UTF-8"
	DefaultTimeout = 15 * time.Second
)

------------------------------------------------------------------------------------- 模擬 Java 的常量 -------------------------------------------------------------------------------------

Variables

View Source
var Log = createLogger()

------------------------------------------------------------------------------------- 日誌系統 (簡化版 LogOut) -------------------------------------------------------------------------------------

Functions

func Base64ConvertToImageAndSave2Local

func Base64ConvertToImageAndSave2Local(_base64String string, _path string) bool

-------------------------------------------------------------------------------------

func Base64ToBytes

func Base64ToBytes(_data_string string) []byte

-------------------------------------------------------------------------------------

func ByteArraySearch

func ByteArraySearch(_data []byte, _start int, _end int, _comp []byte) int

------------------------------------------------------------------------------------- 資料處理 -------------------------------------------------------------------------------------

func Bytes2File

func Bytes2File(_fn string, _content []byte) bool

-------------------------------------------------------------------------------------

func Bytes2Hex

func Bytes2Hex(_b byte) string

-------------------------------------------------------------------------------------

func BytesToBase64String

func BytesToBase64String(_data []byte) string

------------------------------------------------------------------------------------- 加密與編碼 -------------------------------------------------------------------------------------

func ConsolePrint

func ConsolePrint(_msg string)

-------------------------------------------------------------------------------------

func DecodeWebClientData

func DecodeWebClientData(_data []byte, _length int) []byte

------------------------------------------------------------------------------------- Websocket 處理 -------------------------------------------------------------------------------------

func DeleteFile

func DeleteFile(_fn string) bool

-------------------------------------------------------------------------------------

func DisableUncaughtExceptionHandler

func DisableUncaughtExceptionHandler()

-------------------------------------------------------------------------------------

func EnableUncaughtExceptionHandler

func EnableUncaughtExceptionHandler(_serviceName string, _threshold int, _callback func())

-------------------------------------------------------------------------------------

func EncodeWebClientData

func EncodeWebClientData(_data []byte, _length int) []byte

-------------------------------------------------------------------------------------

func ExceptionToString

func ExceptionToString(_err interface{}) string

-------------------------------------------------------------------------------------

func File2Bytes

func File2Bytes(_fn string) []byte

-------------------------------------------------------------------------------------

func File2String

func File2String(_fn string) string

-------------------------------------------------------------------------------------

func ForceFlushMemory

func ForceFlushMemory()

-------------------------------------------------------------------------------------

func GetCurrentDateTimeString

func GetCurrentDateTimeString() string

-------------------------------------------------------------------------------------

func GetFullMachineID

func GetFullMachineID() string

------------------------------------------------------------------------------------- 系統工具 -------------------------------------------------------------------------------------

func GetImageFromURL

func GetImageFromURL(_imageURL string, _authorization string, _timeoutMs int) []byte

-------------------------------------------------------------------------------------

func GetInternetIPv4Address

func GetInternetIPv4Address() string

-------------------------------------------------------------------------------------

func GetLocalIPv4Address

func GetLocalIPv4Address() string

-------------------------------------------------------------------------------------

func GetLocalMACAddress

func GetLocalMACAddress(_seperator string) string

------------------------------------------------------------------------------------- 網路功能 (Net) -------------------------------------------------------------------------------------

func GetLocalMACAddressByConsoleCMD

func GetLocalMACAddressByConsoleCMD(_seperator string) string

------------------------------------------------------------------------------------- GetLocalMACAddressByConsoleCMD 執行系統指令獲取 MAC

func GetLocalTime

func GetLocalTime() int64

func GetMachineID

func GetMachineID() string

-------------------------------------------------------------------------------------

func GetMethodName

func GetMethodName(_class interface{}) string

-------------------------------------------------------------------------------------

func GetOSName

func GetOSName() string

func GetPID

func GetPID(cmd *exec.Cmd) int

------------------------------------------------------------------------------------- Process 功能 -------------------------------------------------------------------------------------

func GetProcessCPUUsage

func GetProcessCPUUsage() float64

-------------------------------------------------------------------------------------

func GetProcessMemoryUsage

func GetProcessMemoryUsage() int64

------------------------------------------------------------------------------------- 系統效能監控 -------------------------------------------------------------------------------------

func GetSystemCPUUsage

func GetSystemCPUUsage() float64

-------------------------------------------------------------------------------------

func GetSystemMemoryUsage

func GetSystemMemoryUsage() int64

-------------------------------------------------------------------------------------

func GetUTC

func GetUTC() int64

-------------------------------------------------------------------------------------

func GlobalRecovery

func GlobalRecovery()

-------------------------------------------------------------------------------------

func HttpGet

func HttpGet(_url string, _authToken string, _timeoutMs int) string

-------------------------------------------------------------------------------------

func HttpGetAsync

func HttpGetAsync(_url string, _callback func([]byte))

-------------------------------------------------------------------------------------

func HttpGet_BytesData

func HttpGet_BytesData(_url string, _authToken string, _timeoutMs int) []byte

------------------------------------------------------------------------------------- 網路功能 (HTTP) -------------------------------------------------------------------------------------

func HttpPost

func HttpPost(_url string, _authToken string, _contentType string, _content string, _timeoutMs int) string

-------------------------------------------------------------------------------------

func HttpPostWithHeaders

func HttpPostWithHeaders(_url string, _headers map[string]string, _contentType string, _content string, _timeoutMs int) string

-------------------------------------------------------------------------------------

func HttpPost_BytesData

func HttpPost_BytesData(_url string, _authToken string, _ignoreSSL bool, _contentType string, _content string, _timeoutMs int) []byte

-------------------------------------------------------------------------------------

func If

func If(condition bool, trueVal any, falseVal any) any

-------------------------------------------------------------------------------------

func IsFileExists

func IsFileExists(_fn string) bool

func IsHostAlive

func IsHostAlive(_host string, _timeout int) bool

-------------------------------------------------------------------------------------

func IsJSONValid

func IsJSONValid(_src string) bool

-------------------------------------------------------------------------------------

func IsLinux

func IsLinux() bool

-------------------------------------------------------------------------------------

func IsMSWindow

func IsMSWindow() bool

-------------------------------------------------------------------------------------

func IsMacOS

func IsMacOS() bool

-------------------------------------------------------------------------------------

func IsPortInUsing

func IsPortInUsing(_port int) bool

-------------------------------------------------------------------------------------

func KillProcess

func KillProcess(pid string) bool

-------------------------------------------------------------------------------------

func ParseURLParams

func ParseURLParams(_paramString string) map[string]string

-------------------------------------------------------------------------------------

func ReadLineFromKeyIn

func ReadLineFromKeyIn() string

------------------------------------------------------------------------------------- 其他工具 -------------------------------------------------------------------------------------

func RestartItSelf

func RestartItSelf() error

-------------------------------------------------------------------------------------

func SHA1ToBytes

func SHA1ToBytes(_data_string string) []byte

-------------------------------------------------------------------------------------

func SafeRun

func SafeRun(_task func())

-------------------------------------------------------------------------------------

func SendCommunityText

func SendCommunityText(_vendor, _from, _to, _text string) string

-------------------------------------------------------------------------------------

func SendEMail

func SendEMail(_sender map[string]interface{}, _to string, _subject string, _contentType string, _content string) bool

-------------------------------------------------------------------------------------

func SendEMailAttachment

func SendEMailAttachment(_sender map[string]interface{}, _to string, _subject string, _msgType string, _msg string, _attType string, _attName string, _buffer []byte) bool

-------------------------------------------------------------------------------------

func SendMulticastData

func SendMulticastData(_multicastGroup string, _multicastPort int, _data []byte)

-------------------------------------------------------------------------------------

func ShellCMD

func ShellCMD(cmds ...string) *exec.Cmd

-------------------------------------------------------------------------------------

func ShellCMDAsync

func ShellCMDAsync(callback IShellCMDCallback, cmds ...string)

-------------------------------------------------------------------------------------

func ShellCMDSync

func ShellCMDSync(_cmds ...string) string

-------------------------------------------------------------------------------------

func ShellCMDWithPah

func ShellCMDWithPah(path string, cmds ...string) *exec.Cmd

------------------------------------------------------------------------------------- 命令執行 (Shell CMD) -------------------------------------------------------------------------------------

func Sleep

func Sleep(_ms int)

-------------------------------------------------------------------------------------

func TransformComposedID

func TransformComposedID(_composedID string) []string

-------------------------------------------------------------------------------------

func TransformID

func TransformID(_uuid string, _suid string) string

-------------------------------------------------------------------------------------

func XValueCompare

func XValueCompare(_a interface{}, _b interface{}) string

-------------------------------------------------------------------------------------

Types

type IShellCMDCallback

type IShellCMDCallback func(proc *os.Process, data string)

-------------------------------------------------------------------------------------

type LogLevel

type LogLevel int

-------------------------------------------------------------------------------------

const (
	LL_Debug LogLevel = iota
	LL_Normal
	LL_Info
	LL_Warning
	LL_Error
)

-------------------------------------------------------------------------------------

type LogOut

type LogOut struct {
	// contains filtered or unexported fields
}

-------------------------------------------------------------------------------------

func (*LogOut) Print

func (_l *LogOut) Print(_level LogLevel, _msgs ...string)

-------------------------------------------------------------------------------------

func (*LogOut) SetDisplayLevel

func (_l *LogOut) SetDisplayLevel(_level LogLevel)

-------------------------------------------------------------------------------------

func (*LogOut) SetRemoteOutput

func (_l *LogOut) SetRemoteOutput(_enable bool, _addr string)

-------------------------------------------------------------------------------------

type Stopwatch

type Stopwatch struct {
	// contains filtered or unexported fields
}

func CreateStopwatch

func CreateStopwatch() *Stopwatch

-------------------------------------------------------------------------------------

func (*Stopwatch) Get

func (_sw *Stopwatch) Get() int64

-------------------------------------------------------------------------------------

func (*Stopwatch) Reset

func (_sw *Stopwatch) Reset()

-------------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

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