util

package
v0.0.0-...-54886de Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Big5ToUtf8

func Big5ToUtf8(source []byte) (string, error)

func ContainAllMulti

func ContainAllMulti[T comparable](source []T, targets []T) bool

檢查目標陣列是否全部物件存在來源陣列內 (排除重複計算ex: source:[2], target:[2,2], return: false)

@params []T 比對來源

@params []T 比對目標

@return bool 是否包含所有物件

func ContainAnyoneMulti

func ContainAnyoneMulti[T comparable](source []T, targets []T) bool

檢查目標陣列是否有任一物件存在來源陣列內

@params []T 比對來源

@params []T 比對目標

@return bool 是否包含所有物件

func Contains

func Contains[T comparable](source []T, target T) bool

檢查站列是否包含目標

@params []T 比對來源

@params T 比對目標

@return bool 是否包含物件

func CountTransDate

func CountTransDate(startTime, endTime time.Time) int

計算天數, 只關注日期不會在意時間

@params time.Time 開始時間

@params time.Time 結束時間

@return int 天數

func DaysIn

func DaysIn(m time.Month, y int) int

計算當月天數

@params time.Month 月份

@params int 年分

@return int 天數

func EquarList

func EquarList[T comparable](a ...T) bool

陣列使否完全相同

@params []T 比對陣列

func EquarTargetList

func EquarTargetList[T comparable](source, target []T) bool

兩陣列是否相等

@params []T 比對來源

@params []T 比對目標

@return bool 是否相等

func FastSearchWithInt

func FastSearchWithInt(target int, source []int) int

@params int target @params []int source

@return int index. -1 is not find.

func GenStrUUID

func GenStrUUID(serviceNodeNum int64) string

func GenerateToken

func GenerateToken(serverHash string, data map[string]interface{}, expTime time.Time) (string, error)

func GetNumberInString

func GetNumberInString(source string) []string

從字串中取得數字

func HexToByte

func HexToByte(hexString string) ([]byte, error)

func Index

func Index[T comparable](source []T, target T) int

取得目標存在於來源陣列的索引值

@params []T 索引來源

@params T 索引目標

@return int 索引值

func IsTransDate

func IsTransDate(startTime, endTime time.Time) bool

是否跨日

func Marshal

func Marshal(v interface{}) ([]byte, error)

func MsgDecode

func MsgDecode(data []byte) (*dtomsg.Dto_Base, error)

@return error

func MsgEncode

func MsgEncode(data *dtomsg.Dto_Base) ([]byte, error)

@return error

func ParseJavaUnixSec

func ParseJavaUnixSec(t time.Time) int64

統一時間單位長度 13碼

func ParseToken

func ParseToken(serverHash string, tokenString string) (map[string]interface{}, error)

func ParseUnixSec

func ParseUnixSec(t int64) time.Time

只能處理到秒數 帶入毫秒級會被處理到只剩下秒級。 帶入奈秒級會被處理到只剩下秒級。

func ReadFileToLineStr

func ReadFileToLineStr(filePath string) []string

func RemoveFirst

func RemoveFirst[T comparable](source []T, target T) []T

刪除第一次出現的目標物件

@params []T 索引列表

@params T 目標物件

@return []T 複製結果

func RemoveFirstArray

func RemoveFirstArray[T comparable](source []T, targets []T) []T

刪除所有目標第一次出現的物件

@params []T 索引列表

@params T 目標物件

@return []T 複製結果

func RemoveIndex

func RemoveIndex[T comparable](source []T, idx int) []T

刪除索引直來源 0~n

@params source 索引列表 @params int 索引直範圍 0~n

func RemoveIndexCount

func RemoveIndexCount[T comparable](source []T, idx int) []T

刪除索引直來源 1~n

@params source 索引列表 @params int 索引直範圍 1~n

func RemoveIndexMulti

func RemoveIndexMulti[T comparable](source []T, idxs []int) []T

刪除索引直來源 1~n

@params source 索引列表 @params []int 索引直範圍 0~n

func RemoveUnPrintUncode

func RemoveUnPrintUncode(source string) string

移除無法顯示的 unicode

func ServerTimeNow

func ServerTimeNow() time.Time

取得當前 server 時間 *時區為 UTC+0

func Shuffle

func Shuffle[T int64](source []T) []T

func ShufflePoint

func ShufflePoint[T int64](source []T)

func Sort

func Sort[T int64](source []T, desc ...bool) []T

func SortPoint

func SortPoint[T int64 | float64](source []T, desc ...bool)

func UnitStr

func UnitStr() string

生成亂數字串

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

func Utf8ToBig5

func Utf8ToBig5(source []byte) ([]byte, error)

Types

type ClockTime

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

func NewClockTime

func NewClockTime(nowTime time.Time) ClockTime

生成新計時器

@param nowTime 當下時間 * 寫入不會做任何調整包含時區

func (*ClockTime) GetNowTime

func (t *ClockTime) GetNowTime() time.Time

取得當前時間 根據初始化給予的 nowTime 自行計數時候的時間

@return time.Time 當下時間

func (*ClockTime) GetTickCount

func (t *ClockTime) GetTickCount() uint64

取得當下計數時間

@return time.Duration 計數時間

func (*ClockTime) GetTimer

func (t *ClockTime) GetTimer() time.Duration

取得當下計數時間

@return time.Duration 計數時間

func (*ClockTime) MarshalJSON

func (t *ClockTime) MarshalJSON() ([]byte, error)

func (*ClockTime) ResetTimer

func (t *ClockTime) ResetTimer()

重製計數器

func (*ClockTime) SetNowTime

func (t *ClockTime) SetNowTime(nowTime time.Time)

設定新的當前時間

@param nowTime 當下時間 * 寫入不會做任何調整包含時區

func (*ClockTime) Ticket

func (t *ClockTime) Ticket(tickTime time.Duration)

計數一段時間

@param tickTime 要前進的時長

func (*ClockTime) UnmarshalJSON

func (t *ClockTime) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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