util

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
	TB
	PB
)

字节大小常量

View Source
const (
	FormatTime     = "15:04:05"
	FormatDate     = "2006-01-02"
	FormatDateTime = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func BetweenNow added in v0.0.15

func BetweenNow(startTime, endTime string) bool

BetweenNow 是否在当前时间内

func ByteConvertString added in v0.0.23

func ByteConvertString(size float32) string

ByteConvertString 字节大小转换 B==>KB==>MB==>GB

func CheckTimeFormat

func CheckTimeFormat(src, layout string) bool

检测时间格式是否正确

func CurrentTimeMillisecond added in v0.0.8

func CurrentTimeMillisecond() int64

获取 服务器内部时间戳 ms,可能有偏移量

func CurrentTimeSecond added in v0.0.8

func CurrentTimeSecond() int64

获取 服务器内部时间戳s,可能有偏移量

func DeepCopy added in v0.0.25

func DeepCopy(dst, src interface{}) error

DeepCopy 深拷贝

func FileExists added in v0.0.15

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func FirstLower added in v0.0.17

func FirstLower(s string) string

FirstLower 字符串首字母小写

func FirstUpper added in v0.0.17

func FirstUpper(s string) string

FirstUpper 字符串首字母大写

func GenerateSessionId

func GenerateSessionId() (string, error)

func GetAppPath added in v0.0.15

func GetAppPath() string

Get the absolute path to the running directory

func GetJavaIntHash added in v0.0.9

func GetJavaIntHash(s string) int32

计算字符串java hash值 int java byte为有符号(-128~127),go为无符号(0~256)

func IsPort added in v0.0.15

func IsPort(p string) bool

IsPort is the string a port

func IsToday

func IsToday(ts int64) bool

是否为今天

func IsWindows added in v0.0.15

func IsWindows() bool

Determine whether the current system is a Windows system?

func Now added in v0.0.8

func Now() time.Time

当前时间,有时间偏移量

func ParseInt added in v0.0.10

func ParseInt(numberStr string) int

字符串转int,失败返回0

func ParseInt32 added in v0.0.10

func ParseInt32(numberStr string) int32

字符串转int32,失败返回0

func ParseInt64 added in v0.0.10

func ParseInt64(numberStr string) int64

字符串转int64,失败返回0

func RandomBool added in v0.0.14

func RandomBool(probability int32) bool

RandomBool 根据几率 计算是否生成,种子数为10000

func RandomInt32 added in v0.0.13

func RandomInt32(start, end int32) int32

RandomInt32 随机 int32 ,包含开始和结束

func RandomInt64 added in v0.0.19

func RandomInt64(start, end int64) int64

RandomInt64 随机 int64 ,包含开始和结束

func SameDay

func SameDay(a, b time.Time) bool

是否为同一天

func SameWeek added in v0.0.4

func SameWeek(a, b int64) bool

是否同一周 单位为s

func SameWeekNow added in v0.0.4

func SameWeekNow(a int64) bool

和当前时间是否为同一周 单位为s

func SetTime added in v0.0.8

func SetTime(timeStr string)

设置系统时间

func SliceContains

func SliceContains(array interface{}, val interface{}) (index int)

是否包含某个元素

func ToString

func ToString(what interface{}) string

ToString 将任意结构转化为json字符串 方便输出调试

func ToStringIndent

func ToStringIndent(what interface{}) string

ToStringIndent 将任意结构转化为json缩进后的字符串 方便输出调试

func WaitForTerminate

func WaitForTerminate()

WaitTerminateSignal wait signal to end the program

func WightRandomTwo added in v0.0.20

func WightRandomTwo[A any](drops []*Two[A, int32]) A

WightRandomTwo 根据权重随机,第二参数为权重

func ZKAdd

func ZKAdd(conn *zk.Conn, path string, value string, flag int32)

增 flags有4种取值: 0:永久,除非手动删除 zk.FlagEphemeral = 1:短暂,session断开则该节点也被删除 zk.FlagSequence = 2:会自动在节点后面添加序号 3:Ephemeral和Sequence,即,短暂且自动添加序号

func ZKCreateConnect

func ZKCreateConnect(hosts []string) *zk.Conn

创建zookeeper连接

func ZKDelete

func ZKDelete(conn *zk.Conn, path string)

func ZKGet

func ZKGet(conn *zk.Conn, path string) string

func ZKUpdate

func ZKUpdate(conn *zk.Conn, path string, value string)

删改与增不同在于其函数中的version参数,其中version是用于 CAS支持 可以通过此种方式保证原子性 改

func ZKWatchChildrenW

func ZKWatchChildrenW(conn *zk.Conn, path string, errClose bool) (chan []string, chan error)

ZKWatchChildrenW 事件监听 只能监听一层子目录?

func ZeroUnixTime added in v0.0.3

func ZeroUnixTime(offsetDay int) int64

获取零点时间

Types

type DefaultModule

type DefaultModule struct {
}

@

func (DefaultModule) Init

func (this DefaultModule) Init() error

func (DefaultModule) Run

func (this DefaultModule) Run()

func (DefaultModule) Stop

func (this DefaultModule) Stop()

type DefaultModuleManager

type DefaultModuleManager struct {
	Module
	Modules []Module
}

DefaultModuleManager default module manager

func NewDefaultModuleManager

func NewDefaultModuleManager() *DefaultModuleManager

func (*DefaultModuleManager) AppendModule

func (this *DefaultModuleManager) AppendModule(module Module) Module

添加模块

func (*DefaultModuleManager) Init

func (this *DefaultModuleManager) Init() error

初始化所有模块

func (*DefaultModuleManager) Run

func (this *DefaultModuleManager) Run()

运行模块

func (*DefaultModuleManager) Stop

func (this *DefaultModuleManager) Stop()

type Five added in v0.0.18

type Five[A any, B any, C any, D any, E any] struct {
	A A
	B B
	C C
	D D
	E E
}

Five 五个个参数结构体

func ParseFiveArgs added in v0.0.18

func ParseFiveArgs[A any, B any, C any, D any, E any](configString, splitSlice, splitArgs string, parseFun func(configStr []string) (A, B, C, D, E)) []*Five[A, B, C, D, E]

ParseFiveArgs 解析字符串道具 splitSlice数组分割 splitArgs 参数分割 例如2=10=1=3=1,5=25=1=3=1,10=20=1=3=1,15=10=1=3=1,20=5=1=3=1 splitSlice

type Four added in v0.0.18

type Four[A any, B any, C any, D any] struct {
	A A
	B B
	C C
	D D
}

Four 四个参数结构体

func ParseFourArgs added in v0.0.18

func ParseFourArgs[A any, B any, C any, D any](configString, splitSlice, splitArgs string, parseFun func(configStr []string) (A, B, C, D)) []*Four[A, B, C, D]

ParseFourArgs 解析字符串道具 splitSlice数组分割 splitArgs 参数分割 例如2=10=1=3,5=25=1=3,10=20=1=3,15=10=1=3,20=5=1=3 splitSlice

type Module

type Module interface {
	Init() error
	Run()
	Stop()
}

模块化

type ServiceConfig

type ServiceConfig struct {
	Name                string `json:"name"`
	Id                  string `json:"id"`
	Address             string `json:"address"`
	Port                int32  `json:"port"`
	RegistrationTimeUTC int64  `json:"registrationTimeUTC"`
	ServiceType         string `json:"serviceType"` //默认值 DYNAMIC
}

ServiceConfig 服务配置,参考java zookeeper服务发现定义

type Snowflake

type Snowflake struct {
	// contains filtered or unexported fields
}
var UUID *Snowflake

func NewSnowflake

func NewSnowflake(id int16) *Snowflake

func (*Snowflake) GetId

func (s *Snowflake) GetId() (int64, error)

func (*Snowflake) Init

func (s *Snowflake) Init(id int16) error

type Three added in v0.0.18

type Three[A any, B any, C any] struct {
	A A
	B B
	C C
}

Three 三个参数结构体

func ParseThreeArgs added in v0.0.18

func ParseThreeArgs[A any, B any, C any](configString, splitSlice, splitArgs string, parseFun func(configStr []string) (A, B, C)) []*Three[A, B, C]

ParseThreeArgs 解析字符串道具 splitSlice数组分割 splitArgs 参数分割 例如2=10=3,5=25=3,10=20=3,15=10=3,20=5=3 splitSlice

type Two added in v0.0.18

type Two[A any, B any] struct {
	A A
	B B
}

Two 两个参数结构体

func ParseTwoArgs added in v0.0.18

func ParseTwoArgs[A any, B any](configString, splitSlice, splitArgs string, parseFun func(configStr []string) (A, B)) []*Two[A, B]

ParseTwoArgs 解析字符串道具 splitSlice数组分割 splitArgs 参数分割 例如2=10,5=25,10=20,15=10,20=5 splitSlice

type Uint32IdAllocator

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

func NewUint32IdAllocator

func NewUint32IdAllocator() *Uint32IdAllocator

@

func (*Uint32IdAllocator) Get

func (a *Uint32IdAllocator) Get() uint32

@

Directories

Path Synopsis
* * 时间轮调度器 * 依赖模块 scheduled_task.go time_wheel.go
* * 时间轮调度器 * 依赖模块 scheduled_task.go time_wheel.go

Jump to

Keyboard shortcuts

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