docs: 优化 README.md 可读性
This commit is contained in:
parent
1645ae47df
commit
22449ff5c3
|
@ -201,31 +201,61 @@ type Controller[Type generic.Basic, ID generic.Basic, Data any, EntityID generic
|
|||
mutex sync.RWMutex
|
||||
}
|
||||
```
|
||||
<span id="struct_Controller_GetGlobalData"></span>
|
||||
|
||||
#### func (*Controller) GetGlobalData(activityId ID) Data
|
||||
> 获取特定活动全局数据
|
||||
|
||||
***
|
||||
<span id="struct_Controller_GetEntityData"></span>
|
||||
|
||||
#### func (*Controller) GetEntityData(activityId ID, entityId EntityID) EntityData
|
||||
> 获取特定活动实体数据
|
||||
|
||||
***
|
||||
<span id="struct_Controller_IsOpen"></span>
|
||||
|
||||
#### func (*Controller) IsOpen(activityId ID) bool
|
||||
> 活动是否开启
|
||||
|
||||
***
|
||||
<span id="struct_Controller_IsShow"></span>
|
||||
|
||||
#### func (*Controller) IsShow(activityId ID) bool
|
||||
> 活动是否展示
|
||||
|
||||
***
|
||||
<span id="struct_Controller_IsOpenOrShow"></span>
|
||||
|
||||
#### func (*Controller) IsOpenOrShow(activityId ID) bool
|
||||
> 活动是否开启或展示
|
||||
|
||||
***
|
||||
<span id="struct_Controller_Refresh"></span>
|
||||
|
||||
#### func (*Controller) Refresh(activityId ID)
|
||||
> 刷新活动
|
||||
|
||||
***
|
||||
<span id="struct_Controller_InitializeNoneData"></span>
|
||||
|
||||
#### func (*Controller) InitializeNoneData(handler func (activityId ID, data *DataMeta[Data])) NoneDataActivityController[Type, ID, Data, EntityID, EntityData]
|
||||
|
||||
***
|
||||
<span id="struct_Controller_InitializeGlobalData"></span>
|
||||
|
||||
#### func (*Controller) InitializeGlobalData(handler func (activityId ID, data *DataMeta[Data])) GlobalDataActivityController[Type, ID, Data, EntityID, EntityData]
|
||||
|
||||
***
|
||||
<span id="struct_Controller_InitializeEntityData"></span>
|
||||
|
||||
#### func (*Controller) InitializeEntityData(handler func (activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) EntityDataActivityController[Type, ID, Data, EntityID, EntityData]
|
||||
|
||||
***
|
||||
<span id="struct_Controller_InitializeGlobalAndEntityData"></span>
|
||||
|
||||
#### func (*Controller) InitializeGlobalAndEntityData(handler func (activityId ID, data *DataMeta[Data]), entityHandler func (activityId ID, entityId EntityID, data *EntityDataMeta[EntityData])) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData]
|
||||
|
||||
***
|
||||
<span id="struct_BasicActivityController"></span>
|
||||
### BasicActivityController `INTERFACE`
|
||||
|
@ -313,19 +343,34 @@ type Options struct {
|
|||
Loop time.Duration
|
||||
}
|
||||
```
|
||||
<span id="struct_Options_WithUpcomingTime"></span>
|
||||
|
||||
#### func (*Options) WithUpcomingTime(t time.Time) *Options
|
||||
> 设置活动预告时间
|
||||
|
||||
***
|
||||
<span id="struct_Options_WithStartTime"></span>
|
||||
|
||||
#### func (*Options) WithStartTime(t time.Time) *Options
|
||||
> 设置活动开始时间
|
||||
|
||||
***
|
||||
<span id="struct_Options_WithEndTime"></span>
|
||||
|
||||
#### func (*Options) WithEndTime(t time.Time) *Options
|
||||
> 设置活动结束时间
|
||||
|
||||
***
|
||||
<span id="struct_Options_WithExtendedShowTime"></span>
|
||||
|
||||
#### func (*Options) WithExtendedShowTime(t time.Time) *Options
|
||||
> 设置延长展示时间
|
||||
|
||||
***
|
||||
<span id="struct_Options_WithLoop"></span>
|
||||
|
||||
#### func (*Options) WithLoop(interval time.Duration) *Options
|
||||
> 设置活动循环,时间间隔小于等于 0 表示不循环
|
||||
> - 当活动状态展示结束后,会根据该选项设置的时间间隔重新开始
|
||||
|
||||
***
|
||||
|
|
|
@ -65,18 +65,30 @@ type TurnBased[CampID comparable, EntityID comparable, Camp generic.IdR[CampID],
|
|||
closed bool
|
||||
}
|
||||
```
|
||||
<span id="struct_TurnBased_Close"></span>
|
||||
|
||||
#### func (*TurnBased) Close()
|
||||
> 关闭回合制
|
||||
|
||||
***
|
||||
<span id="struct_TurnBased_AddCamp"></span>
|
||||
|
||||
#### func (*TurnBased) AddCamp(camp Camp, entity Entity, entities ...Entity)
|
||||
> 添加阵营
|
||||
|
||||
***
|
||||
<span id="struct_TurnBased_SetActionTimeout"></span>
|
||||
|
||||
#### func (*TurnBased) SetActionTimeout(actionTimeoutHandler func ( Camp, Entity) time.Duration)
|
||||
> 设置行动超时时间处理函数
|
||||
> - 默认情况下行动超时时间函数将始终返回 0
|
||||
|
||||
***
|
||||
<span id="struct_TurnBased_Run"></span>
|
||||
|
||||
#### func (*TurnBased) Run()
|
||||
> 运行
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -154,33 +166,60 @@ type TurnBasedController[CampID comparable, EntityID comparable, Camp generic.Id
|
|||
tb *TurnBased[CampID, EntityID, Camp, Entity]
|
||||
}
|
||||
```
|
||||
<span id="struct_TurnBasedController_GetRound"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetRound() int
|
||||
> 获取当前回合数
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_GetCamp"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetCamp() Camp
|
||||
> 获取当前操作阵营
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_GetEntity"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetEntity() Entity
|
||||
> 获取当前操作实体
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_GetActionTimeoutDuration"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetActionTimeoutDuration() time.Duration
|
||||
> 获取当前行动超时时长
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_GetActionStartTime"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetActionStartTime() time.Time
|
||||
> 获取当前行动开始时间
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_GetActionEndTime"></span>
|
||||
|
||||
#### func (*TurnBasedController) GetActionEndTime() time.Time
|
||||
> 获取当前行动结束时间
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_Finish"></span>
|
||||
|
||||
#### func (*TurnBasedController) Finish()
|
||||
> 结束当前操作,将立即切换到下一个操作实体
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_Stop"></span>
|
||||
|
||||
#### func (*TurnBasedController) Stop()
|
||||
> 在当前回合执行完毕后停止回合进程
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedController_Refresh"></span>
|
||||
|
||||
#### func (*TurnBasedController) Refresh(duration time.Duration) time.Time
|
||||
> 刷新当前操作实体的行动超时时间
|
||||
> - 当不在行动阶段时,将返回 time.Time 零值
|
||||
|
||||
***
|
||||
<span id="struct_TurnBasedEntitySwitchEventHandler"></span>
|
||||
### TurnBasedEntitySwitchEventHandler `STRUCT`
|
||||
|
|
|
@ -70,131 +70,245 @@ type RoomController[EntityID comparable, RoomID comparable, Entity generic.IdR[E
|
|||
owner *EntityID
|
||||
}
|
||||
```
|
||||
<span id="struct_RoomController_HasOwner"></span>
|
||||
|
||||
#### func (*RoomController) HasOwner() bool
|
||||
> 判断是否有房主
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_IsOwner"></span>
|
||||
|
||||
#### func (*RoomController) IsOwner(entityId EntityID) bool
|
||||
> 判断是否为房主
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetOwner"></span>
|
||||
|
||||
#### func (*RoomController) GetOwner() Entity
|
||||
> 获取房主
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetOwnerID"></span>
|
||||
|
||||
#### func (*RoomController) GetOwnerID() EntityID
|
||||
> 获取房主 ID
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetOwnerExist"></span>
|
||||
|
||||
#### func (*RoomController) GetOwnerExist() ( Entity, bool)
|
||||
> 获取房间,并返回房主是否存在的状态
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_SetOwner"></span>
|
||||
|
||||
#### func (*RoomController) SetOwner(entityId EntityID)
|
||||
> 设置房主
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_DelOwner"></span>
|
||||
|
||||
#### func (*RoomController) DelOwner()
|
||||
> 删除房主,将房间设置为无主的状态
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_JoinSeat"></span>
|
||||
|
||||
#### func (*RoomController) JoinSeat(entityId EntityID, seat ...int) error
|
||||
> 设置特定对象加入座位,当具体的座位不存在的时候,将会自动分配座位
|
||||
> - 当目标座位存在玩家或未添加到房间中的时候,将会返回错误
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_LeaveSeat"></span>
|
||||
|
||||
#### func (*RoomController) LeaveSeat(entityId EntityID)
|
||||
> 离开座位
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeat"></span>
|
||||
|
||||
#### func (*RoomController) GetSeat(entityId EntityID) int
|
||||
> 获取座位
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetFirstNotEmptySeat"></span>
|
||||
|
||||
#### func (*RoomController) GetFirstNotEmptySeat() int
|
||||
> 获取第一个非空座位号,如果没有非空座位,将返回 UnknownSeat
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetFirstEmptySeatEntity"></span>
|
||||
|
||||
#### func (*RoomController) GetFirstEmptySeatEntity() (entity Entity)
|
||||
> 获取第一个空座位上的实体,如果没有空座位,将返回空实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetRandomEntity"></span>
|
||||
|
||||
#### func (*RoomController) GetRandomEntity() (entity Entity)
|
||||
> 获取随机实体,如果房间中没有实体,将返回空实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetNotEmptySeat"></span>
|
||||
|
||||
#### func (*RoomController) GetNotEmptySeat() []int
|
||||
> 获取非空座位
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEmptySeat"></span>
|
||||
|
||||
#### func (*RoomController) GetEmptySeat() []int
|
||||
> 获取空座位
|
||||
> - 空座位需要在有对象离开座位后才可能出现
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_HasSeat"></span>
|
||||
|
||||
#### func (*RoomController) HasSeat(entityId EntityID) bool
|
||||
> 判断是否有座位
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeatEntityCount"></span>
|
||||
|
||||
#### func (*RoomController) GetSeatEntityCount() int
|
||||
> 获取座位上的实体数量
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeatEntities"></span>
|
||||
|
||||
#### func (*RoomController) GetSeatEntities() map[EntityID]Entity
|
||||
> 获取座位上的实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeatEntitiesByOrdered"></span>
|
||||
|
||||
#### func (*RoomController) GetSeatEntitiesByOrdered() []Entity
|
||||
> 有序的获取座位上的实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeatEntitiesByOrderedAndContainsEmpty"></span>
|
||||
|
||||
#### func (*RoomController) GetSeatEntitiesByOrderedAndContainsEmpty() []Entity
|
||||
> 获取有序的座位上的实体,包含空座位
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetSeatEntity"></span>
|
||||
|
||||
#### func (*RoomController) GetSeatEntity(seat int) (entity Entity)
|
||||
> 获取座位上的实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_ContainEntity"></span>
|
||||
|
||||
#### func (*RoomController) ContainEntity(id EntityID) bool
|
||||
> 房间内是否包含实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetRoom"></span>
|
||||
|
||||
#### func (*RoomController) GetRoom() Room
|
||||
> 获取原始房间实例,该实例为被接管的房间的原始实例
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEntities"></span>
|
||||
|
||||
#### func (*RoomController) GetEntities() map[EntityID]Entity
|
||||
> 获取所有实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_HasEntity"></span>
|
||||
|
||||
#### func (*RoomController) HasEntity(id EntityID) bool
|
||||
> 判断是否有实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEntity"></span>
|
||||
|
||||
#### func (*RoomController) GetEntity(id EntityID) Entity
|
||||
> 获取实体
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEntityExist"></span>
|
||||
|
||||
#### func (*RoomController) GetEntityExist(id EntityID) ( Entity, bool)
|
||||
> 获取实体,并返回实体是否存在的状态
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEntityIDs"></span>
|
||||
|
||||
#### func (*RoomController) GetEntityIDs() []EntityID
|
||||
> 获取所有实体ID
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetEntityCount"></span>
|
||||
|
||||
#### func (*RoomController) GetEntityCount() int
|
||||
> 获取实体数量
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_ChangePassword"></span>
|
||||
|
||||
#### func (*RoomController) ChangePassword(password *string)
|
||||
> 修改房间密码
|
||||
> - 当房间密码为 nil 时,将会取消密码
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_AddEntity"></span>
|
||||
|
||||
#### func (*RoomController) AddEntity(entity Entity) error
|
||||
> 添加实体,如果房间存在密码,应使用 AddEntityByPassword 函数进行添加,否则将始终返回 ErrRoomPasswordNotMatch 错误
|
||||
> - 当房间已满时,将会返回 ErrRoomFull 错误
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_AddEntityByPassword"></span>
|
||||
|
||||
#### func (*RoomController) AddEntityByPassword(entity Entity, password string) error
|
||||
> 通过房间密码添加实体到该房间中
|
||||
> - 当未设置房间密码时,password 参数将会被忽略
|
||||
> - 当房间密码不匹配时,将会返回 ErrRoomPasswordNotMatch 错误
|
||||
> - 当房间已满时,将会返回 ErrRoomFull 错误
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_RemoveEntity"></span>
|
||||
|
||||
#### func (*RoomController) RemoveEntity(id EntityID)
|
||||
> 移除实体
|
||||
> - 当实体被移除时如果实体在座位上,将会自动离开座位
|
||||
> - 如果实体为房主,将会根据 RoomControllerOptions.WithOwnerInherit 函数的设置进行继承
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_RemoveAllEntities"></span>
|
||||
|
||||
#### func (*RoomController) RemoveAllEntities()
|
||||
> 移除该房间中的所有实体
|
||||
> - 当实体被移除时如果实体在座位上,将会自动离开座位
|
||||
> - 如果实体为房主,将会根据 RoomControllerOptions.WithOwnerInherit 函数的设置进行继承
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_Destroy"></span>
|
||||
|
||||
#### func (*RoomController) Destroy()
|
||||
> 销毁房间,房间会从 RoomManager 中移除,同时所有房间的实体、座位等数据都会被清空
|
||||
> - 该函数与 RoomManager.DestroyRoom 相同,RoomManager.DestroyRoom 函数为该函数的快捷方式
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetRoomManager"></span>
|
||||
|
||||
#### func (*RoomController) GetRoomManager() *RoomManager[EntityID, RoomID, Entity, Room]
|
||||
> 获取该房间控制器所属的房间管理器
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_GetRoomID"></span>
|
||||
|
||||
#### func (*RoomController) GetRoomID() RoomID
|
||||
> 获取房间 ID
|
||||
|
||||
***
|
||||
<span id="struct_RoomController_Broadcast"></span>
|
||||
|
||||
#### func (*RoomController) Broadcast(handler func ( Entity), conditions ...func ( Entity) bool)
|
||||
> 广播,该函数会将所有房间中满足 conditions 的对象传入 handler 中进行处理
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager"></span>
|
||||
### RoomManager `STRUCT`
|
||||
|
@ -207,10 +321,13 @@ type RoomManager[EntityID comparable, RoomID comparable, Entity generic.IdR[Enti
|
|||
rooms map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
|
||||
}
|
||||
```
|
||||
<span id="struct_RoomManager_AssumeControl"></span>
|
||||
|
||||
#### func (*RoomManager) AssumeControl(room Room, options ...*RoomControllerOptions[EntityID, RoomID, Entity, Room]) *RoomController[EntityID, RoomID, Entity, Room]
|
||||
> 将房间控制权交由 RoomManager 接管,返回 RoomController 实例
|
||||
> - 当任何房间需要被 RoomManager 管理时,都应该调用该方法获取到 RoomController 实例后进行操作
|
||||
> - 房间被接管后需要在释放房间控制权时调用 RoomController.Destroy 方法,否则将会导致 RoomManager 一直持有房间资源
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -228,31 +345,55 @@ func ExampleRoomManager_AssumeControl() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_DestroyRoom"></span>
|
||||
|
||||
#### func (*RoomManager) DestroyRoom(id RoomID)
|
||||
> 销毁房间,该函数为 RoomController.Destroy 的快捷方式
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_GetRoom"></span>
|
||||
|
||||
#### func (*RoomManager) GetRoom(id RoomID) *RoomController[EntityID, RoomID, Entity, Room]
|
||||
> 通过房间 ID 获取对应房间的控制器 RoomController,当房间不存在时将返回 nil
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_GetRooms"></span>
|
||||
|
||||
#### func (*RoomManager) GetRooms() map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
|
||||
> 获取包含所有房间 ID 到对应控制器 RoomController 的映射
|
||||
> - 返回值的 map 为拷贝对象,可安全的对其进行增删等操作
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_GetRoomCount"></span>
|
||||
|
||||
#### func (*RoomManager) GetRoomCount() int
|
||||
> 获取房间管理器接管的房间数量
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_GetRoomIDs"></span>
|
||||
|
||||
#### func (*RoomManager) GetRoomIDs() []RoomID
|
||||
> 获取房间管理器接管的所有房间 ID
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_HasEntity"></span>
|
||||
|
||||
#### func (*RoomManager) HasEntity(entityId EntityID) bool
|
||||
> 判断特定对象是否在任一房间中,当对象不在任一房间中时将返回 false
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_GetEntityRooms"></span>
|
||||
|
||||
#### func (*RoomManager) GetEntityRooms(entityId EntityID) map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
|
||||
> 获取特定对象所在的房间,返回值为房间 ID 到对应控制器 RoomController 的映射
|
||||
> - 由于一个对象可能在多个房间中,因此返回值为 map 类型
|
||||
|
||||
***
|
||||
<span id="struct_RoomManager_Broadcast"></span>
|
||||
|
||||
#### func (*RoomManager) Broadcast(handler func ( Entity), conditions ...func ( Entity) bool)
|
||||
> 向所有房间对象广播消息,该方法将会遍历所有房间控制器并调用 RoomController.Broadcast 方法
|
||||
|
||||
***
|
||||
<span id="struct_RoomAssumeControlEventHandle"></span>
|
||||
### RoomAssumeControlEventHandle `STRUCT`
|
||||
|
@ -271,14 +412,23 @@ type RoomControllerOptions[EntityID comparable, RoomID comparable, Entity generi
|
|||
ownerInheritHandler func(controller *RoomController[EntityID, RoomID, Entity, Room]) *EntityID
|
||||
}
|
||||
```
|
||||
<span id="struct_RoomControllerOptions_WithOwnerInherit"></span>
|
||||
|
||||
#### func (*RoomControllerOptions) WithOwnerInherit(inherit bool, inheritHandler ...func (controller *RoomController[EntityID, RoomID, Entity, Room]) *EntityID) *RoomControllerOptions[EntityID, RoomID, Entity, Room]
|
||||
> 设置房间所有者是否继承,默认为 false
|
||||
> - inherit: 是否继承,当未设置 inheritHandler 且 inherit 为 true 时,将会按照随机或根据座位号顺序继承房间所有者
|
||||
> - inheritHandler: 继承处理函数,当 inherit 为 true 时,该函数将会被调用,传入当前房间中的所有实体,返回值为新的房间所有者
|
||||
|
||||
***
|
||||
<span id="struct_RoomControllerOptions_WithMaxEntityCount"></span>
|
||||
|
||||
#### func (*RoomControllerOptions) WithMaxEntityCount(maxEntityCount int) *RoomControllerOptions[EntityID, RoomID, Entity, Room]
|
||||
> 设置房间最大实体数量
|
||||
|
||||
***
|
||||
<span id="struct_RoomControllerOptions_WithPassword"></span>
|
||||
|
||||
#### func (*RoomControllerOptions) WithPassword(password string) *RoomControllerOptions[EntityID, RoomID, Entity, Room]
|
||||
> 设置房间密码
|
||||
|
||||
***
|
||||
|
|
|
@ -156,71 +156,137 @@ func TestCond(t *testing.T) {
|
|||
```go
|
||||
type Condition map[any]any
|
||||
```
|
||||
<span id="struct_Condition_Cond"></span>
|
||||
|
||||
#### func (Condition) Cond(k any, v any) Condition
|
||||
> 创建任务条件
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetString"></span>
|
||||
|
||||
#### func (Condition) GetString(key any) string
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetInt"></span>
|
||||
|
||||
#### func (Condition) GetInt(key any) int
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetInt8"></span>
|
||||
|
||||
#### func (Condition) GetInt8(key any) int8
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetInt16"></span>
|
||||
|
||||
#### func (Condition) GetInt16(key any) int16
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetInt32"></span>
|
||||
|
||||
#### func (Condition) GetInt32(key any) int32
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetInt64"></span>
|
||||
|
||||
#### func (Condition) GetInt64(key any) int64
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetUint"></span>
|
||||
|
||||
#### func (Condition) GetUint(key any) uint
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetUint8"></span>
|
||||
|
||||
#### func (Condition) GetUint8(key any) uint8
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetUint16"></span>
|
||||
|
||||
#### func (Condition) GetUint16(key any) uint16
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetUint32"></span>
|
||||
|
||||
#### func (Condition) GetUint32(key any) uint32
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetUint64"></span>
|
||||
|
||||
#### func (Condition) GetUint64(key any) uint64
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetFloat32"></span>
|
||||
|
||||
#### func (Condition) GetFloat32(key any) float32
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetFloat64"></span>
|
||||
|
||||
#### func (Condition) GetFloat64(key any) float64
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetBool"></span>
|
||||
|
||||
#### func (Condition) GetBool(key any) bool
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetTime"></span>
|
||||
|
||||
#### func (Condition) GetTime(key any) time.Time
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetDuration"></span>
|
||||
|
||||
#### func (Condition) GetDuration(key any) time.Duration
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetByte"></span>
|
||||
|
||||
#### func (Condition) GetByte(key any) byte
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetBytes"></span>
|
||||
|
||||
#### func (Condition) GetBytes(key any) []byte
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetRune"></span>
|
||||
|
||||
#### func (Condition) GetRune(key any) rune
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetRunes"></span>
|
||||
|
||||
#### func (Condition) GetRunes(key any) []rune
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_Condition_GetAny"></span>
|
||||
|
||||
#### func (Condition) GetAny(key any) any
|
||||
> 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
|
||||
|
||||
***
|
||||
<span id="struct_RefreshTaskCounterEventHandler"></span>
|
||||
### RefreshTaskCounterEventHandler `STRUCT`
|
||||
|
@ -240,7 +306,10 @@ type Option func(task *Task)
|
|||
```go
|
||||
type Status byte
|
||||
```
|
||||
<span id="struct_Status_String"></span>
|
||||
|
||||
#### func (Status) String() string
|
||||
|
||||
***
|
||||
<span id="struct_Task"></span>
|
||||
### Task `STRUCT`
|
||||
|
@ -259,33 +328,60 @@ type Task struct {
|
|||
LimitedDuration time.Duration
|
||||
}
|
||||
```
|
||||
<span id="struct_Task_IsComplete"></span>
|
||||
|
||||
#### func (*Task) IsComplete() bool
|
||||
> 判断任务是否已完成
|
||||
|
||||
***
|
||||
<span id="struct_Task_IsFailed"></span>
|
||||
|
||||
#### func (*Task) IsFailed() bool
|
||||
> 判断任务是否已失败
|
||||
|
||||
***
|
||||
<span id="struct_Task_IsReward"></span>
|
||||
|
||||
#### func (*Task) IsReward() bool
|
||||
> 判断任务是否已领取奖励
|
||||
|
||||
***
|
||||
<span id="struct_Task_ReceiveReward"></span>
|
||||
|
||||
#### func (*Task) ReceiveReward() bool
|
||||
> 领取任务奖励,当任务状态为已完成时,才能领取奖励,此时返回 true,并且任务状态变更为已领取奖励
|
||||
|
||||
***
|
||||
<span id="struct_Task_IncrementCounter"></span>
|
||||
|
||||
#### func (*Task) IncrementCounter(incr int64) *Task
|
||||
> 增加计数器的值,当 incr 为负数时,计数器的值不会发生变化
|
||||
> - 如果需要溢出计数器,可通过 WithOverflowCounter 设置可溢出的任务计数器
|
||||
|
||||
***
|
||||
<span id="struct_Task_DecrementCounter"></span>
|
||||
|
||||
#### func (*Task) DecrementCounter(decr int64) *Task
|
||||
> 减少计数器的值,当 decr 为负数时,计数器的值不会发生变化
|
||||
|
||||
***
|
||||
<span id="struct_Task_AssignConditionValueAndRefresh"></span>
|
||||
|
||||
#### func (*Task) AssignConditionValueAndRefresh(key any, value any) *Task
|
||||
> 分配条件值并刷新任务状态
|
||||
|
||||
***
|
||||
<span id="struct_Task_AssignConditionValueAndRefreshByCondition"></span>
|
||||
|
||||
#### func (*Task) AssignConditionValueAndRefreshByCondition(condition Condition) *Task
|
||||
> 分配条件值并刷新任务状态
|
||||
|
||||
***
|
||||
<span id="struct_Task_ResetStatus"></span>
|
||||
|
||||
#### func (*Task) ResetStatus() *Task
|
||||
> 重置任务状态
|
||||
> - 该函数会将任务状态重置为已接受状态后,再刷新任务状态
|
||||
> - 当任务条件变更,例如任务计数要求为 10,已经完成的情况下,将任务计数要求变更为 5 或 20,此时任务状态由于是已完成或已领取状态,不会自动刷新,需要调用该函数刷新任务状态
|
||||
|
||||
***
|
||||
|
|
|
@ -47,11 +47,17 @@ type Manager struct {
|
|||
closeChannel chan struct{}
|
||||
}
|
||||
```
|
||||
<span id="struct_Manager_PushNotify"></span>
|
||||
|
||||
#### func (*Manager) PushNotify(notify Notify)
|
||||
> 推送通知
|
||||
|
||||
***
|
||||
<span id="struct_Manager_Release"></span>
|
||||
|
||||
#### func (*Manager) Release()
|
||||
> 释放通知管理器
|
||||
|
||||
***
|
||||
<span id="struct_Notify"></span>
|
||||
### Notify `INTERFACE`
|
||||
|
|
|
@ -156,8 +156,11 @@ type FeiShu struct {
|
|||
MsgType string
|
||||
}
|
||||
```
|
||||
<span id="struct_FeiShu_Format"></span>
|
||||
|
||||
#### func (*FeiShu) Format() ( string, error)
|
||||
> 格式化通知内容
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuMessage"></span>
|
||||
### FeiShuMessage `STRUCT`
|
||||
|
@ -173,8 +176,11 @@ type FeiShuRichText struct {
|
|||
content map[string]*FeiShuRichTextContent
|
||||
}
|
||||
```
|
||||
<span id="struct_FeiShuRichText_Create"></span>
|
||||
|
||||
#### func (*FeiShuRichText) Create(lang string, title string) *FeiShuRichTextContent
|
||||
> 创建一个特定语言和标题的富文本内容
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent"></span>
|
||||
### FeiShuRichTextContent `STRUCT`
|
||||
|
@ -186,45 +192,75 @@ type FeiShuRichTextContent struct {
|
|||
Content [][]map[string]any
|
||||
}
|
||||
```
|
||||
<span id="struct_FeiShuRichTextContent_AddText"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddText(text string, styles ...string) *FeiShuRichTextContent
|
||||
> 添加文本
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddUnescapeText"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddUnescapeText(text string, styles ...string) *FeiShuRichTextContent
|
||||
> 添加 unescape 解码的文本
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddLink"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddLink(text string, href string, styles ...string) *FeiShuRichTextContent
|
||||
> 添加超链接文本
|
||||
> - 请确保链接地址的合法性,否则消息会发送失败
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddAt"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddAt(userId string, styles ...string) *FeiShuRichTextContent
|
||||
> 添加@的用户
|
||||
> - @单个用户时,userId 字段必须是有效值
|
||||
> - @所有人填"all"。
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddAtWithUsername"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddAtWithUsername(userId string, username string, styles ...string) *FeiShuRichTextContent
|
||||
> 添加包含用户名的@用户
|
||||
> - @单个用户时,userId 字段必须是有效值
|
||||
> - @所有人填"all"。
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddImg"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddImg(imageKey string) *FeiShuRichTextContent
|
||||
> 添加图片
|
||||
> - imageKey 表示图片的唯一标识,可通过上传图片接口获取
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddMedia"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddMedia(fileKey string) *FeiShuRichTextContent
|
||||
> 添加视频
|
||||
> - fileKey 表示视频文件的唯一标识,可通过上传文件接口获取
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddMediaWithCover"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddMediaWithCover(fileKey string, imageKey string) *FeiShuRichTextContent
|
||||
> 添加包含封面的视频
|
||||
> - fileKey 表示视频文件的唯一标识,可通过上传文件接口获取
|
||||
> - imageKey 表示图片的唯一标识,可通过上传图片接口获取
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_AddEmotion"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) AddEmotion(emojiType string) *FeiShuRichTextContent
|
||||
> 添加表情
|
||||
> - emojiType 表示表情类型,部分可选值请参见表情文案。
|
||||
>
|
||||
> 表情文案:https://open.feishu.cn/document/server-docs/im-v1/message-reaction/emojis-introduce
|
||||
|
||||
***
|
||||
<span id="struct_FeiShuRichTextContent_Ok"></span>
|
||||
|
||||
#### func (*FeiShuRichTextContent) Ok() *FeiShuRichText
|
||||
> 确认完成,将返回 FeiShuRichText 可继续创建多语言富文本
|
||||
|
||||
***
|
||||
|
|
|
@ -44,8 +44,11 @@ type FeiShu struct {
|
|||
webhook string
|
||||
}
|
||||
```
|
||||
<span id="struct_FeiShu_Push"></span>
|
||||
|
||||
#### func (*FeiShu) Push(notify notify.Notify) error
|
||||
> 推送通知
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -53,7 +56,7 @@ type FeiShu struct {
|
|||
```go
|
||||
|
||||
func TestFeiShu_Push(t *testing.T) {
|
||||
fs := NewFeiShu("https://open.feishu.cn/open-apis/bot/v2/hook/d886f30f-814c-47b1-aeb0-b508da0f7f22")
|
||||
fs := NewFeiShu("https://open.feishu.cn/open-apis/bot/v2/hook/bid")
|
||||
rt := notifies.NewFeiShu(notifies.FeiShuMessageWithRichText(notifies.NewFeiShuRichText().Create("zh_cn", "标题咯").AddText("哈哈哈").Ok()))
|
||||
if err := fs.Push(rt); err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -135,11 +135,17 @@ type DataTmpl interface {
|
|||
```go
|
||||
type Exporter struct{}
|
||||
```
|
||||
<span id="struct_Exporter_ExportStruct"></span>
|
||||
|
||||
#### func (*Exporter) ExportStruct(tmpl Tmpl, tmplStruct ...*TmplStruct) ( []byte, error)
|
||||
> 导出结构
|
||||
|
||||
***
|
||||
<span id="struct_Exporter_ExportData"></span>
|
||||
|
||||
#### func (*Exporter) ExportData(tmpl DataTmpl, data map[any]any) ( []byte, error)
|
||||
> 导出数据
|
||||
|
||||
***
|
||||
<span id="struct_Field"></span>
|
||||
### Field `INTERFACE`
|
||||
|
@ -157,11 +163,20 @@ type Field interface {
|
|||
```go
|
||||
type Int int
|
||||
```
|
||||
<span id="struct_Int_TypeName"></span>
|
||||
|
||||
#### func (Int) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Int_Zero"></span>
|
||||
|
||||
#### func (Int) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Int_Parse"></span>
|
||||
|
||||
#### func (Int) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Int8"></span>
|
||||
### Int8 `STRUCT`
|
||||
|
@ -169,11 +184,20 @@ type Int int
|
|||
```go
|
||||
type Int8 int8
|
||||
```
|
||||
<span id="struct_Int8_TypeName"></span>
|
||||
|
||||
#### func (Int8) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Int8_Zero"></span>
|
||||
|
||||
#### func (Int8) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Int8_Parse"></span>
|
||||
|
||||
#### func (Int8) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Int16"></span>
|
||||
### Int16 `STRUCT`
|
||||
|
@ -181,11 +205,20 @@ type Int8 int8
|
|||
```go
|
||||
type Int16 int16
|
||||
```
|
||||
<span id="struct_Int16_TypeName"></span>
|
||||
|
||||
#### func (Int16) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Int16_Zero"></span>
|
||||
|
||||
#### func (Int16) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Int16_Parse"></span>
|
||||
|
||||
#### func (Int16) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Int32"></span>
|
||||
### Int32 `STRUCT`
|
||||
|
@ -193,11 +226,20 @@ type Int16 int16
|
|||
```go
|
||||
type Int32 int32
|
||||
```
|
||||
<span id="struct_Int32_TypeName"></span>
|
||||
|
||||
#### func (Int32) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Int32_Zero"></span>
|
||||
|
||||
#### func (Int32) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Int32_Parse"></span>
|
||||
|
||||
#### func (Int32) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Int64"></span>
|
||||
### Int64 `STRUCT`
|
||||
|
@ -205,11 +247,20 @@ type Int32 int32
|
|||
```go
|
||||
type Int64 int64
|
||||
```
|
||||
<span id="struct_Int64_TypeName"></span>
|
||||
|
||||
#### func (Int64) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Int64_Zero"></span>
|
||||
|
||||
#### func (Int64) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Int64_Parse"></span>
|
||||
|
||||
#### func (Int64) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uint"></span>
|
||||
### Uint `STRUCT`
|
||||
|
@ -217,11 +268,20 @@ type Int64 int64
|
|||
```go
|
||||
type Uint uint
|
||||
```
|
||||
<span id="struct_Uint_TypeName"></span>
|
||||
|
||||
#### func (Uint) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uint_Zero"></span>
|
||||
|
||||
#### func (Uint) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uint_Parse"></span>
|
||||
|
||||
#### func (Uint) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uint8"></span>
|
||||
### Uint8 `STRUCT`
|
||||
|
@ -229,11 +289,20 @@ type Uint uint
|
|||
```go
|
||||
type Uint8 uint8
|
||||
```
|
||||
<span id="struct_Uint8_TypeName"></span>
|
||||
|
||||
#### func (Uint8) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uint8_Zero"></span>
|
||||
|
||||
#### func (Uint8) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uint8_Parse"></span>
|
||||
|
||||
#### func (Uint8) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uint16"></span>
|
||||
### Uint16 `STRUCT`
|
||||
|
@ -241,11 +310,20 @@ type Uint8 uint8
|
|||
```go
|
||||
type Uint16 uint16
|
||||
```
|
||||
<span id="struct_Uint16_TypeName"></span>
|
||||
|
||||
#### func (Uint16) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uint16_Zero"></span>
|
||||
|
||||
#### func (Uint16) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uint16_Parse"></span>
|
||||
|
||||
#### func (Uint16) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uint32"></span>
|
||||
### Uint32 `STRUCT`
|
||||
|
@ -253,11 +331,20 @@ type Uint16 uint16
|
|||
```go
|
||||
type Uint32 uint32
|
||||
```
|
||||
<span id="struct_Uint32_TypeName"></span>
|
||||
|
||||
#### func (Uint32) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uint32_Zero"></span>
|
||||
|
||||
#### func (Uint32) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uint32_Parse"></span>
|
||||
|
||||
#### func (Uint32) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uint64"></span>
|
||||
### Uint64 `STRUCT`
|
||||
|
@ -265,11 +352,20 @@ type Uint32 uint32
|
|||
```go
|
||||
type Uint64 uint64
|
||||
```
|
||||
<span id="struct_Uint64_TypeName"></span>
|
||||
|
||||
#### func (Uint64) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uint64_Zero"></span>
|
||||
|
||||
#### func (Uint64) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uint64_Parse"></span>
|
||||
|
||||
#### func (Uint64) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Float32"></span>
|
||||
### Float32 `STRUCT`
|
||||
|
@ -277,11 +373,20 @@ type Uint64 uint64
|
|||
```go
|
||||
type Float32 float32
|
||||
```
|
||||
<span id="struct_Float32_TypeName"></span>
|
||||
|
||||
#### func (Float32) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Float32_Zero"></span>
|
||||
|
||||
#### func (Float32) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Float32_Parse"></span>
|
||||
|
||||
#### func (Float32) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Float64"></span>
|
||||
### Float64 `STRUCT`
|
||||
|
@ -289,11 +394,20 @@ type Float32 float32
|
|||
```go
|
||||
type Float64 float64
|
||||
```
|
||||
<span id="struct_Float64_TypeName"></span>
|
||||
|
||||
#### func (Float64) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Float64_Zero"></span>
|
||||
|
||||
#### func (Float64) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Float64_Parse"></span>
|
||||
|
||||
#### func (Float64) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_String"></span>
|
||||
### String `STRUCT`
|
||||
|
@ -301,11 +415,20 @@ type Float64 float64
|
|||
```go
|
||||
type String string
|
||||
```
|
||||
<span id="struct_String_TypeName"></span>
|
||||
|
||||
#### func (String) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_String_Zero"></span>
|
||||
|
||||
#### func (String) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_String_Parse"></span>
|
||||
|
||||
#### func (String) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Bool"></span>
|
||||
### Bool `STRUCT`
|
||||
|
@ -313,11 +436,20 @@ type String string
|
|||
```go
|
||||
type Bool bool
|
||||
```
|
||||
<span id="struct_Bool_TypeName"></span>
|
||||
|
||||
#### func (Bool) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Bool_Zero"></span>
|
||||
|
||||
#### func (Bool) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Bool_Parse"></span>
|
||||
|
||||
#### func (Bool) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Byte"></span>
|
||||
### Byte `STRUCT`
|
||||
|
@ -325,11 +457,20 @@ type Bool bool
|
|||
```go
|
||||
type Byte byte
|
||||
```
|
||||
<span id="struct_Byte_TypeName"></span>
|
||||
|
||||
#### func (Byte) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Byte_Zero"></span>
|
||||
|
||||
#### func (Byte) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Byte_Parse"></span>
|
||||
|
||||
#### func (Byte) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Rune"></span>
|
||||
### Rune `STRUCT`
|
||||
|
@ -337,11 +478,20 @@ type Byte byte
|
|||
```go
|
||||
type Rune rune
|
||||
```
|
||||
<span id="struct_Rune_TypeName"></span>
|
||||
|
||||
#### func (Rune) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Rune_Zero"></span>
|
||||
|
||||
#### func (Rune) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Rune_Parse"></span>
|
||||
|
||||
#### func (Rune) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Complex64"></span>
|
||||
### Complex64 `STRUCT`
|
||||
|
@ -349,11 +499,20 @@ type Rune rune
|
|||
```go
|
||||
type Complex64 complex64
|
||||
```
|
||||
<span id="struct_Complex64_TypeName"></span>
|
||||
|
||||
#### func (Complex64) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Complex64_Zero"></span>
|
||||
|
||||
#### func (Complex64) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Complex64_Parse"></span>
|
||||
|
||||
#### func (Complex64) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Complex128"></span>
|
||||
### Complex128 `STRUCT`
|
||||
|
@ -361,11 +520,20 @@ type Complex64 complex64
|
|||
```go
|
||||
type Complex128 complex128
|
||||
```
|
||||
<span id="struct_Complex128_TypeName"></span>
|
||||
|
||||
#### func (Complex128) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Complex128_Zero"></span>
|
||||
|
||||
#### func (Complex128) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Complex128_Parse"></span>
|
||||
|
||||
#### func (Complex128) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Uintptr"></span>
|
||||
### Uintptr `STRUCT`
|
||||
|
@ -373,11 +541,20 @@ type Complex128 complex128
|
|||
```go
|
||||
type Uintptr uintptr
|
||||
```
|
||||
<span id="struct_Uintptr_TypeName"></span>
|
||||
|
||||
#### func (Uintptr) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Uintptr_Zero"></span>
|
||||
|
||||
#### func (Uintptr) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Uintptr_Parse"></span>
|
||||
|
||||
#### func (Uintptr) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Double"></span>
|
||||
### Double `STRUCT`
|
||||
|
@ -385,11 +562,20 @@ type Uintptr uintptr
|
|||
```go
|
||||
type Double float64
|
||||
```
|
||||
<span id="struct_Double_TypeName"></span>
|
||||
|
||||
#### func (Double) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Double_Zero"></span>
|
||||
|
||||
#### func (Double) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Double_Parse"></span>
|
||||
|
||||
#### func (Double) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Float"></span>
|
||||
### Float `STRUCT`
|
||||
|
@ -397,11 +583,20 @@ type Double float64
|
|||
```go
|
||||
type Float float32
|
||||
```
|
||||
<span id="struct_Float_TypeName"></span>
|
||||
|
||||
#### func (Float) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Float_Zero"></span>
|
||||
|
||||
#### func (Float) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Float_Parse"></span>
|
||||
|
||||
#### func (Float) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Long"></span>
|
||||
### Long `STRUCT`
|
||||
|
@ -409,11 +604,20 @@ type Float float32
|
|||
```go
|
||||
type Long int64
|
||||
```
|
||||
<span id="struct_Long_TypeName"></span>
|
||||
|
||||
#### func (Long) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Long_Zero"></span>
|
||||
|
||||
#### func (Long) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Long_Parse"></span>
|
||||
|
||||
#### func (Long) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Short"></span>
|
||||
### Short `STRUCT`
|
||||
|
@ -421,11 +625,20 @@ type Long int64
|
|||
```go
|
||||
type Short int16
|
||||
```
|
||||
<span id="struct_Short_TypeName"></span>
|
||||
|
||||
#### func (Short) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Short_Zero"></span>
|
||||
|
||||
#### func (Short) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Short_Parse"></span>
|
||||
|
||||
#### func (Short) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Char"></span>
|
||||
### Char `STRUCT`
|
||||
|
@ -433,11 +646,20 @@ type Short int16
|
|||
```go
|
||||
type Char int8
|
||||
```
|
||||
<span id="struct_Char_TypeName"></span>
|
||||
|
||||
#### func (Char) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Char_Zero"></span>
|
||||
|
||||
#### func (Char) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Char_Parse"></span>
|
||||
|
||||
#### func (Char) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Number"></span>
|
||||
### Number `STRUCT`
|
||||
|
@ -445,11 +667,20 @@ type Char int8
|
|||
```go
|
||||
type Number float64
|
||||
```
|
||||
<span id="struct_Number_TypeName"></span>
|
||||
|
||||
#### func (Number) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Number_Zero"></span>
|
||||
|
||||
#### func (Number) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Number_Parse"></span>
|
||||
|
||||
#### func (Number) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Integer"></span>
|
||||
### Integer `STRUCT`
|
||||
|
@ -457,11 +688,20 @@ type Number float64
|
|||
```go
|
||||
type Integer int64
|
||||
```
|
||||
<span id="struct_Integer_TypeName"></span>
|
||||
|
||||
#### func (Integer) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Integer_Zero"></span>
|
||||
|
||||
#### func (Integer) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Integer_Parse"></span>
|
||||
|
||||
#### func (Integer) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Boolean"></span>
|
||||
### Boolean `STRUCT`
|
||||
|
@ -469,11 +709,20 @@ type Integer int64
|
|||
```go
|
||||
type Boolean bool
|
||||
```
|
||||
<span id="struct_Boolean_TypeName"></span>
|
||||
|
||||
#### func (Boolean) TypeName() string
|
||||
|
||||
***
|
||||
<span id="struct_Boolean_Zero"></span>
|
||||
|
||||
#### func (Boolean) Zero() any
|
||||
|
||||
***
|
||||
<span id="struct_Boolean_Parse"></span>
|
||||
|
||||
#### func (Boolean) Parse(value string) any
|
||||
|
||||
***
|
||||
<span id="struct_Loader"></span>
|
||||
### Loader `STRUCT`
|
||||
|
@ -483,11 +732,17 @@ type Loader struct {
|
|||
fields map[string]Field
|
||||
}
|
||||
```
|
||||
<span id="struct_Loader_LoadStruct"></span>
|
||||
|
||||
#### func (*Loader) LoadStruct(config Config) *TmplStruct
|
||||
> 加载结构
|
||||
|
||||
***
|
||||
<span id="struct_Loader_LoadData"></span>
|
||||
|
||||
#### func (*Loader) LoadData(config Config) map[any]any
|
||||
> 加载配置并得到配置数据
|
||||
|
||||
***
|
||||
<span id="struct_DataInfo"></span>
|
||||
### DataInfo `STRUCT`
|
||||
|
@ -532,14 +787,23 @@ type TmplField struct {
|
|||
isIndex bool
|
||||
}
|
||||
```
|
||||
<span id="struct_TmplField_IsIndex"></span>
|
||||
|
||||
#### func (*TmplField) IsIndex() bool
|
||||
> 是否是索引字段
|
||||
|
||||
***
|
||||
<span id="struct_TmplField_IsStruct"></span>
|
||||
|
||||
#### func (*TmplField) IsStruct() bool
|
||||
> 是否是结构类型
|
||||
|
||||
***
|
||||
<span id="struct_TmplField_IsSlice"></span>
|
||||
|
||||
#### func (*TmplField) IsSlice() bool
|
||||
> 是否是切片类型
|
||||
|
||||
***
|
||||
<span id="struct_TmplStruct"></span>
|
||||
### TmplStruct `STRUCT`
|
||||
|
@ -552,6 +816,9 @@ type TmplStruct struct {
|
|||
IndexCount int
|
||||
}
|
||||
```
|
||||
<span id="struct_TmplStruct_AllChildren"></span>
|
||||
|
||||
#### func (*TmplStruct) AllChildren() []*TmplStruct
|
||||
> 获取所有子结构
|
||||
|
||||
***
|
||||
|
|
|
@ -50,15 +50,33 @@ type Xlsx struct {
|
|||
exportType XlsxExportType
|
||||
}
|
||||
```
|
||||
<span id="struct_Xlsx_GetConfigName"></span>
|
||||
|
||||
#### func (*Xlsx) GetConfigName() string
|
||||
|
||||
***
|
||||
<span id="struct_Xlsx_GetDisplayName"></span>
|
||||
|
||||
#### func (*Xlsx) GetDisplayName() string
|
||||
|
||||
***
|
||||
<span id="struct_Xlsx_GetDescription"></span>
|
||||
|
||||
#### func (*Xlsx) GetDescription() string
|
||||
|
||||
***
|
||||
<span id="struct_Xlsx_GetIndexCount"></span>
|
||||
|
||||
#### func (*Xlsx) GetIndexCount() int
|
||||
|
||||
***
|
||||
<span id="struct_Xlsx_GetFields"></span>
|
||||
|
||||
#### func (*Xlsx) GetFields() []pce.DataField
|
||||
|
||||
***
|
||||
<span id="struct_Xlsx_GetData"></span>
|
||||
|
||||
#### func (*Xlsx) GetData() [][]pce.DataInfo
|
||||
|
||||
***
|
||||
|
|
|
@ -50,13 +50,25 @@ type Golang struct {
|
|||
Templates []*pce.TmplStruct
|
||||
}
|
||||
```
|
||||
<span id="struct_Golang_Render"></span>
|
||||
|
||||
#### func (*Golang) Render(templates ...*pce.TmplStruct) ( string, error)
|
||||
|
||||
***
|
||||
<span id="struct_Golang_GetVariable"></span>
|
||||
|
||||
#### func (*Golang) GetVariable(config *pce.TmplStruct) string
|
||||
|
||||
***
|
||||
<span id="struct_Golang_GetConfigName"></span>
|
||||
|
||||
#### func (*Golang) GetConfigName(config *pce.TmplStruct) string
|
||||
|
||||
***
|
||||
<span id="struct_Golang_HasIndex"></span>
|
||||
|
||||
#### func (*Golang) HasIndex(config *pce.TmplStruct) bool
|
||||
|
||||
***
|
||||
<span id="struct_JSON"></span>
|
||||
### JSON `STRUCT`
|
||||
|
@ -66,5 +78,8 @@ type JSON struct {
|
|||
jsonIter.API
|
||||
}
|
||||
```
|
||||
<span id="struct_JSON_Render"></span>
|
||||
|
||||
#### func (*JSON) Render(data map[any]any) ( string, error)
|
||||
|
||||
***
|
||||
|
|
718
server/README.md
718
server/README.md
File diff suppressed because it is too large
Load Diff
|
@ -78,23 +78,38 @@ type Client struct {
|
|||
block chan struct{}
|
||||
}
|
||||
```
|
||||
<span id="struct_Client_Run"></span>
|
||||
|
||||
#### func (*Client) Run(block ...bool) error
|
||||
> 运行客户端,当客户端已运行时,会先关闭客户端再重新运行
|
||||
> - block 以阻塞方式运行
|
||||
|
||||
***
|
||||
<span id="struct_Client_RunByBufferSize"></span>
|
||||
|
||||
#### func (*Client) RunByBufferSize(size int, block ...bool) error
|
||||
> 指定写入循环缓冲区大小运行客户端,当客户端已运行时,会先关闭客户端再重新运行
|
||||
> - block 以阻塞方式运行
|
||||
|
||||
***
|
||||
<span id="struct_Client_IsConnected"></span>
|
||||
|
||||
#### func (*Client) IsConnected() bool
|
||||
> 是否已连接
|
||||
|
||||
***
|
||||
<span id="struct_Client_Close"></span>
|
||||
|
||||
#### func (*Client) Close(err ...error)
|
||||
> 关闭
|
||||
|
||||
***
|
||||
<span id="struct_Client_WriteWS"></span>
|
||||
|
||||
#### func (*Client) WriteWS(wst int, packet []byte, callback ...func (err error))
|
||||
> 向连接中写入指定 websocket 数据类型
|
||||
> - wst: websocket模式中指定消息类型
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -133,11 +148,17 @@ func TestClient_WriteWS(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Client_Write"></span>
|
||||
|
||||
#### func (*Client) Write(packet []byte, callback ...func (err error))
|
||||
> 向连接中写入数据
|
||||
|
||||
***
|
||||
<span id="struct_Client_GetServerAddr"></span>
|
||||
|
||||
#### func (*Client) GetServerAddr() string
|
||||
> 获取服务器地址
|
||||
|
||||
***
|
||||
<span id="struct_Core"></span>
|
||||
### Core `INTERFACE`
|
||||
|
@ -177,15 +198,30 @@ type TCP struct {
|
|||
closed bool
|
||||
}
|
||||
```
|
||||
<span id="struct_TCP_Run"></span>
|
||||
|
||||
#### func (*TCP) Run(runState chan error, receive func (wst int, packet []byte))
|
||||
|
||||
***
|
||||
<span id="struct_TCP_Write"></span>
|
||||
|
||||
#### func (*TCP) Write(packet *Packet) error
|
||||
|
||||
***
|
||||
<span id="struct_TCP_Close"></span>
|
||||
|
||||
#### func (*TCP) Close()
|
||||
|
||||
***
|
||||
<span id="struct_TCP_GetServerAddr"></span>
|
||||
|
||||
#### func (*TCP) GetServerAddr() string
|
||||
|
||||
***
|
||||
<span id="struct_TCP_Clone"></span>
|
||||
|
||||
#### func (*TCP) Clone() Core
|
||||
|
||||
***
|
||||
<span id="struct_UnixDomainSocket"></span>
|
||||
### UnixDomainSocket `STRUCT`
|
||||
|
@ -197,9 +233,15 @@ type UnixDomainSocket struct {
|
|||
closed bool
|
||||
}
|
||||
```
|
||||
<span id="struct_UnixDomainSocket_Run"></span>
|
||||
|
||||
#### func (*UnixDomainSocket) Run(runState chan error, receive func (wst int, packet []byte))
|
||||
|
||||
***
|
||||
<span id="struct_UnixDomainSocket_Write"></span>
|
||||
|
||||
#### func (*UnixDomainSocket) Write(packet *Packet) error
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -243,11 +285,20 @@ func TestUnixDomainSocket_Write(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_UnixDomainSocket_Close"></span>
|
||||
|
||||
#### func (*UnixDomainSocket) Close()
|
||||
|
||||
***
|
||||
<span id="struct_UnixDomainSocket_GetServerAddr"></span>
|
||||
|
||||
#### func (*UnixDomainSocket) GetServerAddr() string
|
||||
|
||||
***
|
||||
<span id="struct_UnixDomainSocket_Clone"></span>
|
||||
|
||||
#### func (*UnixDomainSocket) Clone() Core
|
||||
|
||||
***
|
||||
<span id="struct_Websocket"></span>
|
||||
### Websocket `STRUCT`
|
||||
|
@ -260,13 +311,28 @@ type Websocket struct {
|
|||
mu sync.Mutex
|
||||
}
|
||||
```
|
||||
<span id="struct_Websocket_Run"></span>
|
||||
|
||||
#### func (*Websocket) Run(runState chan error, receive func (wst int, packet []byte))
|
||||
|
||||
***
|
||||
<span id="struct_Websocket_Write"></span>
|
||||
|
||||
#### func (*Websocket) Write(packet *Packet) error
|
||||
|
||||
***
|
||||
<span id="struct_Websocket_Close"></span>
|
||||
|
||||
#### func (*Websocket) Close()
|
||||
|
||||
***
|
||||
<span id="struct_Websocket_GetServerAddr"></span>
|
||||
|
||||
#### func (*Websocket) GetServerAddr() string
|
||||
|
||||
***
|
||||
<span id="struct_Websocket_Clone"></span>
|
||||
|
||||
#### func (*Websocket) Clone() Core
|
||||
|
||||
***
|
||||
|
|
|
@ -129,18 +129,30 @@ type Endpoint struct {
|
|||
cps int
|
||||
}
|
||||
```
|
||||
<span id="struct_Endpoint_GetName"></span>
|
||||
|
||||
#### func (*Endpoint) GetName() string
|
||||
> 获取端点名称
|
||||
|
||||
***
|
||||
<span id="struct_Endpoint_GetAddress"></span>
|
||||
|
||||
#### func (*Endpoint) GetAddress() string
|
||||
> 获取端点地址
|
||||
|
||||
***
|
||||
<span id="struct_Endpoint_GetState"></span>
|
||||
|
||||
#### func (*Endpoint) GetState() float64
|
||||
> 获取端点健康值
|
||||
|
||||
***
|
||||
<span id="struct_Endpoint_Forward"></span>
|
||||
|
||||
#### func (*Endpoint) Forward(conn *server.Conn, packet []byte, callback ...func (err error))
|
||||
> 转发数据包到该端点
|
||||
> - 端点在处理数据包时,应区分数据包为普通直连数据包还是网关数据包。可通过 UnmarshalGatewayOutPacket 进行数据包解析,当解析失败且无其他数据包协议时,可认为该数据包为普通直连数据包。
|
||||
|
||||
***
|
||||
<span id="struct_EndpointOption"></span>
|
||||
### EndpointOption `STRUCT`
|
||||
|
@ -186,8 +198,11 @@ type Gateway struct {
|
|||
cceLock sync.RWMutex
|
||||
}
|
||||
```
|
||||
<span id="struct_Gateway_Run"></span>
|
||||
|
||||
#### func (*Gateway) Run(addr string) error
|
||||
> 运行网关
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -217,23 +232,38 @@ func TestGateway_Run(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Gateway_Shutdown"></span>
|
||||
|
||||
#### func (*Gateway) Shutdown()
|
||||
> 关闭网关
|
||||
|
||||
***
|
||||
<span id="struct_Gateway_Server"></span>
|
||||
|
||||
#### func (*Gateway) Server() *server.Server
|
||||
> 获取网关服务器核心
|
||||
|
||||
***
|
||||
<span id="struct_Gateway_GetEndpoint"></span>
|
||||
|
||||
#### func (*Gateway) GetEndpoint(name string) ( *Endpoint, error)
|
||||
> 获取一个可用的端点
|
||||
> - name: 端点名称
|
||||
|
||||
***
|
||||
<span id="struct_Gateway_GetConnEndpoint"></span>
|
||||
|
||||
#### func (*Gateway) GetConnEndpoint(name string, conn *server.Conn) ( *Endpoint, error)
|
||||
> 获取一个可用的端点,如果客户端已经连接到了某个端点,将优先返回该端点
|
||||
> - 当连接到的端点不可用或没有连接记录时,效果同 GetEndpoint 相同
|
||||
> - 当连接行为为有状态时,推荐使用该方法
|
||||
|
||||
***
|
||||
<span id="struct_Gateway_SwitchEndpoint"></span>
|
||||
|
||||
#### func (*Gateway) SwitchEndpoint(source *Endpoint, dest *Endpoint)
|
||||
> 将端点端点的所有连接切换到另一个端点
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
@ -250,7 +280,13 @@ type Scanner interface {
|
|||
GetInterval() time.Duration
|
||||
}
|
||||
```
|
||||
<span id="struct_Scanner_GetEndpoints"></span>
|
||||
|
||||
#### func (*Scanner) GetEndpoints() ( []*gateway.Endpoint, error)
|
||||
|
||||
***
|
||||
<span id="struct_Scanner_GetInterval"></span>
|
||||
|
||||
#### func (*Scanner) GetInterval() time.Duration
|
||||
|
||||
***
|
||||
|
|
|
@ -176,14 +176,23 @@ type Action[P Producer, M Message[P]] struct {
|
|||
d *Dispatcher[P, M]
|
||||
}
|
||||
```
|
||||
<span id="struct_Action_Name"></span>
|
||||
|
||||
#### func (*Action) Name() string
|
||||
> 获取消息分发器名称
|
||||
|
||||
***
|
||||
<span id="struct_Action_UnExpel"></span>
|
||||
|
||||
#### func (*Action) UnExpel()
|
||||
> 取消特定生产者的驱逐计划
|
||||
|
||||
***
|
||||
<span id="struct_Action_Expel"></span>
|
||||
|
||||
#### func (*Action) Expel()
|
||||
> 设置该消息分发器即将被驱逐,当消息分发器中没有任何消息时,会自动关闭
|
||||
|
||||
***
|
||||
<span id="struct_Handler"></span>
|
||||
### Handler `STRUCT`
|
||||
|
@ -221,11 +230,12 @@ type Dispatcher[P Producer, M Message[P]] struct {
|
|||
abort chan struct{}
|
||||
}
|
||||
```
|
||||
<span id="struct_Dispatcher_SetProducerDoneHandler"></span>
|
||||
|
||||
#### func (*Dispatcher) SetProducerDoneHandler(p P, handler func (p P, dispatcher *Action[P, M])) *Dispatcher[P, M]
|
||||
> 设置特定生产者所有消息处理完成时的回调函数
|
||||
> 设置特定生产者的所有消息处理完成时的回调函数
|
||||
> - 如果 handler 为 nil,则会删除该生产者的回调函数
|
||||
>
|
||||
> 需要注意的是,该 handler 中
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -271,8 +281,11 @@ func TestDispatcher_SetProducerDoneHandler(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_SetClosedHandler"></span>
|
||||
|
||||
#### func (*Dispatcher) SetClosedHandler(handler func (dispatcher *Action[P, M])) *Dispatcher[P, M]
|
||||
> 设置消息分发器关闭时的回调函数
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -319,8 +332,11 @@ func TestDispatcher_SetClosedHandler(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Name"></span>
|
||||
|
||||
#### func (*Dispatcher) Name() string
|
||||
> 获取消息分发器名称
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -348,14 +364,23 @@ func TestDispatcher_Name(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Unique"></span>
|
||||
|
||||
#### func (*Dispatcher) Unique(name string) bool
|
||||
> 设置唯一消息键,返回是否已存在
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_AntiUnique"></span>
|
||||
|
||||
#### func (*Dispatcher) AntiUnique(name string)
|
||||
> 取消唯一消息键
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Expel"></span>
|
||||
|
||||
#### func (*Dispatcher) Expel()
|
||||
> 设置该消息分发器即将被驱逐,当消息分发器中没有任何消息时,会自动关闭
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -402,8 +427,11 @@ func TestDispatcher_Expel(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_UnExpel"></span>
|
||||
|
||||
#### func (*Dispatcher) UnExpel()
|
||||
> 取消特定生产者的驱逐计划
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -452,12 +480,18 @@ func TestDispatcher_UnExpel(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_IncrCount"></span>
|
||||
|
||||
#### func (*Dispatcher) IncrCount(producer P, i int64)
|
||||
> 主动增量设置特定生产者的消息计数,这在等待异步消息完成后再关闭消息分发器时非常有用
|
||||
> - 如果 i 为负数,则会减少消息计数
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Put"></span>
|
||||
|
||||
#### func (*Dispatcher) Put(message M)
|
||||
> 将消息放入分发器
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -498,8 +532,11 @@ func TestDispatcher_Put(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Start"></span>
|
||||
|
||||
#### func (*Dispatcher) Start() *Dispatcher[P, M]
|
||||
> 以非阻塞的方式开始进行消息分发,当消息分发器中没有任何消息并且处于驱逐计划 Expel 时,将会自动关闭
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -540,8 +577,11 @@ func TestDispatcher_Start(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Dispatcher_Closed"></span>
|
||||
|
||||
#### func (*Dispatcher) Closed() bool
|
||||
> 判断消息分发器是否已关闭
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -594,11 +634,17 @@ type Manager[P Producer, M Message[P]] struct {
|
|||
createdHandler func(name string)
|
||||
}
|
||||
```
|
||||
<span id="struct_Manager_Wait"></span>
|
||||
|
||||
#### func (*Manager) Wait()
|
||||
> 等待所有消息分发器关闭
|
||||
|
||||
***
|
||||
<span id="struct_Manager_SetDispatcherClosedHandler"></span>
|
||||
|
||||
#### func (*Manager) SetDispatcherClosedHandler(handler func (name string)) *Manager[P, M]
|
||||
> 设置消息分发器关闭时的回调函数
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -637,8 +683,11 @@ func TestManager_SetDispatcherClosedHandler(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_SetDispatcherCreatedHandler"></span>
|
||||
|
||||
#### func (*Manager) SetDispatcherCreatedHandler(handler func (name string)) *Manager[P, M]
|
||||
> 设置消息分发器创建时的回调函数
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -677,8 +726,11 @@ func TestManager_SetDispatcherCreatedHandler(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_HasDispatcher"></span>
|
||||
|
||||
#### func (*Manager) HasDispatcher(name string) bool
|
||||
> 检查是否存在指定名称的消息分发器
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -714,8 +766,11 @@ func TestManager_HasDispatcher(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_GetDispatcherNum"></span>
|
||||
|
||||
#### func (*Manager) GetDispatcherNum() int
|
||||
> 获取当前正在工作的消息分发器数量
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -758,8 +813,11 @@ func TestManager_GetDispatcherNum(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_GetSystemDispatcher"></span>
|
||||
|
||||
#### func (*Manager) GetSystemDispatcher() *Dispatcher[P, M]
|
||||
> 获取系统消息分发器
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -786,8 +844,11 @@ func TestManager_GetSystemDispatcher(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_GetDispatcher"></span>
|
||||
|
||||
#### func (*Manager) GetDispatcher(p P) *Dispatcher[P, M]
|
||||
> 获取生产者正在使用的消息分发器,如果生产者没有绑定消息分发器,则会返回系统消息分发器
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -818,8 +879,11 @@ func TestManager_GetDispatcher(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_BindProducer"></span>
|
||||
|
||||
#### func (*Manager) BindProducer(p P, name string)
|
||||
> 绑定生产者使用特定的消息分发器,如果生产者已经绑定了消息分发器,则会先解绑
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -850,8 +914,11 @@ func TestManager_BindProducer(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Manager_UnBindProducer"></span>
|
||||
|
||||
#### func (*Manager) UnBindProducer(p P)
|
||||
> 解绑生产者使用特定的消息分发器
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
|
|
@ -30,7 +30,10 @@
|
|||
```go
|
||||
type Ants struct{}
|
||||
```
|
||||
<span id="struct_Ants_Printf"></span>
|
||||
|
||||
#### func (*Ants) Printf(format string, args ...interface {})
|
||||
|
||||
***
|
||||
<span id="struct_GNet"></span>
|
||||
### GNet `STRUCT`
|
||||
|
@ -38,13 +41,28 @@ type Ants struct{}
|
|||
```go
|
||||
type GNet struct{}
|
||||
```
|
||||
<span id="struct_GNet_Debugf"></span>
|
||||
|
||||
#### func (*GNet) Debugf(format string, args ...interface {})
|
||||
|
||||
***
|
||||
<span id="struct_GNet_Infof"></span>
|
||||
|
||||
#### func (*GNet) Infof(format string, args ...interface {})
|
||||
|
||||
***
|
||||
<span id="struct_GNet_Warnf"></span>
|
||||
|
||||
#### func (*GNet) Warnf(format string, args ...interface {})
|
||||
|
||||
***
|
||||
<span id="struct_GNet_Errorf"></span>
|
||||
|
||||
#### func (*GNet) Errorf(format string, args ...interface {})
|
||||
|
||||
***
|
||||
<span id="struct_GNet_Fatalf"></span>
|
||||
|
||||
#### func (*GNet) Fatalf(format string, args ...interface {})
|
||||
|
||||
***
|
||||
|
|
|
@ -152,58 +152,106 @@ type Lockstep[ClientID comparable, Command any] struct {
|
|||
lockstepStoppedEventHandles []StoppedEventHandle[ClientID, Command]
|
||||
}
|
||||
```
|
||||
<span id="struct_Lockstep_JoinClient"></span>
|
||||
|
||||
#### func (*Lockstep) JoinClient(client Client[ClientID])
|
||||
> 将客户端加入到广播队列中,通常在开始广播前使用
|
||||
> - 如果客户端在开始广播后加入,将丢失之前的帧数据,如要从特定帧开始追帧请使用 JoinClientWithFrame
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_JoinClientWithFrame"></span>
|
||||
|
||||
#### func (*Lockstep) JoinClientWithFrame(client Client[ClientID], frameIndex int64)
|
||||
> 加入客户端到广播队列中,并从特定帧开始追帧
|
||||
> - 可用于重连及状态同步、帧同步混用的情况
|
||||
> - 混用:服务端记录指令时同时做一次状态计算,新客户端加入时直接同步当前状态,之后从特定帧开始广播
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_GetClientCount"></span>
|
||||
|
||||
#### func (*Lockstep) GetClientCount() int
|
||||
> 获取客户端数量
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_DropCache"></span>
|
||||
|
||||
#### func (*Lockstep) DropCache(handler func (frame int64) bool)
|
||||
> 丢弃特定帧的缓存,当 handler 返回 true 时将丢弃缓存
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_LeaveClient"></span>
|
||||
|
||||
#### func (*Lockstep) LeaveClient(clientId ClientID)
|
||||
> 将客户端从广播队列中移除
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_StartBroadcast"></span>
|
||||
|
||||
#### func (*Lockstep) StartBroadcast()
|
||||
> 开始广播
|
||||
> - 在开始广播后将持续按照设定的帧率进行帧数推进,并在每一帧推进时向客户端进行同步,需提前将客户端加入广播队列 JoinClient
|
||||
> - 广播过程中使用 AddCommand 将该帧数据追加到当前帧中
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_StopBroadcast"></span>
|
||||
|
||||
#### func (*Lockstep) StopBroadcast()
|
||||
> 停止广播
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_IsRunning"></span>
|
||||
|
||||
#### func (*Lockstep) IsRunning() bool
|
||||
> 是否正在广播
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_AddCommand"></span>
|
||||
|
||||
#### func (*Lockstep) AddCommand(command Command)
|
||||
> 添加命令到当前帧
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_AddCommands"></span>
|
||||
|
||||
#### func (*Lockstep) AddCommands(commands []Command)
|
||||
> 添加命令到当前帧
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_GetCurrentFrame"></span>
|
||||
|
||||
#### func (*Lockstep) GetCurrentFrame() int64
|
||||
> 获取当前帧
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_GetClientCurrentFrame"></span>
|
||||
|
||||
#### func (*Lockstep) GetClientCurrentFrame(clientId ClientID) int64
|
||||
> 获取客户端当前帧
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_GetFrameLimit"></span>
|
||||
|
||||
#### func (*Lockstep) GetFrameLimit() int64
|
||||
> 获取帧上限
|
||||
> - 未设置时将返回0
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_GetCurrentCommands"></span>
|
||||
|
||||
#### func (*Lockstep) GetCurrentCommands() []Command
|
||||
> 获取当前帧还未结束时的所有指令
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_RegLockstepStoppedEvent"></span>
|
||||
|
||||
#### func (*Lockstep) RegLockstepStoppedEvent(handle StoppedEventHandle[ClientID, Command])
|
||||
> 当广播停止时将触发被注册的事件处理函数
|
||||
|
||||
***
|
||||
<span id="struct_Lockstep_OnLockstepStoppedEvent"></span>
|
||||
|
||||
#### func (*Lockstep) OnLockstepStoppedEvent()
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
|
|
@ -60,8 +60,11 @@ func ExampleNewMultistage() {
|
|||
```go
|
||||
type MultistageBind[HandleFunc any] func(HandleFunc)
|
||||
```
|
||||
<span id="struct_MultistageBind_Bind"></span>
|
||||
|
||||
#### func (MultistageBind) Bind(handleFunc HandleFunc)
|
||||
> 将处理函数绑定到预设的路由中
|
||||
|
||||
***
|
||||
<span id="struct_Multistage"></span>
|
||||
### Multistage `STRUCT`
|
||||
|
@ -74,9 +77,12 @@ type Multistage[HandleFunc any] struct {
|
|||
trim func(route any) any
|
||||
}
|
||||
```
|
||||
<span id="struct_Multistage_Register"></span>
|
||||
|
||||
#### func (*Multistage) Register(routes ...any) MultistageBind[HandleFunc]
|
||||
> 注册路由是结合 Sub 和 Route 的快捷方式,用于一次性注册多级路由
|
||||
> - 该函数将返回一个注册函数,可通过调用其将路由绑定到特定处理函数,例如:router.Register("a", "b").Bind(onExec())
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -90,8 +96,11 @@ func ExampleMultistage_Register() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_Multistage_Route"></span>
|
||||
|
||||
#### func (*Multistage) Route(route any, handleFunc HandleFunc)
|
||||
> 为特定路由绑定处理函数,被绑定的处理函数将可以通过 Match 函数进行匹配
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -105,9 +114,12 @@ func ExampleMultistage_Route() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_Multistage_Match"></span>
|
||||
|
||||
#### func (*Multistage) Match(routes ...any) HandleFunc
|
||||
> 匹配已绑定处理函数的路由,返回处理函数
|
||||
> - 如果未找到将会返回空指针
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -156,8 +168,11 @@ func TestMultistage_Match(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Multistage_Sub"></span>
|
||||
|
||||
#### func (*Multistage) Sub(route any) *Multistage[HandleFunc]
|
||||
> 获取子路由器
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
|
|
@ -115,11 +115,17 @@ type Channel[T any] struct {
|
|||
c chan T
|
||||
}
|
||||
```
|
||||
<span id="struct_Channel_Put"></span>
|
||||
|
||||
#### func (*Channel) Put(message T)
|
||||
> 将数据放入写循环,message 应该来源于 hub.ObjectPool
|
||||
|
||||
***
|
||||
<span id="struct_Channel_Close"></span>
|
||||
|
||||
#### func (*Channel) Close()
|
||||
> 关闭写循环
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded"></span>
|
||||
### Unbounded `STRUCT`
|
||||
|
@ -130,8 +136,11 @@ type Unbounded[Message any] struct {
|
|||
buf *buffer.Unbounded[Message]
|
||||
}
|
||||
```
|
||||
<span id="struct_Unbounded_Put"></span>
|
||||
|
||||
#### func (*Unbounded) Put(message Message)
|
||||
> 将数据放入写循环,message 应该来源于 hub.ObjectPool
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -189,8 +198,11 @@ func BenchmarkUnbounded_Put(b *testing.B) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded_Close"></span>
|
||||
|
||||
#### func (*Unbounded) Close()
|
||||
> 关闭写循环
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
|
|
@ -83,17 +83,35 @@ type TwoDimensional[EID generic.Basic, PosType generic.SignedNumber, E TwoDimens
|
|||
repartitionQueue []func()
|
||||
}
|
||||
```
|
||||
<span id="struct_TwoDimensional_AddEntity"></span>
|
||||
|
||||
#### func (*TwoDimensional) AddEntity(entity E)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_DeleteEntity"></span>
|
||||
|
||||
#### func (*TwoDimensional) DeleteEntity(entity E)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_Refresh"></span>
|
||||
|
||||
#### func (*TwoDimensional) Refresh(entity E)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_GetFocus"></span>
|
||||
|
||||
#### func (*TwoDimensional) GetFocus(id EID) map[EID]E
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_SetSize"></span>
|
||||
|
||||
#### func (*TwoDimensional) SetSize(width int, height int)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_SetAreaSize"></span>
|
||||
|
||||
#### func (*TwoDimensional) SetAreaSize(width int, height int)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensionalEntity"></span>
|
||||
### TwoDimensionalEntity `INTERFACE`
|
||||
|
|
|
@ -127,24 +127,42 @@ type Area[ID comparable, AreaInfo any] struct {
|
|||
evaluate AreaEvaluateHandle[ID, AreaInfo]
|
||||
}
|
||||
```
|
||||
<span id="struct_Area_GetAreaInfo"></span>
|
||||
|
||||
#### func (*Area) GetAreaInfo() AreaInfo
|
||||
> 获取编排区域的信息
|
||||
|
||||
***
|
||||
<span id="struct_Area_GetItems"></span>
|
||||
|
||||
#### func (*Area) GetItems() map[ID]Item[ID]
|
||||
> 获取编排区域中的所有成员
|
||||
|
||||
***
|
||||
<span id="struct_Area_IsAllow"></span>
|
||||
|
||||
#### func (*Area) IsAllow(item Item[ID]) (constraintErr error, conflictItems map[ID]Item[ID], allow bool)
|
||||
> 检测一个成员是否可以被添加到该编排区域中
|
||||
|
||||
***
|
||||
<span id="struct_Area_IsConflict"></span>
|
||||
|
||||
#### func (*Area) IsConflict(item Item[ID]) bool
|
||||
> 检测一个成员是否会造成冲突
|
||||
|
||||
***
|
||||
<span id="struct_Area_GetConflictItems"></span>
|
||||
|
||||
#### func (*Area) GetConflictItems(item Item[ID]) map[ID]Item[ID]
|
||||
> 获取与一个成员产生冲突的所有其他成员
|
||||
|
||||
***
|
||||
<span id="struct_Area_GetScore"></span>
|
||||
|
||||
#### func (*Area) GetScore(extra ...Item[ID]) float64
|
||||
> 获取该编排区域的评估分数
|
||||
> - 当 extra 不为空时,将会将 extra 中的内容添加到 items 中进行评估
|
||||
|
||||
***
|
||||
<span id="struct_AreaOption"></span>
|
||||
### AreaOption `STRUCT`
|
||||
|
@ -176,14 +194,23 @@ type Arrangement[ID comparable, AreaInfo any] struct {
|
|||
conflictHandles []ConflictHandle[ID, AreaInfo]
|
||||
}
|
||||
```
|
||||
<span id="struct_Arrangement_AddArea"></span>
|
||||
|
||||
#### func (*Arrangement) AddArea(areaInfo AreaInfo, options ...AreaOption[ID, AreaInfo])
|
||||
> 添加一个编排区域
|
||||
|
||||
***
|
||||
<span id="struct_Arrangement_AddItem"></span>
|
||||
|
||||
#### func (*Arrangement) AddItem(item Item[ID])
|
||||
> 添加一个成员
|
||||
|
||||
***
|
||||
<span id="struct_Arrangement_Arrange"></span>
|
||||
|
||||
#### func (*Arrangement) Arrange() (areas []*Area[ID, AreaInfo], noSolution map[ID]Item[ID])
|
||||
> 编排
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -247,47 +274,89 @@ type Editor[ID comparable, AreaInfo any] struct {
|
|||
retryCount int
|
||||
}
|
||||
```
|
||||
<span id="struct_Editor_GetPendingCount"></span>
|
||||
|
||||
#### func (*Editor) GetPendingCount() int
|
||||
> 获取待编排的成员数量
|
||||
|
||||
***
|
||||
<span id="struct_Editor_RemoveAreaItem"></span>
|
||||
|
||||
#### func (*Editor) RemoveAreaItem(area *Area[ID, AreaInfo], item Item[ID])
|
||||
> 从编排区域中移除一个成员到待编排队列中,如果该成员不存在于编排区域中,则不进行任何操作
|
||||
|
||||
***
|
||||
<span id="struct_Editor_AddAreaItem"></span>
|
||||
|
||||
#### func (*Editor) AddAreaItem(area *Area[ID, AreaInfo], item Item[ID])
|
||||
> 将一个成员添加到编排区域中,如果该成员已经存在于编排区域中,则不进行任何操作
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetAreas"></span>
|
||||
|
||||
#### func (*Editor) GetAreas() []*Area[ID, AreaInfo]
|
||||
> 获取所有的编排区域
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetAreasWithScoreAsc"></span>
|
||||
|
||||
#### func (*Editor) GetAreasWithScoreAsc(extra ...Item[ID]) []*Area[ID, AreaInfo]
|
||||
> 获取所有的编排区域,并按照分数升序排序
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetAreasWithScoreDesc"></span>
|
||||
|
||||
#### func (*Editor) GetAreasWithScoreDesc(extra ...Item[ID]) []*Area[ID, AreaInfo]
|
||||
> 获取所有的编排区域,并按照分数降序排序
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetRetryCount"></span>
|
||||
|
||||
#### func (*Editor) GetRetryCount() int
|
||||
> 获取重试次数
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetThresholdProgressRate"></span>
|
||||
|
||||
#### func (*Editor) GetThresholdProgressRate() float64
|
||||
> 获取重试次数阈值进度
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetAllowAreas"></span>
|
||||
|
||||
#### func (*Editor) GetAllowAreas(item Item[ID]) []*Area[ID, AreaInfo]
|
||||
> 获取允许的编排区域
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetNoAllowAreas"></span>
|
||||
|
||||
#### func (*Editor) GetNoAllowAreas(item Item[ID]) []*Area[ID, AreaInfo]
|
||||
> 获取不允许的编排区域
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetBestAllowArea"></span>
|
||||
|
||||
#### func (*Editor) GetBestAllowArea(item Item[ID]) *Area[ID, AreaInfo]
|
||||
> 获取最佳的允许的编排区域,如果不存在,则返回 nil
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetBestNoAllowArea"></span>
|
||||
|
||||
#### func (*Editor) GetBestNoAllowArea(item Item[ID]) *Area[ID, AreaInfo]
|
||||
> 获取最佳的不允许的编排区域,如果不存在,则返回 nil
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetWorstAllowArea"></span>
|
||||
|
||||
#### func (*Editor) GetWorstAllowArea(item Item[ID]) *Area[ID, AreaInfo]
|
||||
> 获取最差的允许的编排区域,如果不存在,则返回 nil
|
||||
|
||||
***
|
||||
<span id="struct_Editor_GetWorstNoAllowArea"></span>
|
||||
|
||||
#### func (*Editor) GetWorstNoAllowArea(item Item[ID]) *Area[ID, AreaInfo]
|
||||
> 获取最差的不允许的编排区域,如果不存在,则返回 nil
|
||||
|
||||
***
|
||||
<span id="struct_Item"></span>
|
||||
### Item `INTERFACE`
|
||||
|
|
|
@ -94,8 +94,11 @@ type Ring[T any] struct {
|
|||
w int
|
||||
}
|
||||
```
|
||||
<span id="struct_Ring_Read"></span>
|
||||
|
||||
#### func (*Ring) Read() ( T, error)
|
||||
> 读取数据
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起基准测试</summary>
|
||||
|
||||
|
@ -120,14 +123,23 @@ func BenchmarkRing_Read(b *testing.B) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Ring_ReadAll"></span>
|
||||
|
||||
#### func (*Ring) ReadAll() []T
|
||||
> 读取所有数据
|
||||
|
||||
***
|
||||
<span id="struct_Ring_Peek"></span>
|
||||
|
||||
#### func (*Ring) Peek() (t T, err error)
|
||||
> 查看数据
|
||||
|
||||
***
|
||||
<span id="struct_Ring_Write"></span>
|
||||
|
||||
#### func (*Ring) Write(v T)
|
||||
> 写入数据
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起基准测试</summary>
|
||||
|
||||
|
@ -149,17 +161,29 @@ func BenchmarkRing_Write(b *testing.B) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Ring_IsEmpty"></span>
|
||||
|
||||
#### func (*Ring) IsEmpty() bool
|
||||
> 是否为空
|
||||
|
||||
***
|
||||
<span id="struct_Ring_Cap"></span>
|
||||
|
||||
#### func (*Ring) Cap() int
|
||||
> 返回缓冲区容量
|
||||
|
||||
***
|
||||
<span id="struct_Ring_Len"></span>
|
||||
|
||||
#### func (*Ring) Len() int
|
||||
> 返回缓冲区长度
|
||||
|
||||
***
|
||||
<span id="struct_Ring_Reset"></span>
|
||||
|
||||
#### func (*Ring) Reset()
|
||||
> 重置缓冲区
|
||||
|
||||
***
|
||||
<span id="struct_RingUnbounded"></span>
|
||||
### RingUnbounded `STRUCT`
|
||||
|
@ -175,8 +199,11 @@ type RingUnbounded[T any] struct {
|
|||
closedSignal chan struct{}
|
||||
}
|
||||
```
|
||||
<span id="struct_RingUnbounded_Write"></span>
|
||||
|
||||
#### func (*RingUnbounded) Write(v T)
|
||||
> 写入数据
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起基准测试</summary>
|
||||
|
||||
|
@ -198,8 +225,11 @@ func BenchmarkRingUnbounded_Write(b *testing.B) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_RingUnbounded_Read"></span>
|
||||
|
||||
#### func (*RingUnbounded) Read() chan T
|
||||
> 读取数据
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起基准测试</summary>
|
||||
|
||||
|
@ -224,11 +254,17 @@ func BenchmarkRingUnbounded_Read(b *testing.B) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_RingUnbounded_Closed"></span>
|
||||
|
||||
#### func (*RingUnbounded) Closed() bool
|
||||
> 判断缓冲区是否已关闭
|
||||
|
||||
***
|
||||
<span id="struct_RingUnbounded_Close"></span>
|
||||
|
||||
#### func (*RingUnbounded) Close() chan struct {}
|
||||
> 关闭缓冲区,关闭后将不再接收新数据,但是已有数据仍然可以读取
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -268,15 +304,24 @@ type Unbounded[V any] struct {
|
|||
backlog []V
|
||||
}
|
||||
```
|
||||
<span id="struct_Unbounded_Put"></span>
|
||||
|
||||
#### func (*Unbounded) Put(t V)
|
||||
> 将数据放入缓冲区
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded_Load"></span>
|
||||
|
||||
#### func (*Unbounded) Load()
|
||||
> 将缓冲区中的数据发送到读取通道中,如果缓冲区中没有数据,则不会发送
|
||||
> - 在每次 Get 后都应该执行该函数
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded_Get"></span>
|
||||
|
||||
#### func (*Unbounded) Get() chan V
|
||||
> 获取读取通道
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -299,9 +344,15 @@ func TestUnbounded_Get(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded_Close"></span>
|
||||
|
||||
#### func (*Unbounded) Close()
|
||||
> 关闭
|
||||
|
||||
***
|
||||
<span id="struct_Unbounded_IsClosed"></span>
|
||||
|
||||
#### func (*Unbounded) IsClosed() bool
|
||||
> 是否已关闭
|
||||
|
||||
***
|
||||
|
|
|
@ -147,7 +147,7 @@ collection 定义了各种对于集合操作有用的各种函数
|
|||
|
||||
**示例代码:**
|
||||
|
||||
slice 克隆后将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
在该示例中,将 slice 克隆后将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
- 示例中的结果将会输出 [1 2 3]
|
||||
|
||||
|
||||
|
@ -202,7 +202,7 @@ func TestCloneSlice(t *testing.T) {
|
|||
|
||||
**示例代码:**
|
||||
|
||||
map 克隆后将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
在该示例中,将 map 克隆后将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
- 示例中的结果将会输出 3
|
||||
|
||||
|
||||
|
@ -257,7 +257,7 @@ func TestCloneMap(t *testing.T) {
|
|||
|
||||
**示例代码:**
|
||||
|
||||
slice 克隆为 2 个新的 slice,将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
通过将 slice 克隆为 2 个新的 slice,将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
- result 的结果为 [[1 2 3] [1 2 3]]
|
||||
- 示例中的结果将会输出 2
|
||||
|
||||
|
@ -319,7 +319,7 @@ func TestCloneSliceN(t *testing.T) {
|
|||
|
||||
**示例代码:**
|
||||
|
||||
map 克隆为 2 个新的 map,将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
通过将 map 克隆为 2 个新的 map,将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
- result 的结果为 [map[1:1 2:2 3:3] map[1:1 2:2 3:3]] `无序的 Key-Value 对`
|
||||
- 示例中的结果将会输出 2
|
||||
|
||||
|
@ -382,7 +382,7 @@ func TestCloneMapN(t *testing.T) {
|
|||
|
||||
**示例代码:**
|
||||
|
||||
slice 克隆为 2 个新的 slice,将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
通过将多个 slice 克隆为 2 个新的 slice,将会得到一个新的 slice result,而 result 和 slice 将不会有任何关联,但是如果 slice 中的元素是引用类型,那么 result 中的元素将会和 slice 中的元素指向同一个地址
|
||||
- result 的结果为 [[1 2 3] [1 2 3]]
|
||||
|
||||
|
||||
|
@ -441,7 +441,7 @@ func TestCloneSlices(t *testing.T) {
|
|||
|
||||
**示例代码:**
|
||||
|
||||
map 克隆为 2 个新的 map,将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
通过将多个 map 克隆为 2 个新的 map,将会得到一个新的 map result,而 result 和 map 将不会有任何关联,但是如果 map 中的元素是引用类型,那么 result 中的元素将会和 map 中的元素指向同一个地址
|
||||
- result 的结果为 [map[1:1 2:2 3:3] map[1:1 2:2 3:3]] `无序的 Key-Value 对`
|
||||
|
||||
|
||||
|
|
|
@ -65,17 +65,29 @@ type Matrix[V any] struct {
|
|||
data []V
|
||||
}
|
||||
```
|
||||
<span id="struct_Matrix_Get"></span>
|
||||
|
||||
#### func (*Matrix) Get(index ...int) *V
|
||||
> 获取矩阵中给定索引的元素。
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Set"></span>
|
||||
|
||||
#### func (*Matrix) Set(index []int, value V)
|
||||
> 设置矩阵中给定索引的元素。
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Dimensions"></span>
|
||||
|
||||
#### func (*Matrix) Dimensions() []int
|
||||
> 返回矩阵的维度大小。
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Clear"></span>
|
||||
|
||||
#### func (*Matrix) Clear()
|
||||
> 清空矩阵。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice"></span>
|
||||
### PagedSlice `STRUCT`
|
||||
|
@ -88,23 +100,41 @@ type PagedSlice[T any] struct {
|
|||
lenLast int
|
||||
}
|
||||
```
|
||||
<span id="struct_PagedSlice_Add"></span>
|
||||
|
||||
#### func (*PagedSlice) Add(value T)
|
||||
> 添加一个元素到 PagedSlice 中。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice_Get"></span>
|
||||
|
||||
#### func (*PagedSlice) Get(index int) *T
|
||||
> 获取 PagedSlice 中给定索引的元素。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice_Set"></span>
|
||||
|
||||
#### func (*PagedSlice) Set(index int, value T)
|
||||
> 设置 PagedSlice 中给定索引的元素。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice_Len"></span>
|
||||
|
||||
#### func (*PagedSlice) Len() int
|
||||
> 返回 PagedSlice 中元素的数量。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice_Clear"></span>
|
||||
|
||||
#### func (*PagedSlice) Clear()
|
||||
> 清空 PagedSlice。
|
||||
|
||||
***
|
||||
<span id="struct_PagedSlice_Range"></span>
|
||||
|
||||
#### func (*PagedSlice) Range(f func (index int, value T) bool)
|
||||
> 迭代 PagedSlice 中的所有元素。
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice"></span>
|
||||
### PrioritySlice `STRUCT`
|
||||
|
@ -114,17 +144,29 @@ type PrioritySlice[V any] struct {
|
|||
items []*priorityItem[V]
|
||||
}
|
||||
```
|
||||
<span id="struct_PrioritySlice_Len"></span>
|
||||
|
||||
#### func (*PrioritySlice) Len() int
|
||||
> 返回切片长度
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Cap"></span>
|
||||
|
||||
#### func (*PrioritySlice) Cap() int
|
||||
> 返回切片容量
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Clear"></span>
|
||||
|
||||
#### func (*PrioritySlice) Clear()
|
||||
> 清空切片
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Append"></span>
|
||||
|
||||
#### func (*PrioritySlice) Append(v V, p int)
|
||||
> 添加元素
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -145,44 +187,83 @@ func TestPrioritySlice_Append(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Appends"></span>
|
||||
|
||||
#### func (*PrioritySlice) Appends(priority int, vs ...V)
|
||||
> 添加元素
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Get"></span>
|
||||
|
||||
#### func (*PrioritySlice) Get(index int) ( V, int)
|
||||
> 获取元素
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_GetValue"></span>
|
||||
|
||||
#### func (*PrioritySlice) GetValue(index int) V
|
||||
> 获取元素值
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_GetPriority"></span>
|
||||
|
||||
#### func (*PrioritySlice) GetPriority(index int) int
|
||||
> 获取元素优先级
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Set"></span>
|
||||
|
||||
#### func (*PrioritySlice) Set(index int, value V, priority int)
|
||||
> 设置元素
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_SetValue"></span>
|
||||
|
||||
#### func (*PrioritySlice) SetValue(index int, value V)
|
||||
> 设置元素值
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_SetPriority"></span>
|
||||
|
||||
#### func (*PrioritySlice) SetPriority(index int, priority int)
|
||||
> 设置元素优先级
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Action"></span>
|
||||
|
||||
#### func (*PrioritySlice) Action(action func (items []*priorityItem[V]) []*priorityItem[V])
|
||||
> 直接操作切片,如果返回值不为 nil,则替换切片
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Range"></span>
|
||||
|
||||
#### func (*PrioritySlice) Range(action func (index int, item *priorityItem[V]) bool)
|
||||
> 遍历切片,如果返回值为 false,则停止遍历
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_RangeValue"></span>
|
||||
|
||||
#### func (*PrioritySlice) RangeValue(action func (index int, value V) bool)
|
||||
> 遍历切片值,如果返回值为 false,则停止遍历
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_RangePriority"></span>
|
||||
|
||||
#### func (*PrioritySlice) RangePriority(action func (index int, priority int) bool)
|
||||
> 遍历切片优先级,如果返回值为 false,则停止遍历
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_Slice"></span>
|
||||
|
||||
#### func (*PrioritySlice) Slice() []V
|
||||
> 返回切片
|
||||
> SyncSlice 返回切片
|
||||
|
||||
***
|
||||
<span id="struct_PrioritySlice_String"></span>
|
||||
|
||||
#### func (*PrioritySlice) String() string
|
||||
> 返回切片字符串
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice"></span>
|
||||
### SyncSlice `STRUCT`
|
||||
|
@ -193,17 +274,38 @@ type SyncSlice[V any] struct {
|
|||
data []V
|
||||
}
|
||||
```
|
||||
<span id="struct_SyncSlice_Get"></span>
|
||||
|
||||
#### func (*SyncSlice) Get(index int) V
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_GetWithRange"></span>
|
||||
|
||||
#### func (*SyncSlice) GetWithRange(start int, end int) []V
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_Set"></span>
|
||||
|
||||
#### func (*SyncSlice) Set(index int, value V)
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_Append"></span>
|
||||
|
||||
#### func (*SyncSlice) Append(values ...V)
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_Release"></span>
|
||||
|
||||
#### func (*SyncSlice) Release()
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_Clear"></span>
|
||||
|
||||
#### func (*SyncSlice) Clear()
|
||||
|
||||
***
|
||||
<span id="struct_SyncSlice_GetData"></span>
|
||||
|
||||
#### func (*SyncSlice) GetData() []V
|
||||
|
||||
***
|
||||
|
|
|
@ -46,55 +46,109 @@ type SyncMap[K comparable, V any] struct {
|
|||
atom bool
|
||||
}
|
||||
```
|
||||
<span id="struct_SyncMap_Set"></span>
|
||||
|
||||
#### func (*SyncMap) Set(key K, value V)
|
||||
> 设置一个值
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Get"></span>
|
||||
|
||||
#### func (*SyncMap) Get(key K) V
|
||||
> 获取一个值
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Atom"></span>
|
||||
|
||||
#### func (*SyncMap) Atom(handle func (m map[K]V))
|
||||
> 原子操作
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Exist"></span>
|
||||
|
||||
#### func (*SyncMap) Exist(key K) bool
|
||||
> 判断是否存在
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_GetExist"></span>
|
||||
|
||||
#### func (*SyncMap) GetExist(key K) ( V, bool)
|
||||
> 获取一个值并判断是否存在
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Delete"></span>
|
||||
|
||||
#### func (*SyncMap) Delete(key K)
|
||||
> 删除一个值
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_DeleteGet"></span>
|
||||
|
||||
#### func (*SyncMap) DeleteGet(key K) V
|
||||
> 删除一个值并返回
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_DeleteGetExist"></span>
|
||||
|
||||
#### func (*SyncMap) DeleteGetExist(key K) ( V, bool)
|
||||
> 删除一个值并返回是否存在
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_DeleteExist"></span>
|
||||
|
||||
#### func (*SyncMap) DeleteExist(key K) bool
|
||||
> 删除一个值并返回是否存在
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Clear"></span>
|
||||
|
||||
#### func (*SyncMap) Clear()
|
||||
> 清空
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_ClearHandle"></span>
|
||||
|
||||
#### func (*SyncMap) ClearHandle(handle func (key K, value V))
|
||||
> 清空并处理
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Range"></span>
|
||||
|
||||
#### func (*SyncMap) Range(handle func (key K, value V) bool)
|
||||
> 遍历所有值,如果 handle 返回 true 则停止遍历
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Keys"></span>
|
||||
|
||||
#### func (*SyncMap) Keys() []K
|
||||
> 获取所有的键
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Slice"></span>
|
||||
|
||||
#### func (*SyncMap) Slice() []V
|
||||
> 获取所有的值
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Map"></span>
|
||||
|
||||
#### func (*SyncMap) Map() map[K]V
|
||||
> 转换为普通 map
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_Size"></span>
|
||||
|
||||
#### func (*SyncMap) Size() int
|
||||
> 获取数量
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_MarshalJSON"></span>
|
||||
|
||||
#### func (*SyncMap) MarshalJSON() ( []byte, error)
|
||||
|
||||
***
|
||||
<span id="struct_SyncMap_UnmarshalJSON"></span>
|
||||
|
||||
#### func (*SyncMap) UnmarshalJSON(bytes []byte) error
|
||||
|
||||
***
|
||||
|
|
|
@ -44,7 +44,7 @@ combination 包提供了一些实用的组合函数。
|
|||
|[WithValidatorHandleContinuousNot](#WithValidatorHandleContinuousNot)|校验组合成员是否不连续
|
||||
|[WithValidatorHandleGroupContinuous](#WithValidatorHandleGroupContinuous)|校验组合成员是否能够按类型分组并且连续
|
||||
|[WithValidatorHandleGroupContinuousN](#WithValidatorHandleGroupContinuousN)|校验组合成员是否能够按分组为 n 组类型并且连续
|
||||
|[WithValidatorHandleNCarryM](#WithValidatorHandleNCarryM)| 校验组合成员是否匹配 N 携带相同的 M 的组合
|
||||
|[WithValidatorHandleNCarryM](#WithValidatorHandleNCarryM)|校验组合成员是否匹配 N 携带相同的 M 的组合
|
||||
|[WithValidatorHandleNCarryIndependentM](#WithValidatorHandleNCarryIndependentM)|校验组合成员是否匹配 N 携带独立的 M 的组合
|
||||
|
||||
|
||||
|
@ -227,7 +227,7 @@ combination 包提供了一些实用的组合函数。
|
|||
***
|
||||
#### func WithValidatorHandleNCarryM\[T Item, E generic.Ordered\](n int, m int, getType func (item T) E) ValidatorOption[T]
|
||||
<span id="WithValidatorHandleNCarryM"></span>
|
||||
> 校验组合成员是否匹配 N 携带相同的 M 的组合
|
||||
> 校验组合成员是否匹配 N 携带相同的 M 的组合
|
||||
> - n: 组合中元素的数量,表示需要匹配的组合数量,n 的类型需要全部相同
|
||||
> - m: 组合中元素的数量,表示需要匹配的组合数量,m 的类型需要全部相同
|
||||
> - getType: 用于获取组合中元素的类型,用于判断是否相同
|
||||
|
@ -251,23 +251,41 @@ type Combination[T Item] struct {
|
|||
priority []string
|
||||
}
|
||||
```
|
||||
<span id="struct_Combination_NewMatcher"></span>
|
||||
|
||||
#### func (*Combination) NewMatcher(name string, options ...MatcherOption[T]) *Combination[T]
|
||||
> 添加一个新的匹配器
|
||||
|
||||
***
|
||||
<span id="struct_Combination_AddMatcher"></span>
|
||||
|
||||
#### func (*Combination) AddMatcher(name string, matcher *Matcher[T]) *Combination[T]
|
||||
> 添加一个匹配器
|
||||
|
||||
***
|
||||
<span id="struct_Combination_RemoveMatcher"></span>
|
||||
|
||||
#### func (*Combination) RemoveMatcher(name string) *Combination[T]
|
||||
> 移除一个匹配器
|
||||
|
||||
***
|
||||
<span id="struct_Combination_Combinations"></span>
|
||||
|
||||
#### func (*Combination) Combinations(items []T) (result [][]T)
|
||||
> 从一组数据中提取所有符合匹配器规则的组合
|
||||
|
||||
***
|
||||
<span id="struct_Combination_CombinationsToName"></span>
|
||||
|
||||
#### func (*Combination) CombinationsToName(items []T) (result map[string][][]T)
|
||||
> 从一组数据中提取所有符合匹配器规则的组合,并返回匹配器名称
|
||||
|
||||
***
|
||||
<span id="struct_Combination_Best"></span>
|
||||
|
||||
#### func (*Combination) Best(items []T) (name string, result []T)
|
||||
> 从一组数据中提取符合匹配器规则的最佳组合
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -302,8 +320,11 @@ func TestCombination_Best(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Combination_Worst"></span>
|
||||
|
||||
#### func (*Combination) Worst(items []T) (name string, result []T)
|
||||
> 从一组数据中提取符合匹配器规则的最差组合
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
@ -326,18 +347,30 @@ type Matcher[T Item] struct {
|
|||
filter []func(items []T) [][]T
|
||||
}
|
||||
```
|
||||
<span id="struct_Matcher_AddFilter"></span>
|
||||
|
||||
#### func (*Matcher) AddFilter(filter func (items []T) [][]T)
|
||||
> 添加一个筛选器
|
||||
> - 筛选器用于对组合进行筛选,返回一个二维数组,每个数组内的元素都是一个组合
|
||||
|
||||
***
|
||||
<span id="struct_Matcher_Combinations"></span>
|
||||
|
||||
#### func (*Matcher) Combinations(items []T) [][]T
|
||||
> 从一组数据中提取所有符合筛选器规则的组合
|
||||
|
||||
***
|
||||
<span id="struct_Matcher_Best"></span>
|
||||
|
||||
#### func (*Matcher) Best(items []T) []T
|
||||
> 从一组数据中提取符筛选器规则的最佳组合
|
||||
|
||||
***
|
||||
<span id="struct_Matcher_Worst"></span>
|
||||
|
||||
#### func (*Matcher) Worst(items []T) []T
|
||||
> 从一组数据中提取符筛选器规则的最差组合
|
||||
|
||||
***
|
||||
<span id="struct_MatcherOption"></span>
|
||||
### MatcherOption `STRUCT`
|
||||
|
@ -353,8 +386,11 @@ type Validator[T Item] struct {
|
|||
vh []func(items []T) bool
|
||||
}
|
||||
```
|
||||
<span id="struct_Validator_Validate"></span>
|
||||
|
||||
#### func (*Validator) Validate(items []T) bool
|
||||
> 校验组合是否符合要求
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
|
|
@ -52,26 +52,47 @@ type Deck[I Item] struct {
|
|||
sort []int64
|
||||
}
|
||||
```
|
||||
<span id="struct_Deck_AddGroup"></span>
|
||||
|
||||
#### func (*Deck) AddGroup(group *Group[I])
|
||||
> 将一个组添加到甲板中
|
||||
|
||||
***
|
||||
<span id="struct_Deck_RemoveGroup"></span>
|
||||
|
||||
#### func (*Deck) RemoveGroup(guid int64)
|
||||
> 移除甲板中的一个组
|
||||
|
||||
***
|
||||
<span id="struct_Deck_GetCount"></span>
|
||||
|
||||
#### func (*Deck) GetCount() int
|
||||
> 获取甲板中的组数量
|
||||
|
||||
***
|
||||
<span id="struct_Deck_GetGroups"></span>
|
||||
|
||||
#### func (*Deck) GetGroups() map[int64]*Group[I]
|
||||
> 获取所有组
|
||||
|
||||
***
|
||||
<span id="struct_Deck_GetGroupsSlice"></span>
|
||||
|
||||
#### func (*Deck) GetGroupsSlice() []*Group[I]
|
||||
> 获取所有组
|
||||
|
||||
***
|
||||
<span id="struct_Deck_GetNext"></span>
|
||||
|
||||
#### func (*Deck) GetNext(guid int64) *Group[I]
|
||||
> 获取特定组的下一个组
|
||||
|
||||
***
|
||||
<span id="struct_Deck_GetPrev"></span>
|
||||
|
||||
#### func (*Deck) GetPrev(guid int64) *Group[I]
|
||||
> 获取特定组的上一个组
|
||||
|
||||
***
|
||||
<span id="struct_Group"></span>
|
||||
### Group `STRUCT`
|
||||
|
@ -83,50 +104,95 @@ type Group[I Item] struct {
|
|||
items []I
|
||||
}
|
||||
```
|
||||
<span id="struct_Group_GetGuid"></span>
|
||||
|
||||
#### func (*Group) GetGuid() int64
|
||||
> 获取组的 guid
|
||||
|
||||
***
|
||||
<span id="struct_Group_Fill"></span>
|
||||
|
||||
#### func (*Group) Fill()
|
||||
> 将该组的数据填充为 WithGroupFillHandle 中设置的内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_Pop"></span>
|
||||
|
||||
#### func (*Group) Pop() (item I)
|
||||
> 从顶部获取一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_PopN"></span>
|
||||
|
||||
#### func (*Group) PopN(n int) (items []I)
|
||||
> 从顶部获取指定数量的内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_PressOut"></span>
|
||||
|
||||
#### func (*Group) PressOut() (item I)
|
||||
> 从底部压出一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_PressOutN"></span>
|
||||
|
||||
#### func (*Group) PressOutN(n int) (items []I)
|
||||
> 从底部压出指定数量的内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_Push"></span>
|
||||
|
||||
#### func (*Group) Push(item I)
|
||||
> 向顶部压入一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_PushN"></span>
|
||||
|
||||
#### func (*Group) PushN(items []I)
|
||||
> 向顶部压入指定数量的内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_Insert"></span>
|
||||
|
||||
#### func (*Group) Insert(item I)
|
||||
> 向底部插入一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_InsertN"></span>
|
||||
|
||||
#### func (*Group) InsertN(items []I)
|
||||
> 向底部插入指定数量的内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_Pull"></span>
|
||||
|
||||
#### func (*Group) Pull(index int) (item I)
|
||||
> 从特定位置拔出一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_Thrust"></span>
|
||||
|
||||
#### func (*Group) Thrust(index int, item I)
|
||||
> 向特定位置插入一个内容
|
||||
|
||||
***
|
||||
<span id="struct_Group_IsFree"></span>
|
||||
|
||||
#### func (*Group) IsFree() bool
|
||||
> 检查组是否为空
|
||||
|
||||
***
|
||||
<span id="struct_Group_GetCount"></span>
|
||||
|
||||
#### func (*Group) GetCount() int
|
||||
> 获取组中剩余的内容数量
|
||||
|
||||
***
|
||||
<span id="struct_Group_GetItem"></span>
|
||||
|
||||
#### func (*Group) GetItem(index int) I
|
||||
> 获取组中的指定内容
|
||||
|
||||
***
|
||||
<span id="struct_Item"></span>
|
||||
### Item `INTERFACE`
|
||||
|
|
|
@ -85,32 +85,59 @@ type FSM[State comparable, Data any] struct {
|
|||
exitAfterEventHandles map[State][]func(state *FSM[State, Data])
|
||||
}
|
||||
```
|
||||
<span id="struct_FSM_Update"></span>
|
||||
|
||||
#### func (*FSM) Update()
|
||||
> 触发当前状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_Register"></span>
|
||||
|
||||
#### func (*FSM) Register(state State, options ...Option[State, Data])
|
||||
> 注册状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_Unregister"></span>
|
||||
|
||||
#### func (*FSM) Unregister(state State)
|
||||
> 反注册状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_HasState"></span>
|
||||
|
||||
#### func (*FSM) HasState(state State) bool
|
||||
> 检查状态机是否存在特定状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_Change"></span>
|
||||
|
||||
#### func (*FSM) Change(state State)
|
||||
> 改变状态机状态到新的状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_Current"></span>
|
||||
|
||||
#### func (*FSM) Current() (state State)
|
||||
> 获取当前状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_GetData"></span>
|
||||
|
||||
#### func (*FSM) GetData() Data
|
||||
> 获取状态机数据
|
||||
|
||||
***
|
||||
<span id="struct_FSM_IsZero"></span>
|
||||
|
||||
#### func (*FSM) IsZero() bool
|
||||
> 检查状态机是否无状态
|
||||
|
||||
***
|
||||
<span id="struct_FSM_PrevIsZero"></span>
|
||||
|
||||
#### func (*FSM) PrevIsZero() bool
|
||||
> 检查状态机上一个状态是否无状态
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
|
|
@ -93,7 +93,10 @@ type File struct {
|
|||
Comment *Comment
|
||||
}
|
||||
```
|
||||
<span id="struct_File_Package"></span>
|
||||
|
||||
#### func (*File) Package() string
|
||||
|
||||
***
|
||||
<span id="struct_Function"></span>
|
||||
### Function `STRUCT`
|
||||
|
@ -114,7 +117,10 @@ type Function struct {
|
|||
Test bool
|
||||
}
|
||||
```
|
||||
<span id="struct_Function_Code"></span>
|
||||
|
||||
#### func (*Function) Code() string
|
||||
|
||||
***
|
||||
<span id="struct_Package"></span>
|
||||
### Package `STRUCT`
|
||||
|
@ -128,19 +134,40 @@ type Package struct {
|
|||
Functions map[string]*Function
|
||||
}
|
||||
```
|
||||
<span id="struct_Package_StructFunc"></span>
|
||||
|
||||
#### func (*Package) StructFunc(name string) []*Function
|
||||
|
||||
***
|
||||
<span id="struct_Package_PackageFunc"></span>
|
||||
|
||||
#### func (*Package) PackageFunc() []*Function
|
||||
|
||||
***
|
||||
<span id="struct_Package_Structs"></span>
|
||||
|
||||
#### func (*Package) Structs() []*Struct
|
||||
|
||||
***
|
||||
<span id="struct_Package_FileComments"></span>
|
||||
|
||||
#### func (*Package) FileComments() *Comment
|
||||
|
||||
***
|
||||
<span id="struct_Package_GetUnitTest"></span>
|
||||
|
||||
#### func (*Package) GetUnitTest(f *Function) *Function
|
||||
|
||||
***
|
||||
<span id="struct_Package_GetExampleTest"></span>
|
||||
|
||||
#### func (*Package) GetExampleTest(f *Function) *Function
|
||||
|
||||
***
|
||||
<span id="struct_Package_GetBenchmarkTest"></span>
|
||||
|
||||
#### func (*Package) GetBenchmarkTest(f *Function) *Function
|
||||
|
||||
***
|
||||
<span id="struct_Struct"></span>
|
||||
### Struct `STRUCT`
|
||||
|
|
|
@ -44,7 +44,10 @@ type Builder struct {
|
|||
o string
|
||||
}
|
||||
```
|
||||
<span id="struct_Builder_Generate"></span>
|
||||
|
||||
#### func (*Builder) Generate() error
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
|
|
@ -878,23 +878,41 @@ type Circle[V generic.SignedNumber] struct {
|
|||
Shape[V]
|
||||
}
|
||||
```
|
||||
<span id="struct_Circle_Radius"></span>
|
||||
|
||||
#### func (Circle) Radius() V
|
||||
> 获取圆形半径
|
||||
|
||||
***
|
||||
<span id="struct_Circle_Centroid"></span>
|
||||
|
||||
#### func (Circle) Centroid() Point[V]
|
||||
> 获取圆形质心位置
|
||||
|
||||
***
|
||||
<span id="struct_Circle_Overlap"></span>
|
||||
|
||||
#### func (Circle) Overlap(circle Circle[V]) bool
|
||||
> 与另一个圆是否发生重叠
|
||||
|
||||
***
|
||||
<span id="struct_Circle_Area"></span>
|
||||
|
||||
#### func (Circle) Area() V
|
||||
> 获取圆形面积
|
||||
|
||||
***
|
||||
<span id="struct_Circle_Length"></span>
|
||||
|
||||
#### func (Circle) Length() V
|
||||
> 获取圆的周长
|
||||
|
||||
***
|
||||
<span id="struct_Circle_CentroidDistance"></span>
|
||||
|
||||
#### func (Circle) CentroidDistance(circle Circle[V]) V
|
||||
> 计算与另一个圆的质心距离
|
||||
|
||||
***
|
||||
<span id="struct_FloorPlan"></span>
|
||||
### FloorPlan `STRUCT`
|
||||
|
@ -902,17 +920,29 @@ type Circle[V generic.SignedNumber] struct {
|
|||
```go
|
||||
type FloorPlan []string
|
||||
```
|
||||
<span id="struct_FloorPlan_IsFree"></span>
|
||||
|
||||
#### func (FloorPlan) IsFree(point Point[int]) bool
|
||||
> 检查位置是否为空格
|
||||
|
||||
***
|
||||
<span id="struct_FloorPlan_IsInBounds"></span>
|
||||
|
||||
#### func (FloorPlan) IsInBounds(point Point[int]) bool
|
||||
> 检查位置是否在边界内
|
||||
|
||||
***
|
||||
<span id="struct_FloorPlan_Put"></span>
|
||||
|
||||
#### func (FloorPlan) Put(point Point[int], c rune)
|
||||
> 设置平面图特定位置的字符
|
||||
|
||||
***
|
||||
<span id="struct_FloorPlan_String"></span>
|
||||
|
||||
#### func (FloorPlan) String() string
|
||||
> 获取平面图结果
|
||||
|
||||
***
|
||||
<span id="struct_Direction"></span>
|
||||
### Direction `STRUCT`
|
||||
|
@ -926,17 +956,29 @@ type Direction uint8
|
|||
```go
|
||||
type LineSegment[V generic.SignedNumber] [2]Point[V]
|
||||
```
|
||||
<span id="struct_LineSegment_GetPoints"></span>
|
||||
|
||||
#### func (LineSegment) GetPoints() [2]Point[V]
|
||||
> 获取该线段的两个点
|
||||
|
||||
***
|
||||
<span id="struct_LineSegment_GetStart"></span>
|
||||
|
||||
#### func (LineSegment) GetStart() Point[V]
|
||||
> 获取该线段的开始位置
|
||||
|
||||
***
|
||||
<span id="struct_LineSegment_GetEnd"></span>
|
||||
|
||||
#### func (LineSegment) GetEnd() Point[V]
|
||||
> 获取该线段的结束位置
|
||||
|
||||
***
|
||||
<span id="struct_LineSegment_GetLength"></span>
|
||||
|
||||
#### func (LineSegment) GetLength() V
|
||||
> 获取该线段的长度
|
||||
|
||||
***
|
||||
<span id="struct_LineSegmentCap"></span>
|
||||
### LineSegmentCap `STRUCT`
|
||||
|
@ -947,7 +989,10 @@ type LineSegmentCap[V generic.SignedNumber, Data any] struct {
|
|||
Data Data
|
||||
}
|
||||
```
|
||||
<span id="struct_LineSegmentCap_GetData"></span>
|
||||
|
||||
#### func (*LineSegmentCap) GetData() Data
|
||||
|
||||
***
|
||||
<span id="struct_Point"></span>
|
||||
### Point `STRUCT`
|
||||
|
@ -955,53 +1000,101 @@ type LineSegmentCap[V generic.SignedNumber, Data any] struct {
|
|||
```go
|
||||
type Point[V generic.SignedNumber] [2]V
|
||||
```
|
||||
<span id="struct_Point_GetX"></span>
|
||||
|
||||
#### func (Point) GetX() V
|
||||
> 返回该点的 x 坐标
|
||||
|
||||
***
|
||||
<span id="struct_Point_GetY"></span>
|
||||
|
||||
#### func (Point) GetY() V
|
||||
> 返回该点的 y 坐标
|
||||
|
||||
***
|
||||
<span id="struct_Point_GetXY"></span>
|
||||
|
||||
#### func (Point) GetXY() (x V, y V)
|
||||
> 返回该点的 x、y 坐标
|
||||
|
||||
***
|
||||
<span id="struct_Point_GetPos"></span>
|
||||
|
||||
#### func (Point) GetPos(width V) V
|
||||
> 返回该点位于特定宽度的二维数组的顺序位置
|
||||
|
||||
***
|
||||
<span id="struct_Point_GetOffset"></span>
|
||||
|
||||
#### func (Point) GetOffset(x V, y V) Point[V]
|
||||
> 获取偏移后的新坐标
|
||||
|
||||
***
|
||||
<span id="struct_Point_Negative"></span>
|
||||
|
||||
#### func (Point) Negative() bool
|
||||
> 返回该点是否是一个负数坐标
|
||||
|
||||
***
|
||||
<span id="struct_Point_OutOf"></span>
|
||||
|
||||
#### func (Point) OutOf(minWidth V, minHeight V, maxWidth V, maxHeight V) bool
|
||||
> 返回该点在特定宽高下是否越界f
|
||||
|
||||
***
|
||||
<span id="struct_Point_Equal"></span>
|
||||
|
||||
#### func (Point) Equal(point Point[V]) bool
|
||||
> 返回两个点是否相等
|
||||
|
||||
***
|
||||
<span id="struct_Point_Copy"></span>
|
||||
|
||||
#### func (Point) Copy() Point[V]
|
||||
> 复制一个点位置
|
||||
|
||||
***
|
||||
<span id="struct_Point_Add"></span>
|
||||
|
||||
#### func (Point) Add(point Point[V]) Point[V]
|
||||
> 得到加上 point 后的点
|
||||
|
||||
***
|
||||
<span id="struct_Point_Sub"></span>
|
||||
|
||||
#### func (Point) Sub(point Point[V]) Point[V]
|
||||
> 得到减去 point 后的点
|
||||
|
||||
***
|
||||
<span id="struct_Point_Mul"></span>
|
||||
|
||||
#### func (Point) Mul(point Point[V]) Point[V]
|
||||
> 得到乘以 point 后的点
|
||||
|
||||
***
|
||||
<span id="struct_Point_Div"></span>
|
||||
|
||||
#### func (Point) Div(point Point[V]) Point[V]
|
||||
> 得到除以 point 后的点
|
||||
|
||||
***
|
||||
<span id="struct_Point_Abs"></span>
|
||||
|
||||
#### func (Point) Abs() Point[V]
|
||||
> 返回位置的绝对值
|
||||
|
||||
***
|
||||
<span id="struct_Point_Max"></span>
|
||||
|
||||
#### func (Point) Max(point Point[V]) Point[V]
|
||||
> 返回两个位置中每个维度的最大值组成的新的位置
|
||||
|
||||
***
|
||||
<span id="struct_Point_Min"></span>
|
||||
|
||||
#### func (Point) Min(point Point[V]) Point[V]
|
||||
> 返回两个位置中每个维度的最小值组成的新的位置
|
||||
|
||||
***
|
||||
<span id="struct_PointCap"></span>
|
||||
### PointCap `STRUCT`
|
||||
|
@ -1012,8 +1105,11 @@ type PointCap[V generic.SignedNumber, D any] struct {
|
|||
Data D
|
||||
}
|
||||
```
|
||||
<span id="struct_PointCap_GetData"></span>
|
||||
|
||||
#### func (PointCap) GetData() D
|
||||
> 获取数据
|
||||
|
||||
***
|
||||
<span id="struct_Shape"></span>
|
||||
### Shape `STRUCT`
|
||||
|
@ -1021,8 +1117,11 @@ type PointCap[V generic.SignedNumber, D any] struct {
|
|||
```go
|
||||
type Shape[V generic.SignedNumber] []Point[V]
|
||||
```
|
||||
<span id="struct_Shape_Points"></span>
|
||||
|
||||
#### func (Shape) Points() []Point[V]
|
||||
> 获取这个形状的所有点
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -1059,8 +1158,11 @@ func TestShape_Points(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Shape_PointCount"></span>
|
||||
|
||||
#### func (Shape) PointCount() int
|
||||
> 获取这个形状的点数量
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -1092,15 +1194,24 @@ func TestShape_PointCount(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Shape_Contains"></span>
|
||||
|
||||
#### func (Shape) Contains(point Point[V]) bool
|
||||
> 返回该形状中是否包含点
|
||||
|
||||
***
|
||||
<span id="struct_Shape_ToCircle"></span>
|
||||
|
||||
#### func (Shape) ToCircle() Circle[V]
|
||||
> 将形状转换为圆形进行处理
|
||||
> - 当形状非圆形时将会产生意外情况
|
||||
|
||||
***
|
||||
<span id="struct_Shape_String"></span>
|
||||
|
||||
#### func (Shape) String() string
|
||||
> 将该形状转换为可视化的字符串进行返回
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -1133,6 +1244,8 @@ func TestShape_String(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Shape_ShapeSearch"></span>
|
||||
|
||||
#### func (Shape) ShapeSearch(options ...ShapeSearchOption) (result []Shape[V])
|
||||
> 获取该形状中包含的所有图形组合及其位置
|
||||
> - 需要注意的是,即便图形最终表示为相同的,但是只要位置组合顺序不同,那么也将被认定为一种图形组合
|
||||
|
@ -1140,6 +1253,7 @@ func TestShape_String(t *testing.T) {
|
|||
> - 返回的坐标为原始形状的坐标
|
||||
>
|
||||
> 可通过可选项对搜索结果进行过滤
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -1155,12 +1269,18 @@ func ExampleShape_ShapeSearch() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_Shape_Edges"></span>
|
||||
|
||||
#### func (Shape) Edges() (edges []LineSegment[V])
|
||||
> 获取该形状每一条边
|
||||
> - 该形状需要最少由3个点组成,否则将不会返回任意一边
|
||||
|
||||
***
|
||||
<span id="struct_Shape_IsPointOnEdge"></span>
|
||||
|
||||
#### func (Shape) IsPointOnEdge(point Point[V]) bool
|
||||
> 检查点是否在该形状的一条边上
|
||||
|
||||
***
|
||||
<span id="struct_ShapeSearchOption"></span>
|
||||
### ShapeSearchOption `STRUCT`
|
||||
|
|
|
@ -86,5 +86,8 @@ type Graph[Node comparable] interface {
|
|||
Neighbours(node Node) []Node
|
||||
}
|
||||
```
|
||||
<span id="struct_Graph_Neighbours"></span>
|
||||
|
||||
#### func (Graph) Neighbours(point geometry.Point[int]) []geometry.Point[int]
|
||||
|
||||
***
|
||||
|
|
|
@ -81,29 +81,47 @@ type DistributionPattern[Item any] struct {
|
|||
usePos bool
|
||||
}
|
||||
```
|
||||
<span id="struct_DistributionPattern_GetLinks"></span>
|
||||
|
||||
#### func (*DistributionPattern) GetLinks(pos int) (result []Link[Item])
|
||||
> 获取关联的成员
|
||||
> - 其中包含传入的 pos 成员
|
||||
|
||||
***
|
||||
<span id="struct_DistributionPattern_HasLink"></span>
|
||||
|
||||
#### func (*DistributionPattern) HasLink(pos int) bool
|
||||
> 检查一个位置是否包含除它本身外的其他关联成员
|
||||
|
||||
***
|
||||
<span id="struct_DistributionPattern_LoadMatrix"></span>
|
||||
|
||||
#### func (*DistributionPattern) LoadMatrix(matrix [][]Item)
|
||||
> 通过二维矩阵加载分布图
|
||||
> - 通过该函数加载的分布图使用的矩阵是复制后的矩阵,因此无法直接通过刷新(Refresh)来更新分布关系
|
||||
> - 需要通过直接刷新的方式请使用 LoadMatrixWithPos
|
||||
|
||||
***
|
||||
<span id="struct_DistributionPattern_LoadMatrixWithPos"></span>
|
||||
|
||||
#### func (*DistributionPattern) LoadMatrixWithPos(width int, matrix []Item)
|
||||
> 通过二维矩阵加载分布图
|
||||
|
||||
***
|
||||
<span id="struct_DistributionPattern_Refresh"></span>
|
||||
|
||||
#### func (*DistributionPattern) Refresh(pos int)
|
||||
> 刷新特定位置的分布关系
|
||||
> - 由于 LoadMatrix 的矩阵是复制后的矩阵,所以任何外部的改动都不会影响到分布图的变化,在这种情况下,刷新将没有任何意义
|
||||
> - 需要通过直接刷新的方式请使用 LoadMatrixWithPos 加载矩阵,或者通过 RefreshWithItem 函数进行刷新
|
||||
|
||||
***
|
||||
<span id="struct_DistributionPattern_RefreshWithItem"></span>
|
||||
|
||||
#### func (*DistributionPattern) RefreshWithItem(pos int, item Item)
|
||||
> 通过特定的成员刷新特定位置的分布关系
|
||||
> - 如果矩阵通过 LoadMatrixWithPos 加载,将会重定向至 Refresh
|
||||
|
||||
***
|
||||
<span id="struct_Link"></span>
|
||||
### Link `STRUCT`
|
||||
|
|
|
@ -47,52 +47,100 @@ type Matrix[T any] struct {
|
|||
m []T
|
||||
}
|
||||
```
|
||||
<span id="struct_Matrix_GetWidth"></span>
|
||||
|
||||
#### func (*Matrix) GetWidth() int
|
||||
> 获取二维矩阵宽度
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetHeight"></span>
|
||||
|
||||
#### func (*Matrix) GetHeight() int
|
||||
> 获取二维矩阵高度
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetWidth2Height"></span>
|
||||
|
||||
#### func (*Matrix) GetWidth2Height() (width int, height int)
|
||||
> 获取二维矩阵的宽度和高度
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetMatrix"></span>
|
||||
|
||||
#### func (*Matrix) GetMatrix() [][]T
|
||||
> 获取二维矩阵
|
||||
> - 通常建议使用 GetMatrixWithPos 进行处理这样将拥有更高的效率
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetMatrixWithPos"></span>
|
||||
|
||||
#### func (*Matrix) GetMatrixWithPos() []T
|
||||
> 获取顺序的矩阵
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Get"></span>
|
||||
|
||||
#### func (*Matrix) Get(x int, y int) (value T)
|
||||
> 获取特定坐标的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetExist"></span>
|
||||
|
||||
#### func (*Matrix) GetExist(x int, y int) (value T, exist bool)
|
||||
> 获取特定坐标的内容,如果不存在则返回 false
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_GetWithPos"></span>
|
||||
|
||||
#### func (*Matrix) GetWithPos(pos int) (value T)
|
||||
> 获取特定坐标的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Set"></span>
|
||||
|
||||
#### func (*Matrix) Set(x int, y int, data T)
|
||||
> 设置特定坐标的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_SetWithPos"></span>
|
||||
|
||||
#### func (*Matrix) SetWithPos(pos int, data T)
|
||||
> 设置特定坐标的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_Swap"></span>
|
||||
|
||||
#### func (*Matrix) Swap(x1 int, y1 int, x2 int, y2 int)
|
||||
> 交换两个位置的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_SwapWithPos"></span>
|
||||
|
||||
#### func (*Matrix) SwapWithPos(pos1 int, pos2 int)
|
||||
> 交换两个位置的内容
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_TrySwap"></span>
|
||||
|
||||
#### func (*Matrix) TrySwap(x1 int, y1 int, x2 int, y2 int, expressionHandle func (matrix *Matrix[T]) bool)
|
||||
> 尝试交换两个位置的内容,交换后不满足表达式时进行撤销
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_TrySwapWithPos"></span>
|
||||
|
||||
#### func (*Matrix) TrySwapWithPos(pos1 int, pos2 int, expressionHandle func (matrix *Matrix[T]) bool)
|
||||
> 尝试交换两个位置的内容,交换后不满足表达式时进行撤销
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_FillFull"></span>
|
||||
|
||||
#### func (*Matrix) FillFull(generateHandle func (x int) T)
|
||||
> 根据提供的生成器填充整个矩阵
|
||||
|
||||
***
|
||||
<span id="struct_Matrix_FillFullWithPos"></span>
|
||||
|
||||
#### func (*Matrix) FillFullWithPos(generateHandle func (pos int) T)
|
||||
> 根据提供的生成器填充整个矩阵
|
||||
|
||||
***
|
||||
|
|
|
@ -63,9 +63,14 @@ type NavMesh[V generic.SignedNumber] struct {
|
|||
meshShrinkAmount V
|
||||
}
|
||||
```
|
||||
<span id="struct_NavMesh_Neighbours"></span>
|
||||
|
||||
#### func (*NavMesh) Neighbours(node *shape[V]) []*shape[V]
|
||||
> 实现 astar.Graph 的接口,用于向 A* 算法提供相邻图形
|
||||
|
||||
***
|
||||
<span id="struct_NavMesh_Find"></span>
|
||||
|
||||
#### func (*NavMesh) Find(point geometry.Point[V], maxDistance V) (distance V, findPoint geometry.Point[V], findShape geometry.Shape[V])
|
||||
> 用于在 NavMesh 中查找离给定点最近的形状,并返回距离、找到的点和找到的形状。
|
||||
>
|
||||
|
@ -83,7 +88,10 @@ type NavMesh[V generic.SignedNumber] struct {
|
|||
> - 如果给定点不在任何形状内部或者形状的边上,将计算给定点到每个形状的距离,并找到最近的形状和对应的点。
|
||||
> - 距离的计算采用几何学中的投影点到形状的距离。
|
||||
> - 函数返回离给定点最近的形状的距离、找到的点和找到的形状。
|
||||
|
||||
***
|
||||
<span id="struct_NavMesh_FindPath"></span>
|
||||
|
||||
#### func (*NavMesh) FindPath(start geometry.Point[V], end geometry.Point[V]) (result []geometry.Point[V])
|
||||
> 函数用于在 NavMesh 中查找从起点到终点的路径,并返回路径上的点序列。
|
||||
>
|
||||
|
@ -99,6 +107,7 @@ type NavMesh[V generic.SignedNumber] struct {
|
|||
> - 如果起点或终点不在任何形状内部,且 NavMesh 的 meshShrinkAmount 大于0,则会考虑缩小的形状。
|
||||
> - 使用 A* 算法在 NavMesh 上搜索从起点形状到终点形状的最短路径。
|
||||
> - 使用漏斗算法对路径进行优化,以得到最终的路径点序列。
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
|
|
@ -100,8 +100,11 @@ type ObjectPool[T any] struct {
|
|||
releaser func(data T)
|
||||
}
|
||||
```
|
||||
<span id="struct_ObjectPool_Get"></span>
|
||||
|
||||
#### func (*ObjectPool) Get() T
|
||||
> 获取一个对象
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -137,8 +140,11 @@ func TestObjectPool_Get(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_ObjectPool_Release"></span>
|
||||
|
||||
#### func (*ObjectPool) Release(data T)
|
||||
> 将使用完成的对象放回缓冲区
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
|
|
@ -62,61 +62,124 @@
|
|||
```go
|
||||
type Float big.Float
|
||||
```
|
||||
<span id="struct_Float_Copy"></span>
|
||||
|
||||
#### func (*Float) Copy() *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Set"></span>
|
||||
|
||||
#### func (*Float) Set(i *Float) *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_IsZero"></span>
|
||||
|
||||
#### func (*Float) IsZero() bool
|
||||
|
||||
***
|
||||
<span id="struct_Float_ToBigFloat"></span>
|
||||
|
||||
#### func (*Float) ToBigFloat() *big.Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Cmp"></span>
|
||||
|
||||
#### func (*Float) Cmp(i *Float) int
|
||||
> 比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0
|
||||
|
||||
***
|
||||
<span id="struct_Float_GreaterThan"></span>
|
||||
|
||||
#### func (*Float) GreaterThan(i *Float) bool
|
||||
> 大于
|
||||
|
||||
***
|
||||
<span id="struct_Float_GreaterThanOrEqualTo"></span>
|
||||
|
||||
#### func (*Float) GreaterThanOrEqualTo(i *Float) bool
|
||||
> 大于或等于
|
||||
|
||||
***
|
||||
<span id="struct_Float_LessThan"></span>
|
||||
|
||||
#### func (*Float) LessThan(i *Float) bool
|
||||
> 小于
|
||||
|
||||
***
|
||||
<span id="struct_Float_LessThanOrEqualTo"></span>
|
||||
|
||||
#### func (*Float) LessThanOrEqualTo(i *Float) bool
|
||||
> 小于或等于
|
||||
|
||||
***
|
||||
<span id="struct_Float_EqualTo"></span>
|
||||
|
||||
#### func (*Float) EqualTo(i *Float) bool
|
||||
> 等于
|
||||
|
||||
***
|
||||
<span id="struct_Float_Float64"></span>
|
||||
|
||||
#### func (*Float) Float64() float64
|
||||
|
||||
***
|
||||
<span id="struct_Float_String"></span>
|
||||
|
||||
#### func (*Float) String() string
|
||||
|
||||
***
|
||||
<span id="struct_Float_Add"></span>
|
||||
|
||||
#### func (*Float) Add(i *Float) *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Sub"></span>
|
||||
|
||||
#### func (*Float) Sub(i *Float) *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Mul"></span>
|
||||
|
||||
#### func (*Float) Mul(i *Float) *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Div"></span>
|
||||
|
||||
#### func (*Float) Div(i *Float) *Float
|
||||
|
||||
***
|
||||
<span id="struct_Float_Sqrt"></span>
|
||||
|
||||
#### func (*Float) Sqrt() *Float
|
||||
> 平方根
|
||||
|
||||
***
|
||||
<span id="struct_Float_Abs"></span>
|
||||
|
||||
#### func (*Float) Abs() *Float
|
||||
> 返回数字的绝对值
|
||||
|
||||
***
|
||||
<span id="struct_Float_Sign"></span>
|
||||
|
||||
#### func (*Float) Sign() int
|
||||
> 返回数字的符号
|
||||
> - 1:正数
|
||||
> - 0:零
|
||||
> - -1:负数
|
||||
|
||||
***
|
||||
<span id="struct_Float_IsPositive"></span>
|
||||
|
||||
#### func (*Float) IsPositive() bool
|
||||
> 是否为正数
|
||||
|
||||
***
|
||||
<span id="struct_Float_IsNegative"></span>
|
||||
|
||||
#### func (*Float) IsNegative() bool
|
||||
> 是否为负数
|
||||
|
||||
***
|
||||
<span id="struct_Int"></span>
|
||||
### Int `STRUCT`
|
||||
|
@ -124,258 +187,591 @@ type Float big.Float
|
|||
```go
|
||||
type Int big.Int
|
||||
```
|
||||
<span id="struct_Int_Copy"></span>
|
||||
|
||||
#### func (*Int) Copy() *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Set"></span>
|
||||
|
||||
#### func (*Int) Set(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetInt"></span>
|
||||
|
||||
#### func (*Int) SetInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetInt8"></span>
|
||||
|
||||
#### func (*Int) SetInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetInt16"></span>
|
||||
|
||||
#### func (*Int) SetInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetInt32"></span>
|
||||
|
||||
#### func (*Int) SetInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetInt64"></span>
|
||||
|
||||
#### func (*Int) SetInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetUint"></span>
|
||||
|
||||
#### func (*Int) SetUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetUint8"></span>
|
||||
|
||||
#### func (*Int) SetUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetUint16"></span>
|
||||
|
||||
#### func (*Int) SetUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetUint32"></span>
|
||||
|
||||
#### func (*Int) SetUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetUint64"></span>
|
||||
|
||||
#### func (*Int) SetUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_IsZero"></span>
|
||||
|
||||
#### func (*Int) IsZero() bool
|
||||
|
||||
***
|
||||
<span id="struct_Int_ToBigint"></span>
|
||||
|
||||
#### func (*Int) ToBigint() *big.Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Cmp"></span>
|
||||
|
||||
#### func (*Int) Cmp(i *Int) int
|
||||
> 比较,当 slf > i 时返回 1,当 slf < i 时返回 -1,当 slf == i 时返回 0
|
||||
|
||||
***
|
||||
<span id="struct_Int_GreaterThan"></span>
|
||||
|
||||
#### func (*Int) GreaterThan(i *Int) bool
|
||||
> 大于
|
||||
|
||||
***
|
||||
<span id="struct_Int_GreaterThanOrEqualTo"></span>
|
||||
|
||||
#### func (*Int) GreaterThanOrEqualTo(i *Int) bool
|
||||
> 大于或等于
|
||||
|
||||
***
|
||||
<span id="struct_Int_LessThan"></span>
|
||||
|
||||
#### func (*Int) LessThan(i *Int) bool
|
||||
> 小于
|
||||
|
||||
***
|
||||
<span id="struct_Int_LessThanOrEqualTo"></span>
|
||||
|
||||
#### func (*Int) LessThanOrEqualTo(i *Int) bool
|
||||
> 小于或等于
|
||||
|
||||
***
|
||||
<span id="struct_Int_EqualTo"></span>
|
||||
|
||||
#### func (*Int) EqualTo(i *Int) bool
|
||||
> 等于
|
||||
|
||||
***
|
||||
<span id="struct_Int_Int64"></span>
|
||||
|
||||
#### func (*Int) Int64() int64
|
||||
|
||||
***
|
||||
<span id="struct_Int_String"></span>
|
||||
|
||||
#### func (*Int) String() string
|
||||
|
||||
***
|
||||
<span id="struct_Int_Add"></span>
|
||||
|
||||
#### func (*Int) Add(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddInt"></span>
|
||||
|
||||
#### func (*Int) AddInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddInt8"></span>
|
||||
|
||||
#### func (*Int) AddInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddInt16"></span>
|
||||
|
||||
#### func (*Int) AddInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddInt32"></span>
|
||||
|
||||
#### func (*Int) AddInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddInt64"></span>
|
||||
|
||||
#### func (*Int) AddInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddUint"></span>
|
||||
|
||||
#### func (*Int) AddUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddUint8"></span>
|
||||
|
||||
#### func (*Int) AddUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddUint16"></span>
|
||||
|
||||
#### func (*Int) AddUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddUint32"></span>
|
||||
|
||||
#### func (*Int) AddUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_AddUint64"></span>
|
||||
|
||||
#### func (*Int) AddUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Mul"></span>
|
||||
|
||||
#### func (*Int) Mul(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulInt"></span>
|
||||
|
||||
#### func (*Int) MulInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulInt8"></span>
|
||||
|
||||
#### func (*Int) MulInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulInt16"></span>
|
||||
|
||||
#### func (*Int) MulInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulInt32"></span>
|
||||
|
||||
#### func (*Int) MulInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulInt64"></span>
|
||||
|
||||
#### func (*Int) MulInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulUint"></span>
|
||||
|
||||
#### func (*Int) MulUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulUint8"></span>
|
||||
|
||||
#### func (*Int) MulUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulUint16"></span>
|
||||
|
||||
#### func (*Int) MulUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulUint32"></span>
|
||||
|
||||
#### func (*Int) MulUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_MulUint64"></span>
|
||||
|
||||
#### func (*Int) MulUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Sub"></span>
|
||||
|
||||
#### func (*Int) Sub(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubInt"></span>
|
||||
|
||||
#### func (*Int) SubInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubInt8"></span>
|
||||
|
||||
#### func (*Int) SubInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubInt16"></span>
|
||||
|
||||
#### func (*Int) SubInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubInt32"></span>
|
||||
|
||||
#### func (*Int) SubInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubInt64"></span>
|
||||
|
||||
#### func (*Int) SubInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubUint"></span>
|
||||
|
||||
#### func (*Int) SubUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubUint8"></span>
|
||||
|
||||
#### func (*Int) SubUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubUint16"></span>
|
||||
|
||||
#### func (*Int) SubUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubUint32"></span>
|
||||
|
||||
#### func (*Int) SubUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_SubUint64"></span>
|
||||
|
||||
#### func (*Int) SubUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Div"></span>
|
||||
|
||||
#### func (*Int) Div(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivInt"></span>
|
||||
|
||||
#### func (*Int) DivInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivInt8"></span>
|
||||
|
||||
#### func (*Int) DivInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivInt16"></span>
|
||||
|
||||
#### func (*Int) DivInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivInt32"></span>
|
||||
|
||||
#### func (*Int) DivInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivInt64"></span>
|
||||
|
||||
#### func (*Int) DivInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivUint"></span>
|
||||
|
||||
#### func (*Int) DivUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivUint8"></span>
|
||||
|
||||
#### func (*Int) DivUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivUint16"></span>
|
||||
|
||||
#### func (*Int) DivUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivUint32"></span>
|
||||
|
||||
#### func (*Int) DivUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_DivUint64"></span>
|
||||
|
||||
#### func (*Int) DivUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Mod"></span>
|
||||
|
||||
#### func (*Int) Mod(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInt"></span>
|
||||
|
||||
#### func (*Int) ModInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInt8"></span>
|
||||
|
||||
#### func (*Int) ModInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInt16"></span>
|
||||
|
||||
#### func (*Int) ModInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInt32"></span>
|
||||
|
||||
#### func (*Int) ModInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInt64"></span>
|
||||
|
||||
#### func (*Int) ModInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModUint"></span>
|
||||
|
||||
#### func (*Int) ModUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModUint8"></span>
|
||||
|
||||
#### func (*Int) ModUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModUint16"></span>
|
||||
|
||||
#### func (*Int) ModUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModUint32"></span>
|
||||
|
||||
#### func (*Int) ModUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModUint64"></span>
|
||||
|
||||
#### func (*Int) ModUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Pow"></span>
|
||||
|
||||
#### func (*Int) Pow(i *Int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowInt"></span>
|
||||
|
||||
#### func (*Int) PowInt(i int) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowInt8"></span>
|
||||
|
||||
#### func (*Int) PowInt8(i int8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowInt16"></span>
|
||||
|
||||
#### func (*Int) PowInt16(i int16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowInt32"></span>
|
||||
|
||||
#### func (*Int) PowInt32(i int32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowInt64"></span>
|
||||
|
||||
#### func (*Int) PowInt64(i int64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowUint"></span>
|
||||
|
||||
#### func (*Int) PowUint(i uint) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowUint8"></span>
|
||||
|
||||
#### func (*Int) PowUint8(i uint8) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowUint16"></span>
|
||||
|
||||
#### func (*Int) PowUint16(i uint16) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowUint32"></span>
|
||||
|
||||
#### func (*Int) PowUint32(i uint32) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_PowUint64"></span>
|
||||
|
||||
#### func (*Int) PowUint64(i uint64) *Int
|
||||
|
||||
***
|
||||
<span id="struct_Int_Lsh"></span>
|
||||
|
||||
#### func (*Int) Lsh(i int) *Int
|
||||
> 左移
|
||||
|
||||
***
|
||||
<span id="struct_Int_Rsh"></span>
|
||||
|
||||
#### func (*Int) Rsh(i int) *Int
|
||||
> 右移
|
||||
|
||||
***
|
||||
<span id="struct_Int_And"></span>
|
||||
|
||||
#### func (*Int) And(i *Int) *Int
|
||||
> 与
|
||||
|
||||
***
|
||||
<span id="struct_Int_AndNot"></span>
|
||||
|
||||
#### func (*Int) AndNot(i *Int) *Int
|
||||
> 与非
|
||||
|
||||
***
|
||||
<span id="struct_Int_Or"></span>
|
||||
|
||||
#### func (*Int) Or(i *Int) *Int
|
||||
> 或
|
||||
|
||||
***
|
||||
<span id="struct_Int_Xor"></span>
|
||||
|
||||
#### func (*Int) Xor(i *Int) *Int
|
||||
> 异或
|
||||
|
||||
***
|
||||
<span id="struct_Int_Not"></span>
|
||||
|
||||
#### func (*Int) Not() *Int
|
||||
> 非
|
||||
|
||||
***
|
||||
<span id="struct_Int_Sqrt"></span>
|
||||
|
||||
#### func (*Int) Sqrt() *Int
|
||||
> 平方根
|
||||
|
||||
***
|
||||
<span id="struct_Int_GCD"></span>
|
||||
|
||||
#### func (*Int) GCD(i *Int) *Int
|
||||
> 最大公约数
|
||||
|
||||
***
|
||||
<span id="struct_Int_LCM"></span>
|
||||
|
||||
#### func (*Int) LCM(i *Int) *Int
|
||||
> 最小公倍数
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModInverse"></span>
|
||||
|
||||
#### func (*Int) ModInverse(i *Int) *Int
|
||||
> 模反元素
|
||||
|
||||
***
|
||||
<span id="struct_Int_ModSqrt"></span>
|
||||
|
||||
#### func (*Int) ModSqrt(i *Int) *Int
|
||||
> 模平方根
|
||||
|
||||
***
|
||||
<span id="struct_Int_BitLen"></span>
|
||||
|
||||
#### func (*Int) BitLen() int
|
||||
> 二进制长度
|
||||
|
||||
***
|
||||
<span id="struct_Int_Bit"></span>
|
||||
|
||||
#### func (*Int) Bit(i int) uint
|
||||
> 二进制位
|
||||
|
||||
***
|
||||
<span id="struct_Int_SetBit"></span>
|
||||
|
||||
#### func (*Int) SetBit(i int, v uint) *Int
|
||||
> 设置二进制位
|
||||
|
||||
***
|
||||
<span id="struct_Int_Neg"></span>
|
||||
|
||||
#### func (*Int) Neg() *Int
|
||||
> 返回数字的相反数
|
||||
|
||||
***
|
||||
<span id="struct_Int_Abs"></span>
|
||||
|
||||
#### func (*Int) Abs() *Int
|
||||
> 返回数字的绝对值
|
||||
|
||||
***
|
||||
<span id="struct_Int_Sign"></span>
|
||||
|
||||
#### func (*Int) Sign() int
|
||||
> 返回数字的符号
|
||||
> - 1:正数
|
||||
> - 0:零
|
||||
> - -1:负数
|
||||
|
||||
***
|
||||
<span id="struct_Int_IsPositive"></span>
|
||||
|
||||
#### func (*Int) IsPositive() bool
|
||||
> 是否为正数
|
||||
|
||||
***
|
||||
<span id="struct_Int_IsNegative"></span>
|
||||
|
||||
#### func (*Int) IsNegative() bool
|
||||
> 是否为负数
|
||||
|
||||
***
|
||||
<span id="struct_Int_IsEven"></span>
|
||||
|
||||
#### func (*Int) IsEven() bool
|
||||
> 是否为偶数
|
||||
|
||||
***
|
||||
<span id="struct_Int_IsOdd"></span>
|
||||
|
||||
#### func (*Int) IsOdd() bool
|
||||
> 是否为奇数
|
||||
|
||||
***
|
||||
<span id="struct_Int_ProportionalCalc"></span>
|
||||
|
||||
#### func (*Int) ProportionalCalc(proportional *Int, formula func (v *Int) *Int) *Int
|
||||
> 比例计算,该函数会再 formula 返回值的基础上除以 proportional
|
||||
> - formula 为计算公式,该公式的参数为调用该函数的 Int 的拷贝
|
||||
|
||||
***
|
||||
|
|
|
@ -76,9 +76,12 @@ type BinarySearch[CompetitorID comparable, Score generic.Ordered] struct {
|
|||
rankClearBeforeEventHandles []BinarySearchRankClearBeforeEventHandle[CompetitorID, Score]
|
||||
}
|
||||
```
|
||||
<span id="struct_BinarySearch_Competitor"></span>
|
||||
|
||||
#### func (*BinarySearch) Competitor(competitorId CompetitorID, score Score)
|
||||
> 声明排行榜竞争者
|
||||
> - 如果竞争者存在的情况下,会更新已有成绩,否则新增竞争者
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -97,8 +100,11 @@ func ExampleBinarySearch_Competitor() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_RemoveCompetitor"></span>
|
||||
|
||||
#### func (*BinarySearch) RemoveCompetitor(competitorId CompetitorID)
|
||||
> 删除特定竞争者
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -118,16 +124,25 @@ func ExampleBinarySearch_RemoveCompetitor() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_Size"></span>
|
||||
|
||||
#### func (*BinarySearch) Size() int
|
||||
> 获取竞争者数量
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetRankDefault"></span>
|
||||
|
||||
#### func (*BinarySearch) GetRankDefault(competitorId CompetitorID, defaultValue int) int
|
||||
> 获取竞争者排名,如果竞争者不存在则返回默认值
|
||||
> - 排名从 0 开始
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetRank"></span>
|
||||
|
||||
#### func (*BinarySearch) GetRank(competitorId CompetitorID) ( int, error)
|
||||
> 获取竞争者排名
|
||||
> - 排名从 0 开始
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -144,38 +159,77 @@ func ExampleBinarySearch_GetRank() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetCompetitor"></span>
|
||||
|
||||
#### func (*BinarySearch) GetCompetitor(rank int) (competitorId CompetitorID, err error)
|
||||
> 获取特定排名的竞争者
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetCompetitorWithRange"></span>
|
||||
|
||||
#### func (*BinarySearch) GetCompetitorWithRange(start int, end int) ( []CompetitorID, error)
|
||||
> 获取第start名到第end名竞争者
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetScore"></span>
|
||||
|
||||
#### func (*BinarySearch) GetScore(competitorId CompetitorID) (score Score, err error)
|
||||
> 获取竞争者成绩
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetScoreDefault"></span>
|
||||
|
||||
#### func (*BinarySearch) GetScoreDefault(competitorId CompetitorID, defaultValue Score) Score
|
||||
> 获取竞争者成绩,不存在时返回默认值
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_GetAllCompetitor"></span>
|
||||
|
||||
#### func (*BinarySearch) GetAllCompetitor() []CompetitorID
|
||||
> 获取所有竞争者ID
|
||||
> - 结果为名次有序的
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_Clear"></span>
|
||||
|
||||
#### func (*BinarySearch) Clear()
|
||||
> 清空排行榜
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_Cmp"></span>
|
||||
|
||||
#### func (*BinarySearch) Cmp(s1 Score, s2 Score) int
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_UnmarshalJSON"></span>
|
||||
|
||||
#### func (*BinarySearch) UnmarshalJSON(bytes []byte) error
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_MarshalJSON"></span>
|
||||
|
||||
#### func (*BinarySearch) MarshalJSON() ( []byte, error)
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_RegRankChangeEvent"></span>
|
||||
|
||||
#### func (*BinarySearch) RegRankChangeEvent(handle BinarySearchRankChangeEventHandle[CompetitorID, Score])
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_OnRankChangeEvent"></span>
|
||||
|
||||
#### func (*BinarySearch) OnRankChangeEvent(competitorId CompetitorID, oldRank int, newRank int, oldScore Score, newScore Score)
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_RegRankClearBeforeEvent"></span>
|
||||
|
||||
#### func (*BinarySearch) RegRankClearBeforeEvent(handle BinarySearchRankClearBeforeEventHandle[CompetitorID, Score])
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearch_OnRankClearBeforeEvent"></span>
|
||||
|
||||
#### func (*BinarySearch) OnRankClearBeforeEvent()
|
||||
|
||||
***
|
||||
<span id="struct_BinarySearchRankChangeEventHandle"></span>
|
||||
### BinarySearchRankChangeEventHandle `STRUCT`
|
||||
|
|
|
@ -415,13 +415,25 @@ type MultiHandler struct {
|
|||
handlers []slog.Handler
|
||||
}
|
||||
```
|
||||
<span id="struct_MultiHandler_Enabled"></span>
|
||||
|
||||
#### func (MultiHandler) Enabled(ctx context.Context, level slog.Level) bool
|
||||
|
||||
***
|
||||
<span id="struct_MultiHandler_Handle"></span>
|
||||
|
||||
#### func (MultiHandler) Handle(ctx context.Context, record slog.Record) (err error)
|
||||
|
||||
***
|
||||
<span id="struct_MultiHandler_WithAttrs"></span>
|
||||
|
||||
#### func (MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler
|
||||
|
||||
***
|
||||
<span id="struct_MultiHandler_WithGroup"></span>
|
||||
|
||||
#### func (MultiHandler) WithGroup(name string) slog.Handler
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
|
|
@ -166,32 +166,58 @@ type Analyzer struct {
|
|||
m sync.Mutex
|
||||
}
|
||||
```
|
||||
<span id="struct_Analyzer_Sub"></span>
|
||||
|
||||
#### func (*Analyzer) Sub(key string) *Analyzer
|
||||
> 获取子分析器
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetFormat"></span>
|
||||
|
||||
#### func (*Analyzer) SetFormat(key string, format func (v any) any)
|
||||
> 设置格式化函数
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValueIfGreaterThan"></span>
|
||||
|
||||
#### func (*Analyzer) SetValueIfGreaterThan(key string, value float64)
|
||||
> 设置指定 key 的值,当新值大于旧值时
|
||||
> - 当已有值不为 float64 时,将会被忽略
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValueIfLessThan"></span>
|
||||
|
||||
#### func (*Analyzer) SetValueIfLessThan(key string, value float64)
|
||||
> 设置指定 key 的值,当新值小于旧值时
|
||||
> - 当已有值不为 float64 时,将会被忽略
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValueIf"></span>
|
||||
|
||||
#### func (*Analyzer) SetValueIf(key string, expression bool, value float64)
|
||||
> 当表达式满足的时候将设置指定 key 的值为 value
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValueStringIf"></span>
|
||||
|
||||
#### func (*Analyzer) SetValueStringIf(key string, expression bool, value string)
|
||||
> 当表达式满足的时候将设置指定 key 的值为 value
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValue"></span>
|
||||
|
||||
#### func (*Analyzer) SetValue(key string, value float64)
|
||||
> 设置指定 key 的值
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_SetValueString"></span>
|
||||
|
||||
#### func (*Analyzer) SetValueString(key string, value string)
|
||||
> 设置指定 key 的值
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_Increase"></span>
|
||||
|
||||
#### func (*Analyzer) Increase(key string, record R, recordKey string)
|
||||
> 在指定 key 现有值的基础上增加 recordKey 的值
|
||||
> - 当分析器已经记录过相同 key 的值时,会根据已有的值类型进行不同处理
|
||||
|
@ -199,21 +225,37 @@ type Analyzer struct {
|
|||
> 处理方式:
|
||||
> - 当已有值类型为 string 时,将会使用新的值的 string 类型进行覆盖
|
||||
> - 当已有值类型为 float64 时,当新的值类型不为 float64 时,将会被忽略
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_IncreaseValue"></span>
|
||||
|
||||
#### func (*Analyzer) IncreaseValue(key string, value float64)
|
||||
> 在指定 key 现有值的基础上增加 value
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_IncreaseNonRepeat"></span>
|
||||
|
||||
#### func (*Analyzer) IncreaseNonRepeat(key string, record R, recordKey string, dimension ...string)
|
||||
> 在指定 key 现有值的基础上增加 recordKey 的值,但是当去重维度 dimension 相同时,不会增加
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_IncreaseValueNonRepeat"></span>
|
||||
|
||||
#### func (*Analyzer) IncreaseValueNonRepeat(key string, record R, value float64, dimension ...string)
|
||||
> 在指定 key 现有值的基础上增加 value,但是当去重维度 dimension 相同时,不会增加
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_GetValue"></span>
|
||||
|
||||
#### func (*Analyzer) GetValue(key string) float64
|
||||
> 获取当前记录的值
|
||||
|
||||
***
|
||||
<span id="struct_Analyzer_GetValueString"></span>
|
||||
|
||||
#### func (*Analyzer) GetValueString(key string) string
|
||||
> 获取当前记录的值
|
||||
|
||||
***
|
||||
<span id="struct_Flusher"></span>
|
||||
### Flusher `INTERFACE`
|
||||
|
@ -236,9 +278,15 @@ type FileFlusher struct {
|
|||
layoutLen int
|
||||
}
|
||||
```
|
||||
<span id="struct_FileFlusher_Flush"></span>
|
||||
|
||||
#### func (*FileFlusher) Flush(records []string)
|
||||
|
||||
***
|
||||
<span id="struct_FileFlusher_Info"></span>
|
||||
|
||||
#### func (*FileFlusher) Info() string
|
||||
|
||||
***
|
||||
<span id="struct_Option"></span>
|
||||
### Option `STRUCT`
|
||||
|
@ -258,33 +306,60 @@ type Result gjson.Result
|
|||
```go
|
||||
type R string
|
||||
```
|
||||
<span id="struct_R_GetTime"></span>
|
||||
|
||||
#### func (R) GetTime(layout string) time.Time
|
||||
> 获取该记录的时间
|
||||
|
||||
***
|
||||
<span id="struct_R_Get"></span>
|
||||
|
||||
#### func (R) Get(key string) Result
|
||||
> 获取指定 key 的值
|
||||
> - 当 key 为嵌套 key 时,使用 . 进行分割,例如:a.b.c
|
||||
> - 更多用法参考:https://github.com/tidwall/gjson
|
||||
|
||||
***
|
||||
<span id="struct_R_Exist"></span>
|
||||
|
||||
#### func (R) Exist(key string) bool
|
||||
> 判断指定 key 是否存在
|
||||
|
||||
***
|
||||
<span id="struct_R_GetString"></span>
|
||||
|
||||
#### func (R) GetString(key string) string
|
||||
> 该函数为 Get(key).String() 的简写
|
||||
|
||||
***
|
||||
<span id="struct_R_GetInt64"></span>
|
||||
|
||||
#### func (R) GetInt64(key string) int64
|
||||
> 该函数为 Get(key).Int() 的简写
|
||||
|
||||
***
|
||||
<span id="struct_R_GetInt"></span>
|
||||
|
||||
#### func (R) GetInt(key string) int
|
||||
> 该函数为 Get(key).Int() 的简写,但是返回值为 int 类型
|
||||
|
||||
***
|
||||
<span id="struct_R_GetFloat64"></span>
|
||||
|
||||
#### func (R) GetFloat64(key string) float64
|
||||
> 该函数为 Get(key).Float() 的简写
|
||||
|
||||
***
|
||||
<span id="struct_R_GetBool"></span>
|
||||
|
||||
#### func (R) GetBool(key string) bool
|
||||
> 该函数为 Get(key).Bool() 的简写
|
||||
|
||||
***
|
||||
<span id="struct_R_String"></span>
|
||||
|
||||
#### func (R) String() string
|
||||
|
||||
***
|
||||
<span id="struct_Report"></span>
|
||||
### Report `STRUCT`
|
||||
|
@ -298,26 +373,50 @@ type Report struct {
|
|||
Subs []*Report
|
||||
}
|
||||
```
|
||||
<span id="struct_Report_Avg"></span>
|
||||
|
||||
#### func (*Report) Avg(key string) float64
|
||||
> 计算平均值
|
||||
|
||||
***
|
||||
<span id="struct_Report_Count"></span>
|
||||
|
||||
#### func (*Report) Count(key string) int64
|
||||
> 获取特定 key 的计数次数
|
||||
|
||||
***
|
||||
<span id="struct_Report_Sum"></span>
|
||||
|
||||
#### func (*Report) Sum(keys ...string) float64
|
||||
> 获取特定 key 的总和
|
||||
|
||||
***
|
||||
<span id="struct_Report_Sub"></span>
|
||||
|
||||
#### func (*Report) Sub(name string) *Report
|
||||
> 获取特定名称的子报告
|
||||
|
||||
***
|
||||
<span id="struct_Report_ReserveSubByPrefix"></span>
|
||||
|
||||
#### func (*Report) ReserveSubByPrefix(prefix string) *Report
|
||||
> 仅保留特定前缀的子报告
|
||||
|
||||
***
|
||||
<span id="struct_Report_ReserveSub"></span>
|
||||
|
||||
#### func (*Report) ReserveSub(names ...string) *Report
|
||||
> 仅保留特定名称子报告
|
||||
|
||||
***
|
||||
<span id="struct_Report_FilterSub"></span>
|
||||
|
||||
#### func (*Report) FilterSub(names ...string) *Report
|
||||
> 将特定名称的子报告过滤掉
|
||||
|
||||
***
|
||||
<span id="struct_Report_String"></span>
|
||||
|
||||
#### func (*Report) String() string
|
||||
|
||||
***
|
||||
|
|
|
@ -107,10 +107,13 @@ type Option struct {
|
|||
delay time.Duration
|
||||
}
|
||||
```
|
||||
<span id="struct_Option_WithPeriodicity"></span>
|
||||
|
||||
#### func (*Option) WithPeriodicity(ticker *timer.Ticker, firstDelay time.Duration, interval time.Duration, delay time.Duration) *Option
|
||||
> 设置持久化周期
|
||||
> - ticker 定时器,通常建议使用服务器的定时器,这样可以降低多线程的程序复杂性
|
||||
> - firstDelay 首次持久化延迟,当首次持久化为 0 时,将会在下一个持久化周期开始时持久化
|
||||
> - interval 持久化间隔
|
||||
> - delay 每条数据持久化间隔,适当的设置该值可以使持久化期间尽量降低对用户体验的影响,如果为0,将会一次性持久化所有数据
|
||||
|
||||
***
|
||||
|
|
|
@ -115,8 +115,11 @@ type TwoDimensional[EID generic.Basic, PosType generic.SignedNumber] struct {
|
|||
position2DStopMoveEventHandles []Position2DStopMoveEventHandle[EID, PosType]
|
||||
}
|
||||
```
|
||||
<span id="struct_TwoDimensional_MoveTo"></span>
|
||||
|
||||
#### func (*TwoDimensional) MoveTo(entity TwoDimensionalEntity[EID, PosType], x PosType, y PosType)
|
||||
> 设置对象移动到特定位置
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -140,8 +143,11 @@ func ExampleTwoDimensional_MoveTo() {
|
|||
```
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_StopMove"></span>
|
||||
|
||||
#### func (*TwoDimensional) StopMove(id EID)
|
||||
> 停止特定对象的移动
|
||||
|
||||
**示例代码:**
|
||||
|
||||
```go
|
||||
|
@ -215,23 +221,44 @@ func TestTwoDimensional_StopMove(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_RegPosition2DChangeEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) RegPosition2DChangeEvent(handle Position2DChangeEventHandle[EID, PosType])
|
||||
> 在对象位置改变时将执行注册的事件处理函数
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_OnPosition2DChangeEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) OnPosition2DChangeEvent(entity TwoDimensionalEntity[EID, PosType], oldX PosType, oldY PosType)
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_RegPosition2DDestinationEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) RegPosition2DDestinationEvent(handle Position2DDestinationEventHandle[EID, PosType])
|
||||
> 在对象到达终点时将执行被注册的事件处理函数
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_OnPosition2DDestinationEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) OnPosition2DDestinationEvent(entity TwoDimensionalEntity[EID, PosType])
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_RegPosition2DStopMoveEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) RegPosition2DStopMoveEvent(handle Position2DStopMoveEventHandle[EID, PosType])
|
||||
> 在对象停止移动时将执行被注册的事件处理函数
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_OnPosition2DStopMoveEvent"></span>
|
||||
|
||||
#### func (*TwoDimensional) OnPosition2DStopMoveEvent(entity TwoDimensionalEntity[EID, PosType])
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensional_Release"></span>
|
||||
|
||||
#### func (*TwoDimensional) Release()
|
||||
> 释放对象移动对象所占用的资源
|
||||
|
||||
***
|
||||
<span id="struct_TwoDimensionalEntity"></span>
|
||||
### TwoDimensionalEntity `INTERFACE`
|
||||
|
|
|
@ -67,12 +67,21 @@ type Time struct {
|
|||
offset time.Duration
|
||||
}
|
||||
```
|
||||
<span id="struct_Time_SetOffset"></span>
|
||||
|
||||
#### func (*Time) SetOffset(offset time.Duration)
|
||||
> 设置时间偏移
|
||||
|
||||
***
|
||||
<span id="struct_Time_Now"></span>
|
||||
|
||||
#### func (*Time) Now() time.Time
|
||||
> 获取当前时间偏移后的时间
|
||||
|
||||
***
|
||||
<span id="struct_Time_Since"></span>
|
||||
|
||||
#### func (*Time) Since(t time.Time) time.Duration
|
||||
> 获取当前时间偏移后的时间自从 t 以来经过的时间
|
||||
|
||||
***
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|[DiceN](#DiceN)|掷骰子
|
||||
|[NetIP](#NetIP)|返回一个随机的IP地址
|
||||
|[Port](#Port)|返回一个随机的端口号
|
||||
|[UsablePort](#UsablePort)|随机返回一个可用的端口号,如果没有可用端口号则返回 -1
|
||||
|[IPv4](#IPv4)|返回一个随机产生的IPv4地址。
|
||||
|[IPv4Port](#IPv4Port)|返回一个随机产生的IPv4地址和端口。
|
||||
|[Int64](#Int64)|返回一个介于min和max之间的int64类型的随机数。
|
||||
|
@ -73,6 +74,11 @@
|
|||
<span id="Port"></span>
|
||||
> 返回一个随机的端口号
|
||||
|
||||
***
|
||||
#### func UsablePort() int
|
||||
<span id="UsablePort"></span>
|
||||
> 随机返回一个可用的端口号,如果没有可用端口号则返回 -1
|
||||
|
||||
***
|
||||
#### func IPv4() string
|
||||
<span id="IPv4"></span>
|
||||
|
|
|
@ -133,9 +133,15 @@ type Once[V any] struct {
|
|||
r map[any]struct{}
|
||||
}
|
||||
```
|
||||
<span id="struct_Once_Get"></span>
|
||||
|
||||
#### func (*Once) Get(key any, value V, defaultValue V) V
|
||||
> 获取一个值,当该值已经被获取过的时候,返回 defaultValue,否则返回 value
|
||||
|
||||
***
|
||||
<span id="struct_Once_Reset"></span>
|
||||
|
||||
#### func (*Once) Reset(key ...any)
|
||||
> 当 key 数量大于 0 时,将会重置对应 key 的记录,否则重置所有记录
|
||||
|
||||
***
|
||||
|
|
|
@ -752,8 +752,11 @@ type BitSet[Bit generic.Integer] struct {
|
|||
set []uint64
|
||||
}
|
||||
```
|
||||
<span id="struct_BitSet_Set"></span>
|
||||
|
||||
#### func (*BitSet) Set(bit Bit) *BitSet[Bit]
|
||||
> 将指定的位 bit 设置为 1
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -775,8 +778,11 @@ func TestBitSet_Set(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Del"></span>
|
||||
|
||||
#### func (*BitSet) Del(bit Bit) *BitSet[Bit]
|
||||
> 将指定的位 bit 设置为 0
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -799,9 +805,12 @@ func TestBitSet_Del(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Shrink"></span>
|
||||
|
||||
#### func (*BitSet) Shrink() *BitSet[Bit]
|
||||
> 将 BitSet 中的比特位集合缩小到最小
|
||||
> - 正常情况下当 BitSet 中的比特位超出 64 位时,将自动增长,当 BitSet 中的比特位数量减少时,可以使用该方法将 BitSet 中的比特位集合缩小到最小
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -825,92 +834,179 @@ func TestBitSet_Shrink(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Cap"></span>
|
||||
|
||||
#### func (*BitSet) Cap() int
|
||||
> 返回当前 BitSet 中可以表示的最大比特位数量
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Has"></span>
|
||||
|
||||
#### func (*BitSet) Has(bit Bit) bool
|
||||
> 检查指定的位 bit 是否被设置为 1
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Clear"></span>
|
||||
|
||||
#### func (*BitSet) Clear() *BitSet[Bit]
|
||||
> 清空所有的比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Len"></span>
|
||||
|
||||
#### func (*BitSet) Len() int
|
||||
> 返回当前 BitSet 中被设置的比特位数量
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Bits"></span>
|
||||
|
||||
#### func (*BitSet) Bits() []Bit
|
||||
> 返回当前 BitSet 中被设置的比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Reverse"></span>
|
||||
|
||||
#### func (*BitSet) Reverse() *BitSet[Bit]
|
||||
> 反转当前 BitSet 中的所有比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Not"></span>
|
||||
|
||||
#### func (*BitSet) Not() *BitSet[Bit]
|
||||
> 返回当前 BitSet 中所有比特位的反转
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_And"></span>
|
||||
|
||||
#### func (*BitSet) And(other *BitSet[Bit]) *BitSet[Bit]
|
||||
> 将当前 BitSet 与另一个 BitSet 进行按位与运算
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Or"></span>
|
||||
|
||||
#### func (*BitSet) Or(other *BitSet[Bit]) *BitSet[Bit]
|
||||
> 将当前 BitSet 与另一个 BitSet 进行按位或运算
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Xor"></span>
|
||||
|
||||
#### func (*BitSet) Xor(other *BitSet[Bit]) *BitSet[Bit]
|
||||
> 将当前 BitSet 与另一个 BitSet 进行按位异或运算
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Sub"></span>
|
||||
|
||||
#### func (*BitSet) Sub(other *BitSet[Bit]) *BitSet[Bit]
|
||||
> 将当前 BitSet 与另一个 BitSet 进行按位减运算
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_IsZero"></span>
|
||||
|
||||
#### func (*BitSet) IsZero() bool
|
||||
> 检查当前 BitSet 是否为空
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Clone"></span>
|
||||
|
||||
#### func (*BitSet) Clone() *BitSet[Bit]
|
||||
> 返回当前 BitSet 的副本
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Equal"></span>
|
||||
|
||||
#### func (*BitSet) Equal(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否与另一个 BitSet 相等
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Contains"></span>
|
||||
|
||||
#### func (*BitSet) Contains(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否包含另一个 BitSet
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_ContainsAny"></span>
|
||||
|
||||
#### func (*BitSet) ContainsAny(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否包含另一个 BitSet 中的任意比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_ContainsAll"></span>
|
||||
|
||||
#### func (*BitSet) ContainsAll(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否包含另一个 BitSet 中的所有比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Intersect"></span>
|
||||
|
||||
#### func (*BitSet) Intersect(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否与另一个 BitSet 有交集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Union"></span>
|
||||
|
||||
#### func (*BitSet) Union(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否与另一个 BitSet 有并集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Difference"></span>
|
||||
|
||||
#### func (*BitSet) Difference(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否与另一个 BitSet 有差集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_SymmetricDifference"></span>
|
||||
|
||||
#### func (*BitSet) SymmetricDifference(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否与另一个 BitSet 有对称差集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Subset"></span>
|
||||
|
||||
#### func (*BitSet) Subset(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否为另一个 BitSet 的子集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Superset"></span>
|
||||
|
||||
#### func (*BitSet) Superset(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否为另一个 BitSet 的超集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Complement"></span>
|
||||
|
||||
#### func (*BitSet) Complement(other *BitSet[Bit]) bool
|
||||
> 检查当前 BitSet 是否为另一个 BitSet 的补集
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Max"></span>
|
||||
|
||||
#### func (*BitSet) Max() Bit
|
||||
> 返回当前 BitSet 中最大的比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_Min"></span>
|
||||
|
||||
#### func (*BitSet) Min() Bit
|
||||
> 返回当前 BitSet 中最小的比特位
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_String"></span>
|
||||
|
||||
#### func (*BitSet) String() string
|
||||
> 返回当前 BitSet 的字符串表示
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_MarshalJSON"></span>
|
||||
|
||||
#### func (*BitSet) MarshalJSON() ( []byte, error)
|
||||
> 实现 json.Marshaler 接口
|
||||
|
||||
***
|
||||
<span id="struct_BitSet_UnmarshalJSON"></span>
|
||||
|
||||
#### func (*BitSet) UnmarshalJSON(data []byte) error
|
||||
> 实现 json.Unmarshaler 接口
|
||||
|
||||
***
|
||||
<span id="struct_LossCounter"></span>
|
||||
### LossCounter `STRUCT`
|
||||
|
@ -922,13 +1018,22 @@ type LossCounter struct {
|
|||
lossKey []string
|
||||
}
|
||||
```
|
||||
<span id="struct_LossCounter_Record"></span>
|
||||
|
||||
#### func (*LossCounter) Record(name string)
|
||||
> 记录一次损耗
|
||||
|
||||
***
|
||||
<span id="struct_LossCounter_GetLoss"></span>
|
||||
|
||||
#### func (*LossCounter) GetLoss(handler func (step int, name string, loss time.Duration))
|
||||
> 获取损耗
|
||||
|
||||
***
|
||||
<span id="struct_LossCounter_String"></span>
|
||||
|
||||
#### func (*LossCounter) String() string
|
||||
|
||||
***
|
||||
<span id="struct_Matcher"></span>
|
||||
### Matcher `STRUCT`
|
||||
|
@ -940,11 +1045,17 @@ type Matcher[Value any, Result any] struct {
|
|||
d bool
|
||||
}
|
||||
```
|
||||
<span id="struct_Matcher_Case"></span>
|
||||
|
||||
#### func (*Matcher) Case(value Value, result Result) *Matcher[Value, Result]
|
||||
> 匹配
|
||||
|
||||
***
|
||||
<span id="struct_Matcher_Default"></span>
|
||||
|
||||
#### func (*Matcher) Default(value Result) Result
|
||||
> 默认
|
||||
|
||||
***
|
||||
<span id="struct_Permission"></span>
|
||||
### Permission `STRUCT`
|
||||
|
@ -955,17 +1066,29 @@ type Permission[Code generic.Integer, EntityID comparable] struct {
|
|||
l sync.RWMutex
|
||||
}
|
||||
```
|
||||
<span id="struct_Permission_HasPermission"></span>
|
||||
|
||||
#### func (*Permission) HasPermission(entityId EntityID, permission Code) bool
|
||||
> 是否有权限
|
||||
|
||||
***
|
||||
<span id="struct_Permission_AddPermission"></span>
|
||||
|
||||
#### func (*Permission) AddPermission(entityId EntityID, permission ...Code)
|
||||
> 添加权限
|
||||
|
||||
***
|
||||
<span id="struct_Permission_RemovePermission"></span>
|
||||
|
||||
#### func (*Permission) RemovePermission(entityId EntityID, permission ...Code)
|
||||
> 移除权限
|
||||
|
||||
***
|
||||
<span id="struct_Permission_SetPermission"></span>
|
||||
|
||||
#### func (*Permission) SetPermission(entityId EntityID, permission ...Code)
|
||||
> 设置权限
|
||||
|
||||
***
|
||||
<span id="struct_StackGo"></span>
|
||||
### StackGo `STRUCT`
|
||||
|
@ -978,19 +1101,28 @@ type StackGo struct {
|
|||
collect chan []byte
|
||||
}
|
||||
```
|
||||
<span id="struct_StackGo_Wait"></span>
|
||||
|
||||
#### func (*StackGo) Wait()
|
||||
> 等待收集消息堆栈
|
||||
> - 在调用 Wait 函数后,当前协程将会被挂起,直到调用 Stack 或 GiveUp 函数
|
||||
|
||||
***
|
||||
<span id="struct_StackGo_Stack"></span>
|
||||
|
||||
#### func (*StackGo) Stack() []byte
|
||||
> 获取消息堆栈
|
||||
> - 在调用 Wait 函数后调用该函数,将会返回上一个协程的堆栈信息
|
||||
> - 在调用 GiveUp 函数后调用该函数,将会 panic
|
||||
|
||||
***
|
||||
<span id="struct_StackGo_GiveUp"></span>
|
||||
|
||||
#### func (*StackGo) GiveUp()
|
||||
> 放弃收集消息堆栈
|
||||
> - 在调用 Wait 函数后调用该函数,将会放弃收集消息堆栈并且释放资源
|
||||
> - 在调用 GiveUp 函数后调用 Stack 函数,将会 panic
|
||||
|
||||
***
|
||||
<span id="struct_VerifyHandle"></span>
|
||||
### VerifyHandle `STRUCT`
|
||||
|
@ -1002,13 +1134,22 @@ type VerifyHandle[V any] struct {
|
|||
hit bool
|
||||
}
|
||||
```
|
||||
<span id="struct_VerifyHandle_PreCase"></span>
|
||||
|
||||
#### func (*VerifyHandle) PreCase(expression func () bool, value V, caseHandle func (verify *VerifyHandle[V]) bool) bool
|
||||
> 先决校验用例,当 expression 成立时,将跳过 caseHandle 的执行,直接执行 handle 并返回 false
|
||||
> - 常用于对前置参数的空指针校验,例如当 a 为 nil 时,不执行 a.B(),而是直接返回 false
|
||||
|
||||
***
|
||||
<span id="struct_VerifyHandle_Case"></span>
|
||||
|
||||
#### func (*VerifyHandle) Case(expression bool, value V) *VerifyHandle[V]
|
||||
> 校验用例,当 expression 成立时,将忽略后续 Case,并将在 Do 时执行 handle,返回 false
|
||||
|
||||
***
|
||||
<span id="struct_VerifyHandle_Do"></span>
|
||||
|
||||
#### func (*VerifyHandle) Do() bool
|
||||
> 执行校验,当校验失败时,将执行 handle,并返回 false
|
||||
|
||||
***
|
||||
|
|
|
@ -115,16 +115,25 @@ type Pool struct {
|
|||
closed bool
|
||||
}
|
||||
```
|
||||
<span id="struct_Pool_ChangePoolSize"></span>
|
||||
|
||||
#### func (*Pool) ChangePoolSize(size int) error
|
||||
> 改变定时器池大小
|
||||
> - 当传入的大小小于或等于 0 时,将会返回错误,并且不会发生任何改变
|
||||
|
||||
***
|
||||
<span id="struct_Pool_GetTicker"></span>
|
||||
|
||||
#### func (*Pool) GetTicker(size int, options ...Option) *Ticker
|
||||
> 获取一个新的定时器
|
||||
|
||||
***
|
||||
<span id="struct_Pool_Release"></span>
|
||||
|
||||
#### func (*Pool) Release()
|
||||
> 释放定时器池的资源,释放后由其产生的 Ticker 在 Ticker.Release 后将不再回到池中,而是直接释放
|
||||
> - 虽然定时器池已被释放,但是依旧可以产出 Ticker
|
||||
|
||||
***
|
||||
<span id="struct_Scheduler"></span>
|
||||
### Scheduler `STRUCT`
|
||||
|
@ -145,14 +154,23 @@ type Scheduler struct {
|
|||
expr *cronexpr.Expression
|
||||
}
|
||||
```
|
||||
<span id="struct_Scheduler_Name"></span>
|
||||
|
||||
#### func (*Scheduler) Name() string
|
||||
> 获取调度器名称
|
||||
|
||||
***
|
||||
<span id="struct_Scheduler_Next"></span>
|
||||
|
||||
#### func (*Scheduler) Next(prev time.Time) time.Time
|
||||
> 获取下一次执行的时间
|
||||
|
||||
***
|
||||
<span id="struct_Scheduler_Caller"></span>
|
||||
|
||||
#### func (*Scheduler) Caller()
|
||||
> 可由外部发起调用的执行函数
|
||||
|
||||
***
|
||||
<span id="struct_Ticker"></span>
|
||||
### Ticker `STRUCT`
|
||||
|
@ -167,24 +185,42 @@ type Ticker struct {
|
|||
mark string
|
||||
}
|
||||
```
|
||||
<span id="struct_Ticker_Mark"></span>
|
||||
|
||||
#### func (*Ticker) Mark() string
|
||||
> 获取定时器的标记
|
||||
> - 通常用于鉴别定时器来源
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_Release"></span>
|
||||
|
||||
#### func (*Ticker) Release()
|
||||
> 释放定时器,并将定时器重新放回 Pool 池中
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_StopTimer"></span>
|
||||
|
||||
#### func (*Ticker) StopTimer(name string)
|
||||
> 停止特定名称的调度器
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_IsStopped"></span>
|
||||
|
||||
#### func (*Ticker) IsStopped(name string) bool
|
||||
> 特定名称的调度器是否已停止
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_GetSchedulers"></span>
|
||||
|
||||
#### func (*Ticker) GetSchedulers() []string
|
||||
> 获取所有调度器名称
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_Cron"></span>
|
||||
|
||||
#### func (*Ticker) Cron(name string, expression string, handleFunc interface {}, args ...interface {})
|
||||
> 通过 cron 表达式设置一个调度器,当 cron 表达式错误时,将会引发 panic
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
@ -212,12 +248,21 @@ func TestTicker_Cron(t *testing.T) {
|
|||
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_CronByInstantly"></span>
|
||||
|
||||
#### func (*Ticker) CronByInstantly(name string, expression string, handleFunc interface {}, args ...interface {})
|
||||
> 与 Cron 相同,但是会立即执行一次
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_After"></span>
|
||||
|
||||
#### func (*Ticker) After(name string, after time.Duration, handleFunc interface {}, args ...interface {})
|
||||
> 设置一个在特定时间后运行一次的调度器
|
||||
|
||||
***
|
||||
<span id="struct_Ticker_Loop"></span>
|
||||
|
||||
#### func (*Ticker) Loop(name string, after time.Duration, interval time.Duration, times int, handleFunc interface {}, args ...interface {})
|
||||
> 设置一个在特定时间后反复运行的调度器
|
||||
|
||||
***
|
||||
|
|
|
@ -410,6 +410,8 @@ type StateLine[State generic.Basic] struct {
|
|||
trigger [][]func()
|
||||
}
|
||||
```
|
||||
<span id="struct_StateLine_Check"></span>
|
||||
|
||||
#### func (*StateLine) Check(missingAllowed bool, states ...State) bool
|
||||
> 根据状态顺序检查时间线是否合法
|
||||
> - missingAllowed: 是否允许状态缺失,如果为 true,则状态可以不连续,如果为 false,则状态必须连续
|
||||
|
@ -417,76 +419,146 @@ type StateLine[State generic.Basic] struct {
|
|||
> 状态不连续表示时间线中存在状态缺失,例如:
|
||||
> - 状态为 [1, 2, 3, 4, 5] 的时间线,如果 missingAllowed 为 true,则状态为 [1, 3, 5] 也是合法的
|
||||
> - 状态为 [1, 2, 3, 4, 5] 的时间线,如果 missingAllowed 为 false,则状态为 [1, 3, 5] 是不合法的
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetMissingStates"></span>
|
||||
|
||||
#### func (*StateLine) GetMissingStates(states ...State) []State
|
||||
> 获取缺失的状态
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_HasState"></span>
|
||||
|
||||
#### func (*StateLine) HasState(state State) bool
|
||||
> 检查时间线中是否包含指定状态
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_String"></span>
|
||||
|
||||
#### func (*StateLine) String() string
|
||||
> 获取时间线的字符串表示
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_AddState"></span>
|
||||
|
||||
#### func (*StateLine) AddState(state State, t time.Time, onTrigger ...func ()) *StateLine[State]
|
||||
> 添加一个状态到时间线中,状态不能与任一时间点重合,否则将被忽略
|
||||
> - onTrigger: 该状态绑定的触发器,该触发器不会被主动执行,需要主动获取触发器执行
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetTimeByState"></span>
|
||||
|
||||
#### func (*StateLine) GetTimeByState(state State) time.Time
|
||||
> 获取指定状态的时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetNextTimeByState"></span>
|
||||
|
||||
#### func (*StateLine) GetNextTimeByState(state State) time.Time
|
||||
> 获取指定状态的下一个时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetLastState"></span>
|
||||
|
||||
#### func (*StateLine) GetLastState() State
|
||||
> 获取最后一个状态
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetPrevTimeByState"></span>
|
||||
|
||||
#### func (*StateLine) GetPrevTimeByState(state State) time.Time
|
||||
> 获取指定状态的上一个时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetIndexByState"></span>
|
||||
|
||||
#### func (*StateLine) GetIndexByState(state State) int
|
||||
> 获取指定状态的索引
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetStateByTime"></span>
|
||||
|
||||
#### func (*StateLine) GetStateByTime(t time.Time) State
|
||||
> 获取指定时间点的状态
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetTimeByIndex"></span>
|
||||
|
||||
#### func (*StateLine) GetTimeByIndex(index int) time.Time
|
||||
> 获取指定索引的时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_Move"></span>
|
||||
|
||||
#### func (*StateLine) Move(d time.Duration) *StateLine[State]
|
||||
> 时间线整体移动
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetNextStateTimeByIndex"></span>
|
||||
|
||||
#### func (*StateLine) GetNextStateTimeByIndex(index int) time.Time
|
||||
> 获取指定索引的下一个时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetPrevStateTimeByIndex"></span>
|
||||
|
||||
#### func (*StateLine) GetPrevStateTimeByIndex(index int) time.Time
|
||||
> 获取指定索引的上一个时间点
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetStateIndexByTime"></span>
|
||||
|
||||
#### func (*StateLine) GetStateIndexByTime(t time.Time) int
|
||||
> 获取指定时间点的索引
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetStateCount"></span>
|
||||
|
||||
#### func (*StateLine) GetStateCount() int
|
||||
> 获取状态数量
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetStateByIndex"></span>
|
||||
|
||||
#### func (*StateLine) GetStateByIndex(index int) State
|
||||
> 获取指定索引的状态
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetTriggerByTime"></span>
|
||||
|
||||
#### func (*StateLine) GetTriggerByTime(t time.Time) []func ()
|
||||
> 获取指定时间点的触发器
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetTriggerByIndex"></span>
|
||||
|
||||
#### func (*StateLine) GetTriggerByIndex(index int) []func ()
|
||||
> 获取指定索引的触发器
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_GetTriggerByState"></span>
|
||||
|
||||
#### func (*StateLine) GetTriggerByState(state State) []func ()
|
||||
> 获取指定状态的触发器
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_AddTriggerToState"></span>
|
||||
|
||||
#### func (*StateLine) AddTriggerToState(state State, onTrigger ...func ()) *StateLine[State]
|
||||
> 给指定状态添加触发器
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_Range"></span>
|
||||
|
||||
#### func (*StateLine) Range(handler func (index int, state State, t time.Time) bool)
|
||||
> 按照时间顺序遍历时间线
|
||||
|
||||
***
|
||||
<span id="struct_StateLine_RangeReverse"></span>
|
||||
|
||||
#### func (*StateLine) RangeReverse(handler func (index int, state State, t time.Time) bool)
|
||||
> 按照时间逆序遍历时间线
|
||||
|
||||
***
|
||||
<span id="struct_Period"></span>
|
||||
### Period `STRUCT`
|
||||
|
@ -494,61 +566,118 @@ type StateLine[State generic.Basic] struct {
|
|||
```go
|
||||
type Period [2]time.Time
|
||||
```
|
||||
<span id="struct_Period_Start"></span>
|
||||
|
||||
#### func (Period) Start() time.Time
|
||||
> 返回时间段的开始时间
|
||||
|
||||
***
|
||||
<span id="struct_Period_End"></span>
|
||||
|
||||
#### func (Period) End() time.Time
|
||||
> 返回时间段的结束时间
|
||||
|
||||
***
|
||||
<span id="struct_Period_Duration"></span>
|
||||
|
||||
#### func (Period) Duration() time.Duration
|
||||
> 返回时间段的持续时间
|
||||
|
||||
***
|
||||
<span id="struct_Period_Day"></span>
|
||||
|
||||
#### func (Period) Day() int
|
||||
> 返回时间段的持续天数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Hour"></span>
|
||||
|
||||
#### func (Period) Hour() int
|
||||
> 返回时间段的持续小时数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Minute"></span>
|
||||
|
||||
#### func (Period) Minute() int
|
||||
> 返回时间段的持续分钟数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Seconds"></span>
|
||||
|
||||
#### func (Period) Seconds() int
|
||||
> 返回时间段的持续秒数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Milliseconds"></span>
|
||||
|
||||
#### func (Period) Milliseconds() int
|
||||
> 返回时间段的持续毫秒数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Microseconds"></span>
|
||||
|
||||
#### func (Period) Microseconds() int
|
||||
> 返回时间段的持续微秒数
|
||||
|
||||
***
|
||||
<span id="struct_Period_Nanoseconds"></span>
|
||||
|
||||
#### func (Period) Nanoseconds() int
|
||||
> 返回时间段的持续纳秒数
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsZero"></span>
|
||||
|
||||
#### func (Period) IsZero() bool
|
||||
> 判断时间段是否为零值
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsInvalid"></span>
|
||||
|
||||
#### func (Period) IsInvalid() bool
|
||||
> 判断时间段是否无效
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsBefore"></span>
|
||||
|
||||
#### func (Period) IsBefore(t time.Time) bool
|
||||
> 判断时间段是否在指定时间之前
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsAfter"></span>
|
||||
|
||||
#### func (Period) IsAfter(t time.Time) bool
|
||||
> 判断时间段是否在指定时间之后
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsBetween"></span>
|
||||
|
||||
#### func (Period) IsBetween(t time.Time) bool
|
||||
> 判断指定时间是否在时间段之间
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsOngoing"></span>
|
||||
|
||||
#### func (Period) IsOngoing(t time.Time) bool
|
||||
> 判断指定时间是否正在进行时
|
||||
> - 如果时间段的开始时间在指定时间之前或者等于指定时间,且时间段的结束时间在指定时间之后,则返回 true
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsBetweenOrEqual"></span>
|
||||
|
||||
#### func (Period) IsBetweenOrEqual(t time.Time) bool
|
||||
> 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsBetweenOrEqualPeriod"></span>
|
||||
|
||||
#### func (Period) IsBetweenOrEqualPeriod(t Period) bool
|
||||
> 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间
|
||||
|
||||
***
|
||||
<span id="struct_Period_IsOverlap"></span>
|
||||
|
||||
#### func (Period) IsOverlap(t Period) bool
|
||||
> 判断时间段是否与指定时间段重叠
|
||||
|
||||
***
|
||||
|
|
Loading…
Reference in New Issue