Documentation ¶
Index ¶
- Constants
- func After(u, t time.Time) bool
- func Afterf(layout, u string, t time.Time) bool
- func Afterfx(layout, u, t string) bool
- func Before(u, t time.Time) bool
- func Beforef(layout, u string, t time.Time) bool
- func Beforefx(layout, u, t string) bool
- func Between(start, end, u time.Time, zero ...bool) bool
- func Betweenf(layout, start, end string, u time.Time, zero ...bool) bool
- func Betweenfx(layout, start, end, u string, zero ...bool) bool
- func Daily(now, last time.Time, hour int) bool
- func DailyNext(now time.Time, hour int) time.Time
- func DailyPrev(now time.Time, hour int) time.Time
- func Date(year int, month time.Month, day int, value ...int) time.Time
- func EquateApproxProtoTimestamp(margin time.Duration) cmp.Option
- func Err(a ...any) error
- func ExpvarStr(expvarStat []ExpvarStat) string
- func FixedNext(base, now time.Time, duration time.Duration) time.Time
- func FixedPrev(base, now time.Time, duration time.Duration) time.Time
- func FlagszAND(input, other string) string
- func FlagszAdd(input string, flag bool) string
- func FlagszAll(input string) bool
- func FlagszAny(input string) bool
- func FlagszCount(input string, flag bool) int32
- func FlagszGet(input string, index int32) bool
- func FlagszInit(size int32, flag bool) string
- func FlagszNone(input string) bool
- func FlagszOR(input, other string) string
- func FlagszSet(input string, index int32, flag bool) string
- func FlagszXOR(input, other string) string
- func FromBase58(input string) (uint64, error)
- func FromBase80(input string) (uint64, error)
- func FromBaseN(model, input string) (uint64, error)
- func FromProtoAny[T any](input *anypb.Any) (output *T, err error)
- func GetTimeZone() *time.Location
- func JsonString(data any) string
- func MapToArray[K comparable, V any](input map[K]V) (rk []K, rv []V)
- func Monthly(now, last time.Time, mday, hour int) bool
- func MonthlyNext(now time.Time, mday, hour int) time.Time
- func MonthlyPrev(now time.Time, mday, hour int) time.Time
- func Overlap(start1, end1, start2, end2 time.Time) bool
- func Overlapf(layout, start1, end1 string, start2, end2 time.Time) bool
- func Overlapfx(layout, start1, end1, start2, end2 string) bool
- func ProtoString(input proto.Message) string
- func RandInt() int
- func RandInt32() int32
- func RandInt32n(minimum, maximum int32) int32
- func RandInt64() int64
- func RandInt64n(minimum, maximum int64) int64
- func RandIntn(minimum, maximum int) int
- func RandReal64() int64
- func RandReal64n(minimum, maximum int64) int64
- func RandSeed(seed int64)
- func RandSeedTime()
- func RandString(length int, letter string) string
- func RandStringDefault() string
- func ReflectFieldValue[T any](value reflect.Value, name string) (result T, ok bool)
- func SetTimeZone(timeZone string) error
- func SetTimeZoneLocal()
- func SetTimeZoneUTC()
- func StrPercentage(count, total int) string
- func StringDisplayLength(input string) int
- func StringJoin(sep string, element ...string) string
- func TemplateBuild(blueprint string, builder *strings.Builder, refer any) (err error)
- func Time() time.Time
- func Timef(layout, value string) (time.Time, error)
- func ToBase58(input uint64) string
- func ToBase80(input uint64) string
- func ToBaseN(model string, input uint64) string
- func ToProtoAny(input ...proto.Message) (output []*anypb.Any, err error)
- func UnwrapErrID(err error) int
- func Weekly(now, last time.Time, wday, hour int) bool
- func WeeklyNext(now time.Time, wday, hour int) time.Time
- func WeeklyPrev(now time.Time, wday, hour int) time.Time
- func WriteFile(path string, data []byte) error
- func Yearly(now, last time.Time, month, mday, hour int) bool
- func YearlyNext(now time.Time, month, mday, hour int) time.Time
- func YearlyPrev(now time.Time, month, mday, hour int) time.Time
- type Dice
- func (this *Dice) Clear()
- func (this *Dice) Complete(payload any, maximum int64) error
- func (this *Dice) Fill(payload []any, weight []int64) error
- func (this *Dice) Max() int64
- func (this *Dice) One(payload any, weight int64) error
- func (this *Dice) Rand() any
- func (this *Dice) Randn(maximum int64) any
- func (this *Dice) Valid() bool
- type DiceDetect
- type Error
- type ExpvarStat
- type Fit
- type FitCap
- type Percent
- func (this *Percent) Add(per int32) *Percent
- func (this *Percent) Base() int32
- func (this *Percent) Calc(input int32, round Rounder) int
- func (this *Percent) Calc32(input int32, round Rounder) int32
- func (this *Percent) Calc64(input int32, round Rounder) int64
- func (this *Percent) Del(per int32) *Percent
- func (this *Percent) Div(per int32) *Percent
- func (this *Percent) Get() int32
- func (this *Percent) Mul(per int32) *Percent
- func (this *Percent) Set(per int32) *Percent
- func (this *Percent) SetBase() *Percent
- type Pprof
- type Rounder
- type StdColor
- func (this *StdColor) Err(format string, a ...any) *StdColor
- func (this *StdColor) Errf(format string, a ...any) *StdColor
- func (this *StdColor) Errln(a ...any) *StdColor
- func (this *StdColor) Failed() bool
- func (this *StdColor) GetStderr() io.Writer
- func (this *StdColor) GetStdout() io.Writer
- func (this *StdColor) Out(format string, a ...any) *StdColor
- func (this *StdColor) Outf(format string, a ...any) *StdColor
- func (this *StdColor) Outln(a ...any) *StdColor
- type SyncAttr
- type SyncOnce
Constants ¶
const ( Base58 = "0123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" // 58進制字串, 只使用0~9, a~z, A~Z 並且排除了oOlI這些容易混淆的字母 Base80 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._~+-*=?!|@#$%^&<>" // 80進制字串 )
const ( Success = 0 // 成功 ErrUnknown = 1 // 不明錯誤 ErrUnwrap = 2 // 取得錯誤編號失敗 )
const ( FlagszOnRune = '1' // 開啟旗標字符 FlagszOffRune = '0' // 關閉旗標字符 )
const ( PercentRatio100 = 100 // 百分比例值 PercentRatio1K = 1000 // 千分比例值 PercentRatio10K = 10000 // 萬分比例值 )
const ( StrNumber = "0123456789" // 數字列表 StrNumberAlpha = StrNumber + StrAlphaLower + StrAlphaUpper // 數字+小寫英文字母+大寫英文字母列表 StrAlphaLower = "abcdefghijklmnopqrstuvwxyz" // 小寫英文字母列表 StrAlphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // 大寫英文字母列表 )
const ( TimeMillisecond = time.Millisecond // 1毫秒時間 TimeSecond = time.Second // 1秒時間 TimeMinute = time.Minute // 1分鐘時間 TimeHour = time.Hour // 1小時時間 TimeDay = TimeHour * DayHourMax // 1日時間 TimeWeek = TimeDay * WeekdayMax // 1週時間 TimeMonth = TimeWeek * 4 // 1月時間, 這個時間並不準確 TimeYear = TimeDay * 365 // 1年時間, 這個時間並不準確 DayHourMax = 24 // 一天有幾小時 WeekdayMax = 7 // 1週有幾天 LayoutSecond = "2006-01-02 15:04:05" // 時間字串格式, 使用年月日時分秒 LayoutMinute = "2006-01-02 15:04" // 時間字串格式, 使用年月日時分 LayoutDay = "2006-01-02" // 時間字串格式, 使用年月日 )
Variables ¶
This section is empty.
Functions ¶
func Betweenf ¶
Betweenf 檢查 u 是否在 start 與 end 之間, start 與 end 按照 layout 來解析; 當 start 與 end 為空時, 回傳 zero, zero 預設為true
func Betweenfx ¶ added in v1.1.5
Betweenfx 檢查 u 是否在 start 與 end 之間, start 與 end 與 u 按照 layout 來解析; 當 start 與 end 為空時, 回傳 zero, zero 預設為true
func Date ¶
Date 取得指定時間, 會轉換為 SetTimeZone 設定的時區時間; 輸入參數依序是 年, 月, 日, 時, 分, 秒, 毫秒; 若時, 分, 秒, 毫秒未輸入則自動填0; 例如 Date(2023, 2, 15) 會得到 2023/02/15 00:00:00 的時間
func EquateApproxProtoTimestamp ¶ added in v1.1.33
EquateApproxProtoTimestamp 取得比對選項, 用於比較兩個 proto 的 timestamppb.Timestamp 時, 時間差異在 margin 範圍內時, 視為相等
margin 必須是非負數, 否則會觸發 panic
func Err ¶ added in v1.1.0
Err 產生錯誤, 最後會產生 Error 物件, 物件中分為字串與錯誤編號兩個部分, 產生的方式為
- 字串部分: 由 a 列表中的項目轉為字串後組合而成
- 錯誤編號部分: a 列表中最後一個可獲取的錯誤編號, 只有項目為錯誤編號或是 Error 才能獲取錯誤編號
使用時, 請讓參數結尾為 [ error | 字串 | Error, 錯誤編號]; 以下提供使用的範例
- trials.Err(字串, 字串, ... , error, 錯誤編號)
- trials.Err(字串, 字串, ... , error)
- trials.Err(字串, 字串, ... , 錯誤編號)
- trials.Err(字串, 錯誤編號)
- trials.Err(error, 錯誤編號)
- trials.Err(錯誤編號)
在制定錯誤編號時, 請加入以下三個預設的錯誤編號 Success, ErrUnknown, ErrUnwrap
func FixedNext ¶
FixedNext 取得下個固定間隔時間; base 若小於1970年, base 會被改為從1970年開始; now 若小於 base, now 會被改為 base; duration 不能小於1秒, 會造成計算錯誤
func FixedPrev ¶
FixedPrev 取得上個固定間隔時間; base 若小於1970年, base 會被改為從1970年開始; now 若小於 base, now 會被改為 base; duration 不能小於1秒, 會造成計算錯誤
func FromProtoAny ¶ added in v1.1.2
FromProtoAny 將any轉換為指定物件
func MapToArray ¶ added in v1.1.20
func MapToArray[K comparable, V any](input map[K]V) (rk []K, rv []V)
MapToArray 取得映射的索引與資料列表
func MonthlyNext ¶
MonthlyNext 取得下次的每月時間, mday是month-day
func MonthlyPrev ¶
MonthlyPrev 取得上次的每月時間, mday是month-day
func Overlapfx ¶ added in v1.1.5
Overlapfx 檢查兩個時間段是否有重疊, start1 與 end1 與 start2 與 end2 按照 layout 來解析
func ProtoString ¶ added in v1.1.2
ProtoString 將proto轉為字串
func RandReal64n ¶
RandReal64n 取得範圍內真隨機數值, 不需要事先設定隨機種子, 但是速度大約比偽隨機慢10倍
func ReflectFieldValue ¶ added in v1.1.9
ReflectFieldValue 取得反射物件中指定欄位的值
func StringJoin ¶
StringJoin 以分隔字串來組合字串列表, 實際上就是使用了 strings.Join 只是轉換了參數順序而已
func TemplateBuild ¶ added in v1.1.8
TemplateBuild 輸入模板字串(blueprint)與參考物件(refer), 利用go語言的 text/template 引擎在字串建造器(builder)的尾端產生字串
func ToProtoAny ¶ added in v1.1.2
ToProtoAny 將proto轉換為any
func WeeklyNext ¶
WeeklyNext 取得下次的每週時間, wday是 time.Weekday, 週日為0, 週一為1, 依此類推
func WeeklyPrev ¶
WeeklyPrev 取得上次的每週時間, wday是 time.Weekday, 週日為0, 週一為1, 依此類推
func YearlyNext ¶ added in v1.1.36
YearlyNext 取得下次的每年時間, mday是month-day
Types ¶
type Dice ¶
type Dice struct {
// contains filtered or unexported fields
}
Dice 骰子資料
type DiceDetect ¶
type DiceDetect struct {
// contains filtered or unexported fields
}
DiceDetect 骰子檢測資料
type Error ¶ added in v1.1.0
type Error struct {
// contains filtered or unexported fields
}
Error 錯誤資料
type Percent ¶
type Percent struct {
// contains filtered or unexported fields
}
Percent 比例計算器
func (*Percent) Calc32 ¶
Calc32 計算結果, input為輸入值, round為使用哪個函式來計算進位(math.Round / math.Ceil / math.Floor)
type Pprof ¶ added in v1.1.11
type Pprof struct {
// contains filtered or unexported fields
}
Pprof CPU剖析工具
type StdColor ¶
type StdColor struct {
// contains filtered or unexported fields
}
StdColor 色彩輸出顯示工具