Documentation
¶
Overview ¶
Package framework 提供 Golaxy 分布式服务的应用启动、装配与业务开发入口。
它在 git.golaxy.org/core 之上补齐了服务端开发常用的组合能力,包括:
- App 启动入口,以及基于 Cobra/Viper 的统一配置装载
- Service 与 Runtime 的默认 add-in 装配
- Service、Runtime、Entity、Component 之间的强类型桥接
- 生命周期接口、异步调用辅助,以及实体原型/实体构建器
典型使用方式是先创建 App,注册一个或多个服务装配器,再在服务生命周期 回调中创建 runtime、声明实体原型并生成实体实例。
Index ¶
- Variables
- type App
- func (app *App) Cmd() *cobra.Command
- func (app *App) Conf() *viper.Viper
- func (app *App) InitCB(cb generic.Action1[*App]) *App
- func (app *App) Run()
- func (app *App) SetAssembler(name string, assembler any) *App
- func (app *App) StartingCB(cb generic.Action1[*App]) *App
- func (app *App) TerminateCB(cb generic.Action1[*App]) *App
- type ComponentBehavior
- func (c *ComponentBehavior) After(dur time.Duration) async.Future
- func (c *ComponentBehavior) At(at time.Time) async.Future
- func (c *ComponentBehavior) BalanceOnewayRPC(service, comp, method string, args ...any) error
- func (c *ComponentBehavior) BalanceRPC(service, comp, method string, args ...any) async.Future
- func (c *ComponentBehavior) BroadcastOnewayRPC(excludeSelf bool, service, comp, method string, args ...any) error
- func (c *ComponentBehavior) CliOnewayRPC(proc, method string, args ...any) error
- func (c *ComponentBehavior) CliRPC(proc, method string, args ...any) async.Future
- func (c *ComponentBehavior) ContinueOn(future async.Future, ...) async.Future
- func (c *ComponentBehavior) ContinueOnVoid(future async.Future, fun generic.ActionVar2[IRuntime, async.Result, any], ...) async.Future
- func (c *ComponentBehavior) Every(dur time.Duration) async.Stream
- func (c *ComponentBehavior) FromChan(ch <-chan any) async.Stream
- func (c *ComponentBehavior) GlobalBalanceOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
- func (c *ComponentBehavior) GlobalBalanceRPC(excludeSelf bool, comp, method string, args ...any) async.Future
- func (c *ComponentBehavior) GlobalBroadcastOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
- func (c *ComponentBehavior) L() *zap.Logger
- func (c *ComponentBehavior) OnewayRPC(service, comp, method string, args ...any) error
- func (c *ComponentBehavior) Post(fun generic.ActionVar1[IRuntime, any], args ...any) error
- func (c *ComponentBehavior) RPC(service, comp, method string, args ...any) async.Future
- func (c *ComponentBehavior) Runtime() IRuntime
- func (c *ComponentBehavior) S() *zap.SugaredLogger
- func (c *ComponentBehavior) Service() IService
- func (c *ComponentBehavior) Spawn(fun generic.FuncVar1[context.Context, any, async.Result], args ...any) async.Future
- func (c *ComponentBehavior) SpawnVoid(fun generic.ActionVar1[context.Context, any], args ...any) async.Future
- func (c *ComponentBehavior) Submit(fun generic.FuncVar1[IRuntime, any, async.Result], args ...any) async.Future
- func (c *ComponentBehavior) SubmitVoid(fun generic.ActionVar1[IRuntime, any], args ...any) async.Future
- type EntityBehavior
- func (e *EntityBehavior) After(dur time.Duration) async.Future
- func (e *EntityBehavior) At(at time.Time) async.Future
- func (e *EntityBehavior) BalanceOnewayRPC(service, comp, method string, args ...any) error
- func (e *EntityBehavior) BalanceRPC(service, comp, method string, args ...any) async.Future
- func (e *EntityBehavior) BroadcastOnewayRPC(excludeSelf bool, service, comp, method string, args ...any) error
- func (e *EntityBehavior) CliOnewayRPC(proc, method string, args ...any) error
- func (e *EntityBehavior) CliRPC(proc, method string, args ...any) async.Future
- func (e *EntityBehavior) ContinueOn(future async.Future, ...) async.Future
- func (e *EntityBehavior) ContinueOnVoid(future async.Future, fun generic.ActionVar2[IRuntime, async.Result, any], ...) async.Future
- func (e *EntityBehavior) Every(dur time.Duration) async.Stream
- func (e *EntityBehavior) FromChan(ch <-chan any) async.Stream
- func (e *EntityBehavior) GlobalBalanceOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
- func (e *EntityBehavior) GlobalBalanceRPC(excludeSelf bool, comp, method string, args ...any) async.Future
- func (e *EntityBehavior) GlobalBroadcastOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
- func (e *EntityBehavior) L() *zap.Logger
- func (e *EntityBehavior) OnewayRPC(service, comp, method string, args ...any) error
- func (e *EntityBehavior) Post(fun generic.ActionVar1[IRuntime, any], args ...any) error
- func (e *EntityBehavior) RPC(service, comp, method string, args ...any) async.Future
- func (e *EntityBehavior) Runtime() IRuntime
- func (e *EntityBehavior) S() *zap.SugaredLogger
- func (e *EntityBehavior) Service() IService
- func (e *EntityBehavior) Spawn(fun generic.FuncVar1[context.Context, any, async.Result], args ...any) async.Future
- func (e *EntityBehavior) SpawnVoid(fun generic.ActionVar1[context.Context, any], args ...any) async.Future
- func (e *EntityBehavior) Submit(fun generic.FuncVar1[IRuntime, any, async.Result], args ...any) async.Future
- func (e *EntityBehavior) SubmitVoid(fun generic.ActionVar1[IRuntime, any], args ...any) async.Future
- type EntityCreator
- func (c *EntityCreator) AssignMeta(m meta.Meta) *EntityCreator
- func (c *EntityCreator) MergeMeta(dict map[string]any) *EntityCreator
- func (c *EntityCreator) MergeMetaIfAbsent(dict map[string]any) *EntityCreator
- func (c *EntityCreator) New() (ec.ConcurrentEntity, error)
- func (c *EntityCreator) NewAsync() async.Future
- func (c *EntityCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityCreator
- func (c *EntityCreator) SetComponentUniqueID(b bool) *EntityCreator
- func (c *EntityCreator) SetInstance(instance ec.Entity) *EntityCreator
- func (c *EntityCreator) SetInstanceFace(face iface.Face[ec.Entity]) *EntityCreator
- func (c *EntityCreator) SetMeta(dict map[string]any) *EntityCreator
- func (c *EntityCreator) SetPersistId(id uid.Id) *EntityCreator
- func (c *EntityCreator) SetRuntime(rtInst IRuntime) *EntityCreator
- func (c *EntityCreator) SetRuntimeCreator(rtCreator *RuntimeCreator) *EntityCreator
- func (c *EntityCreator) SetScope(scope ec.Scope) *EntityCreator
- type EntityPTCreator
- type IRuntime
- type IRuntimeInstantiator
- type IService
- type IServiceInstantiator
- type InstallRuntimeDistEntityRegistry
- type InstallRuntimeLogger
- type InstallRuntimeRPCStack
- type InstallServiceBroker
- type InstallServiceConfig
- type InstallServiceDistEntityQuerier
- type InstallServiceDistService
- type InstallServiceDistSync
- type InstallServiceLogger
- type InstallServiceRPC
- type InstallServiceRegistry
- type LifecycleRuntimeAddInActivated
- type LifecycleRuntimeAddInActivating
- type LifecycleRuntimeAddInActivationAborted
- type LifecycleRuntimeAddInDeactivated
- type LifecycleRuntimeAddInDeactivating
- type LifecycleRuntimeBirth
- type LifecycleRuntimeBuilt
- type LifecycleRuntimeEntityActivated
- type LifecycleRuntimeEntityActivating
- type LifecycleRuntimeEntityActivationAborted
- type LifecycleRuntimeEntityComponentDeactivated
- type LifecycleRuntimeEntityComponentDeactivating
- type LifecycleRuntimeEntityComponentDeactivationAborted
- type LifecycleRuntimeEntityComponentsActivated
- type LifecycleRuntimeEntityComponentsActivating
- type LifecycleRuntimeEntityComponentsActivationAborted
- type LifecycleRuntimeEntityDeactivated
- type LifecycleRuntimeEntityDeactivating
- type LifecycleRuntimeFrameLoopBegin
- type LifecycleRuntimeFrameLoopEnd
- type LifecycleRuntimeFrameUpdateBegin
- type LifecycleRuntimeFrameUpdateEnd
- type LifecycleRuntimeRunCallBegin
- type LifecycleRuntimeRunCallEnd
- type LifecycleRuntimeRunGCBegin
- type LifecycleRuntimeRunGCEnd
- type LifecycleRuntimeStarted
- type LifecycleRuntimeStarting
- type LifecycleRuntimeTerminated
- type LifecycleRuntimeTerminating
- type LifecycleServiceBirth
- type LifecycleServiceBuilt
- type LifecycleServiceComponentPTDeclared
- type LifecycleServiceEntityDeregistered
- type LifecycleServiceEntityPTDeclared
- type LifecycleServiceEntityRegistered
- type LifecycleServiceHeartbeat
- type LifecycleServiceStarted
- type LifecycleServiceStarting
- type LifecycleServiceTerminated
- type LifecycleServiceTerminating
- type RuntimeAssembler
- type RuntimeBehavior
- func (rt *RuntimeBehavior) AutoInjection() bool
- func (rt *RuntimeBehavior) BuildEntity(prototype string) *core.EntityCreator
- func (rt *RuntimeBehavior) DistEntityRegistry() dent.IDistEntityRegistry
- func (rt *RuntimeBehavior) L() *zap.Logger
- func (rt *RuntimeBehavior) MainEntity() ec.Entity
- func (rt *RuntimeBehavior) RPCStack() rpcstack.IRPCStack
- func (rt *RuntimeBehavior) S() *zap.SugaredLogger
- func (rt *RuntimeBehavior) Service() IService
- type RuntimeCreator
- func (c *RuntimeCreator) New() (IRuntime, error)
- func (c *RuntimeCreator) SetAssembler(assembler any) *RuntimeCreator
- func (c *RuntimeCreator) SetAutoInjection(b bool) *RuntimeCreator
- func (c *RuntimeCreator) SetContinueOnActivatingEntityPanic(b bool) *RuntimeCreator
- func (c *RuntimeCreator) SetEnableFrame(b bool) *RuntimeCreator
- func (c *RuntimeCreator) SetFPS(fps float64) *RuntimeCreator
- func (c *RuntimeCreator) SetMainEntity(entity ec.Entity) *RuntimeCreator
- func (c *RuntimeCreator) SetName(name string) *RuntimeCreator
- func (c *RuntimeCreator) SetPanicHandling(autoRecover bool, reportError chan error) *RuntimeCreator
- func (c *RuntimeCreator) SetPersistId(id uid.Id) *RuntimeCreator
- type ServiceAssembler
- type ServiceBehavior
- func (svc *ServiceBehavior) AppConf() *viper.Viper
- func (svc *ServiceBehavior) Broker() broker.IBroker
- func (svc *ServiceBehavior) BuildEntity(prototype string) *EntityCreator
- func (svc *ServiceBehavior) BuildEntityPT(prototype string) *EntityPTCreator
- func (svc *ServiceBehavior) BuildRuntime() *RuntimeCreator
- func (svc *ServiceBehavior) DistEntityQuerier() dent.IDistEntityQuerier
- func (svc *ServiceBehavior) DistService() dsvc.IDistService
- func (svc *ServiceBehavior) DistSync() dsync.IDistSync
- func (svc *ServiceBehavior) L() *zap.Logger
- func (svc *ServiceBehavior) Memory() *sync.Map
- func (svc *ServiceBehavior) RPC() rpc.IRPC
- func (svc *ServiceBehavior) Registry() discovery.IRegistry
- func (svc *ServiceBehavior) ReplicaNo() int
- func (svc *ServiceBehavior) S() *zap.SugaredLogger
- func (svc *ServiceBehavior) ServiceConf() *viper.Viper
Constants ¶
This section is empty.
Variables ¶
var BuildEntityPT = core.BuildEntityPT
BuildEntityPT 创建绑定服务上下文及 prototype 名称的实体原型构建器。
var ( // ErrAsyncCallerNotAlive 表示异步结果返回时,发起续体的实体或组件已经失活。 ErrAsyncCallerNotAlive = errors.New("async caller is not alive") )
var ( // ErrFramework 是 framework 包错误的根错误,可通过 errors.Is 判断错误类别。 ErrFramework = errors.New("framework") )
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App 负责装载应用配置、启动已注册的服务副本,并等待所有服务停止。 App 的配置和装配方法应在 Run 前由同一 goroutine 调用。
func (*App) Run ¶
func (app *App) Run()
Run 初始化并执行应用命令,随后启动配置指定的服务副本。 Cobra 返回执行错误时 Run 会 panic;同一个 App 不应并发调用 Run。
func (*App) SetAssembler ¶ added in v0.3.68
SetAssembler 注册名为 name 的服务装配器。 assembler 可以是自定义装配器,也可以是实现 IService 的实例或 reflect.Type; 后两者会被转换为按需创建实例的默认装配器。同名注册会替换此前的装配器。
func (*App) StartingCB ¶
StartingCB 设置应用启动回调。 回调在配置与可选 pprof 服务初始化完成后、启动服务副本前执行。
type ComponentBehavior ¶ added in v0.1.56
type ComponentBehavior struct {
ec.ComponentBehavior
// contains filtered or unexported fields
}
ComponentBehavior 扩展 core 组件行为,供自定义组件匿名嵌入。 日志器会按组件实例惰性创建,因此应在组件所属运行时 goroutine 中使用。
func (*ComponentBehavior) After ¶ added in v0.3.68
func (c *ComponentBehavior) After(dur time.Duration) async.Future
After 在组件生命周期内等待 dur 后以当前时间完成 Future。
func (*ComponentBehavior) At ¶ added in v0.3.68
func (c *ComponentBehavior) At(at time.Time) async.Future
At 在组件生命周期内等待到 at 后以当前时间完成 Future。
func (*ComponentBehavior) BalanceOnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) BalanceOnewayRPC(service, comp, method string, args ...any) error
BalanceOnewayRPC 从承载当前实体且服务名匹配的节点中随机选择一个发起单向 RPC。
func (*ComponentBehavior) BalanceRPC ¶ added in v0.1.56
func (c *ComponentBehavior) BalanceRPC(service, comp, method string, args ...any) async.Future
BalanceRPC 从承载当前实体且服务名匹配的节点中随机选择一个发起 RPC。
func (*ComponentBehavior) BroadcastOnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) BroadcastOnewayRPC(excludeSelf bool, service, comp, method string, args ...any) error
BroadcastOnewayRPC 向指定服务中承载当前实体的节点广播单向 RPC;excludeSelf 为 true 时排除源节点。
func (*ComponentBehavior) CliOnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) CliOnewayRPC(proc, method string, args ...any) error
CliOnewayRPC 向当前实体 ID 对应的客户端单播地址发起单向 RPC。
func (*ComponentBehavior) CliRPC ¶ added in v0.1.56
func (c *ComponentBehavior) CliRPC(proc, method string, args ...any) async.Future
CliRPC 向当前实体 ID 对应的客户端单播地址发起 RPC。
func (*ComponentBehavior) ContinueOn ¶ added in v0.3.68
func (c *ComponentBehavior) ContinueOn(future async.Future, fun generic.FuncVar2[IRuntime, async.Result, any, async.Result], args ...any) async.Future
ContinueOn 在 future 完成后回到组件所属 Runtime 执行 fun。
func (*ComponentBehavior) ContinueOnVoid ¶ added in v0.3.68
func (c *ComponentBehavior) ContinueOnVoid(future async.Future, fun generic.ActionVar2[IRuntime, async.Result, any], args ...any) async.Future
ContinueOnVoid 在 future 完成后回到组件所属 Runtime 执行无业务返回值的 fun。
func (*ComponentBehavior) Every ¶ added in v0.3.68
func (c *ComponentBehavior) Every(dur time.Duration) async.Stream
Every 在组件生命周期内按 dur 周期产出当前时间。
func (*ComponentBehavior) FromChan ¶ added in v0.3.68
func (c *ComponentBehavior) FromChan(ch <-chan any) async.Stream
FromChan 将 ch 转换为绑定组件生命周期的 Stream。
func (*ComponentBehavior) GlobalBalanceOnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) GlobalBalanceOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
GlobalBalanceOnewayRPC 从承载当前实体的全部节点中随机选择一个发起单向 RPC;excludeSelf 为 true 时排除本节点。
func (*ComponentBehavior) GlobalBalanceRPC ¶ added in v0.1.56
func (c *ComponentBehavior) GlobalBalanceRPC(excludeSelf bool, comp, method string, args ...any) async.Future
GlobalBalanceRPC 从承载当前实体的全部节点中随机选择一个发起 RPC;excludeSelf 为 true 时排除本节点。
func (*ComponentBehavior) GlobalBroadcastOnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) GlobalBroadcastOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
GlobalBroadcastOnewayRPC 向所有服务中承载当前实体的节点广播单向 RPC;excludeSelf 为 true 时排除源节点。
func (*ComponentBehavior) L ¶ added in v0.3.68
func (c *ComponentBehavior) L() *zap.Logger
L 返回附带当前组件字段的结构化日志器。
func (*ComponentBehavior) OnewayRPC ¶ added in v0.2.38
func (c *ComponentBehavior) OnewayRPC(service, comp, method string, args ...any) error
OnewayRPC 向承载当前实体的首个指定服务节点发起单向 RPC。
func (*ComponentBehavior) Post ¶ added in v0.3.68
func (c *ComponentBehavior) Post(fun generic.ActionVar1[IRuntime, any], args ...any) error
Post 将 fun 投递到组件所属 Runtime,不创建 Future。 fun 执行前组件已经失活时会被忽略。
func (*ComponentBehavior) RPC ¶ added in v0.1.56
func (c *ComponentBehavior) RPC(service, comp, method string, args ...any) async.Future
RPC 向承载当前实体的首个指定服务节点发起 RPC。
func (*ComponentBehavior) Runtime ¶ added in v0.3.68
func (c *ComponentBehavior) Runtime() IRuntime
Runtime 返回组件所属的 framework 运行时。
func (*ComponentBehavior) S ¶ added in v0.3.68
func (c *ComponentBehavior) S() *zap.SugaredLogger
S 返回附带当前组件字段的 SugaredLogger。
func (*ComponentBehavior) Service ¶ added in v0.3.68
func (c *ComponentBehavior) Service() IService
Service 返回承载组件所属运行时的服务。
func (*ComponentBehavior) Spawn ¶ added in v0.3.68
func (c *ComponentBehavior) Spawn(fun generic.FuncVar1[context.Context, any, async.Result], args ...any) async.Future
Spawn 在组件生命周期 Scope 中启动后台任务。 fun 不得直接并发访问 Runtime 局部状态。
func (*ComponentBehavior) SpawnVoid ¶ added in v0.3.68
func (c *ComponentBehavior) SpawnVoid(fun generic.ActionVar1[context.Context, any], args ...any) async.Future
SpawnVoid 在组件生命周期 Scope 中启动无业务返回值的后台任务。
func (*ComponentBehavior) Submit ¶ added in v0.3.68
func (c *ComponentBehavior) Submit(fun generic.FuncVar1[IRuntime, any, async.Result], args ...any) async.Future
Submit 将 fun 提交到组件所属 Runtime,并返回执行结果 Future。 执行时组件若已失活,Future 返回 ErrAsyncCallerNotAlive。
func (*ComponentBehavior) SubmitVoid ¶ added in v0.3.68
func (c *ComponentBehavior) SubmitVoid(fun generic.ActionVar1[IRuntime, any], args ...any) async.Future
SubmitVoid 将无业务返回值的 fun 提交到组件所属 Runtime。 执行时组件若已失活,Future 返回 ErrAsyncCallerNotAlive。
type EntityBehavior ¶ added in v0.1.76
type EntityBehavior struct {
ec.EntityBehavior
// contains filtered or unexported fields
}
EntityBehavior 扩展 core 实体行为,供自定义实体匿名嵌入。 日志器会按实体实例惰性创建,因此应在实体所属运行时 goroutine 中使用。
func (*EntityBehavior) After ¶ added in v0.3.68
func (e *EntityBehavior) After(dur time.Duration) async.Future
After 在实体生命周期内等待 dur 后以当前时间完成 Future。
func (*EntityBehavior) At ¶ added in v0.3.68
func (e *EntityBehavior) At(at time.Time) async.Future
At 在实体生命周期内等待到 at 后以当前时间完成 Future。
func (*EntityBehavior) BalanceOnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) BalanceOnewayRPC(service, comp, method string, args ...any) error
BalanceOnewayRPC 从承载当前实体且服务名匹配的节点中随机选择一个发起单向 RPC。
func (*EntityBehavior) BalanceRPC ¶ added in v0.1.76
func (e *EntityBehavior) BalanceRPC(service, comp, method string, args ...any) async.Future
BalanceRPC 从承载当前实体且服务名匹配的节点中随机选择一个发起 RPC。
func (*EntityBehavior) BroadcastOnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) BroadcastOnewayRPC(excludeSelf bool, service, comp, method string, args ...any) error
BroadcastOnewayRPC 向指定服务中承载当前实体的节点广播单向 RPC;excludeSelf 为 true 时排除源节点。
func (*EntityBehavior) CliOnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) CliOnewayRPC(proc, method string, args ...any) error
CliOnewayRPC 向当前实体 ID 对应的客户端单播地址发起单向 RPC。
func (*EntityBehavior) CliRPC ¶ added in v0.1.76
func (e *EntityBehavior) CliRPC(proc, method string, args ...any) async.Future
CliRPC 向当前实体 ID 对应的客户端单播地址发起 RPC。
func (*EntityBehavior) ContinueOn ¶ added in v0.3.68
func (e *EntityBehavior) ContinueOn(future async.Future, fun generic.FuncVar2[IRuntime, async.Result, any, async.Result], args ...any) async.Future
ContinueOn 在 future 完成后回到实体所属 Runtime 执行 fun。
func (*EntityBehavior) ContinueOnVoid ¶ added in v0.3.68
func (e *EntityBehavior) ContinueOnVoid(future async.Future, fun generic.ActionVar2[IRuntime, async.Result, any], args ...any) async.Future
ContinueOnVoid 在 future 完成后回到实体所属 Runtime 执行无业务返回值的 fun。
func (*EntityBehavior) Every ¶ added in v0.3.68
func (e *EntityBehavior) Every(dur time.Duration) async.Stream
Every 在实体生命周期内按 dur 周期产出当前时间。
func (*EntityBehavior) FromChan ¶ added in v0.3.68
func (e *EntityBehavior) FromChan(ch <-chan any) async.Stream
FromChan 将 ch 转换为绑定实体生命周期的 Stream。
func (*EntityBehavior) GlobalBalanceOnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) GlobalBalanceOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
GlobalBalanceOnewayRPC 从承载当前实体的全部节点中随机选择一个发起单向 RPC;excludeSelf 为 true 时排除本节点。
func (*EntityBehavior) GlobalBalanceRPC ¶ added in v0.1.76
func (e *EntityBehavior) GlobalBalanceRPC(excludeSelf bool, comp, method string, args ...any) async.Future
GlobalBalanceRPC 从承载当前实体的全部节点中随机选择一个发起 RPC;excludeSelf 为 true 时排除本节点。
func (*EntityBehavior) GlobalBroadcastOnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) GlobalBroadcastOnewayRPC(excludeSelf bool, comp, method string, args ...any) error
GlobalBroadcastOnewayRPC 向所有服务中承载当前实体的节点广播单向 RPC;excludeSelf 为 true 时排除源节点。
func (*EntityBehavior) L ¶ added in v0.3.68
func (e *EntityBehavior) L() *zap.Logger
L 返回附带当前实体字段的结构化日志器。
func (*EntityBehavior) OnewayRPC ¶ added in v0.2.38
func (e *EntityBehavior) OnewayRPC(service, comp, method string, args ...any) error
OnewayRPC 向承载当前实体的首个指定服务节点发起单向 RPC。
func (*EntityBehavior) Post ¶ added in v0.3.68
func (e *EntityBehavior) Post(fun generic.ActionVar1[IRuntime, any], args ...any) error
Post 将 fun 投递到实体所属 Runtime,不创建 Future。 fun 执行前实体已经失活时会被忽略。
func (*EntityBehavior) RPC ¶ added in v0.1.76
func (e *EntityBehavior) RPC(service, comp, method string, args ...any) async.Future
RPC 向承载当前实体的首个指定服务节点发起 RPC。
func (*EntityBehavior) Runtime ¶ added in v0.3.68
func (e *EntityBehavior) Runtime() IRuntime
Runtime 返回实体所属的 framework 运行时。
func (*EntityBehavior) S ¶ added in v0.3.68
func (e *EntityBehavior) S() *zap.SugaredLogger
S 返回附带当前实体字段的 SugaredLogger。
func (*EntityBehavior) Service ¶ added in v0.3.68
func (e *EntityBehavior) Service() IService
Service 返回承载实体所属运行时的服务。
func (*EntityBehavior) Spawn ¶ added in v0.3.68
func (e *EntityBehavior) Spawn(fun generic.FuncVar1[context.Context, any, async.Result], args ...any) async.Future
Spawn 在实体生命周期 Scope 中启动后台任务。 fun 不得直接并发访问 Runtime 局部状态。
func (*EntityBehavior) SpawnVoid ¶ added in v0.3.68
func (e *EntityBehavior) SpawnVoid(fun generic.ActionVar1[context.Context, any], args ...any) async.Future
SpawnVoid 在实体生命周期 Scope 中启动无业务返回值的后台任务。
func (*EntityBehavior) Submit ¶ added in v0.3.68
func (e *EntityBehavior) Submit(fun generic.FuncVar1[IRuntime, any, async.Result], args ...any) async.Future
Submit 将 fun 提交到实体所属 Runtime,并返回执行结果 Future。 执行时实体若已失活,Future 返回 ErrAsyncCallerNotAlive。
func (*EntityBehavior) SubmitVoid ¶ added in v0.3.68
func (e *EntityBehavior) SubmitVoid(fun generic.ActionVar1[IRuntime, any], args ...any) async.Future
SubmitVoid 将无业务返回值的 fun 提交到实体所属 Runtime。 执行时实体若已失活,Future 返回 ErrAsyncCallerNotAlive。
type EntityCreator ¶ added in v0.3.68
type EntityCreator struct {
// contains filtered or unexported fields
}
EntityCreator 保存一次实体构建所需的运行时目标、元数据与 core 实体选项。 构建器可按值复制,但不应由多个 goroutine 并发修改。
func BuildEntity ¶ added in v0.3.68
func BuildEntity(svcInst IService, prototype string) *EntityCreator
BuildEntity 创建绑定 svcInst 及 prototype 名称的实体构建器。
func (*EntityCreator) AssignMeta ¶ added in v0.3.68
func (c *EntityCreator) AssignMeta(m meta.Meta) *EntityCreator
AssignMeta 直接绑定实体元数据;m 不会在此时复制,nil 会替换为空 Meta。
func (*EntityCreator) MergeMeta ¶ added in v0.3.68
func (c *EntityCreator) MergeMeta(dict map[string]any) *EntityCreator
MergeMeta 合并实体元数据,同名键会被覆盖。
func (*EntityCreator) MergeMetaIfAbsent ¶ added in v0.3.68
func (c *EntityCreator) MergeMetaIfAbsent(dict map[string]any) *EntityCreator
MergeMetaIfAbsent 合并实体元数据,并保留已有的同名键。
func (*EntityCreator) New ¶ added in v0.3.68
func (c *EntityCreator) New() (ec.ConcurrentEntity, error)
New 构造实体并将其加入指定运行时。 未指定运行时时会创建自动运行的新运行时,并将实体设为其主实体。
func (*EntityCreator) NewAsync ¶ added in v0.3.68
func (c *EntityCreator) NewAsync() async.Future
NewAsync 构造实体并返回其加入运行时的 Future。 使用既有运行时时加入操作由该运行时调度;新建运行时时装配过程仍在调用方同步完成。
func (*EntityCreator) SetComponentAwakeOnFirstTouch ¶ added in v0.3.68
func (c *EntityCreator) SetComponentAwakeOnFirstTouch(b bool) *EntityCreator
SetComponentAwakeOnFirstTouch 设置是否在组件首次访问时检查并调用 Awake。
func (*EntityCreator) SetComponentUniqueID ¶ added in v0.3.68
func (c *EntityCreator) SetComponentUniqueID(b bool) *EntityCreator
SetComponentUniqueID 设置是否为组件分配唯一 ID。
func (*EntityCreator) SetInstance ¶ added in v0.3.68
func (c *EntityCreator) SetInstance(instance ec.Entity) *EntityCreator
SetInstance 设置自定义实体实例。
func (*EntityCreator) SetInstanceFace ¶ added in v0.3.68
func (c *EntityCreator) SetInstanceFace(face iface.Face[ec.Entity]) *EntityCreator
SetInstanceFace 设置实体实例面,用于提供自定义实体行为与反射信息。
func (*EntityCreator) SetMeta ¶ added in v0.3.68
func (c *EntityCreator) SetMeta(dict map[string]any) *EntityCreator
SetMeta 用 dict 替换实体元数据;dict 的内容会复制到新的 Meta 中。
func (*EntityCreator) SetPersistId ¶ added in v0.3.68
func (c *EntityCreator) SetPersistId(id uid.Id) *EntityCreator
SetPersistId 设置实体持久化 ID。
func (*EntityCreator) SetRuntime ¶ added in v0.3.68
func (c *EntityCreator) SetRuntime(rtInst IRuntime) *EntityCreator
SetRuntime 设置实体要加入的既有运行时。 rtInst 为 nil 时清除该设置;非 nil 运行时必须属于构建器绑定的服务。
func (*EntityCreator) SetRuntimeCreator ¶ added in v0.3.68
func (c *EntityCreator) SetRuntimeCreator(rtCreator *RuntimeCreator) *EntityCreator
SetRuntimeCreator 设置没有指定既有运行时时使用的运行时构建器。 nil 表示使用服务默认构建器;新实体会成为新运行时的主实体。
func (*EntityCreator) SetScope ¶ added in v0.3.68
func (c *EntityCreator) SetScope(scope ec.Scope) *EntityCreator
SetScope 设置实体的可访问作用域。
type EntityPTCreator ¶ added in v0.1.77
type EntityPTCreator = core.EntityPTCreator
EntityPTCreator 是 core 实体原型构建器的别名。
type IRuntime ¶ added in v0.3.24
type IRuntime interface {
runtime.Context
// DistEntityRegistry 返回分布式实体注册 add-in;未安装时会 panic。
DistEntityRegistry() dent.IDistEntityRegistry
// RPCStack 返回 RPC 调用栈 add-in;未安装时会 panic。
RPCStack() rpcstack.IRPCStack
// Service 返回承载当前运行时的服务实例。
Service() IService
// MainEntity 返回与运行时生命周期绑定的主实体;主实体停用后运行时会终止。
MainEntity() ec.Entity
// AutoInjection 报告实体或组件激活时是否自动注入组件依赖。
AutoInjection() bool
// BuildEntity 创建绑定当前运行时及 prototype 名称的 core 实体构建器。
BuildEntity(prototype string) *core.EntityCreator
// L 返回当前运行时的结构化日志器。
L() *zap.Logger
// S 返回当前运行时的 SugaredLogger。
S() *zap.SugaredLogger
}
IRuntime 扩展 core runtime.Context,并聚合 framework 的运行时级 add-in 与构建入口。 除明确标注可并发的 API 外,应在所属运行时 goroutine 中访问运行时状态。
func GetRuntime ¶ added in v0.3.24
func GetRuntime(provider runtime.CurrentContextProvider) IRuntime
GetRuntime 返回 provider 所属的 framework 运行时实例。
type IRuntimeInstantiator ¶ added in v0.3.68
type IRuntimeInstantiator interface {
Instantiate() IRuntime
}
IRuntimeInstantiator 为 RuntimeAssembler 提供自定义 IRuntime 实例。 每次构建运行时都会调用一次 Instantiate,且返回值必须是新的非 nil 实例。
type IService ¶ added in v0.3.24
type IService interface {
service.Context
// AppConf 返回合并后的应用配置。
AppConf() *viper.Viper
// ServiceConf 返回以服务名为键的配置子树;不存在时可能返回 nil。
ServiceConf() *viper.Viper
// Registry 返回服务发现 add-in;未安装时会 panic。
Registry() discovery.IRegistry
// Broker 返回消息代理 add-in;未安装时会 panic。
Broker() broker.IBroker
// DistSync 返回分布式同步 add-in;未安装时会 panic。
DistSync() dsync.IDistSync
// DistService 返回分布式服务 add-in;未安装时会 panic。
DistService() dsvc.IDistService
// DistEntityQuerier 返回分布式实体查询 add-in;未安装时会 panic。
DistEntityQuerier() dent.IDistEntityQuerier
// RPC 返回 RPC add-in;未安装时会 panic。
RPC() rpc.IRPC
// ReplicaNo 返回当前服务在本次应用启动中的副本序号,从 0 开始。
ReplicaNo() int
// Memory 返回服务私有的并发键值存储。
Memory() *sync.Map
// BuildRuntime 创建绑定当前服务的运行时构建器。
BuildRuntime() *RuntimeCreator
// BuildEntityPT 创建绑定当前服务及 prototype 名称的实体原型构建器。
BuildEntityPT(prototype string) *EntityPTCreator
// BuildEntity 创建绑定当前服务及 prototype 名称的实体构建器。
BuildEntity(prototype string) *EntityCreator
// L 返回当前服务的结构化日志器。
L() *zap.Logger
// S 返回当前服务的 SugaredLogger。
S() *zap.SugaredLogger
}
IService 扩展 core service.Context,并聚合 framework 的服务级 add-in 与构建入口。 服务上下文可被多个 goroutine 访问;具体 add-in 的并发约束由各自接口说明。
func GetService ¶ added in v0.3.24
func GetService(provider runtime.ConcurrentContextProvider) IService
GetService 返回 provider 所属的 framework 服务实例。
type IServiceInstantiator ¶ added in v0.3.68
type IServiceInstantiator interface {
Instantiate() IService
}
IServiceInstantiator 为 ServiceAssembler 提供自定义 IService 实例。 每个服务副本都会调用一次 Instantiate,且返回值必须是新的非 nil 实例。
type InstallRuntimeDistEntityRegistry ¶ added in v0.1.87
type InstallRuntimeDistEntityRegistry interface {
InstallDistEntityRegistry(rt IRuntime)
}
InstallRuntimeDistEntityRegistry 为运行时提供自定义分布式实体注册 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallRuntimeLogger ¶
type InstallRuntimeLogger interface {
InstallLogger(rt IRuntime)
}
InstallRuntimeLogger 为运行时提供自定义日志 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallRuntimeRPCStack ¶ added in v0.1.69
type InstallRuntimeRPCStack interface {
InstallRPCStack(rt IRuntime)
}
InstallRuntimeRPCStack 为运行时提供自定义 RPC 调用栈 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceBroker ¶
type InstallServiceBroker interface {
InstallBroker(svc IService)
}
InstallServiceBroker 为服务提供自定义消息代理 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceConfig ¶
type InstallServiceConfig interface {
InstallConfig(svc IService)
}
InstallServiceConfig 为服务提供自定义配置 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceDistEntityQuerier ¶
type InstallServiceDistEntityQuerier interface {
InstallDistEntityQuerier(svc IService)
}
InstallServiceDistEntityQuerier 为服务提供自定义分布式实体查询 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceDistService ¶
type InstallServiceDistService interface {
InstallDistService(svc IService)
}
InstallServiceDistService 为服务提供自定义分布式服务 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceDistSync ¶
type InstallServiceDistSync interface {
InstallDistSync(svc IService)
}
InstallServiceDistSync 为服务提供自定义分布式同步 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceLogger ¶
type InstallServiceLogger interface {
InstallLogger(svc IService)
}
InstallServiceLogger 为服务提供自定义日志 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceRPC ¶
type InstallServiceRPC interface {
InstallRPC(svc IService)
}
InstallServiceRPC 为服务提供自定义 RPC add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type InstallServiceRegistry ¶
type InstallServiceRegistry interface {
InstallRegistry(svc IService)
}
InstallServiceRegistry 为服务提供自定义服务发现 add-in 安装钩子。 仅当 Birth 阶段尚未安装同名 add-in 时调用;实现必须在返回前完成安装。
type LifecycleRuntimeAddInActivated ¶ added in v0.2.85
type LifecycleRuntimeAddInActivated interface {
OnAddInActivated(rt IRuntime, addIn extension.AddInStatus)
}
LifecycleRuntimeAddInActivated 在 add-in 完成 Init 并进入运行状态后接收回调。
type LifecycleRuntimeAddInActivating ¶ added in v0.2.85
type LifecycleRuntimeAddInActivating interface {
OnAddInActivating(rt IRuntime, addIn extension.AddInStatus)
}
LifecycleRuntimeAddInActivating 在 add-in 调用 Init 前接收回调。 回调中卸载该 add-in 会中止激活流程。
type LifecycleRuntimeAddInActivationAborted ¶ added in v0.3.68
type LifecycleRuntimeAddInActivationAborted interface {
OnAddInActivationAborted(rt IRuntime, addIn extension.AddInStatus)
}
LifecycleRuntimeAddInActivationAborted 在 add-in 激活流程被中止时接收回调。
type LifecycleRuntimeAddInDeactivated ¶ added in v0.2.85
type LifecycleRuntimeAddInDeactivated interface {
OnAddInDeactivated(rt IRuntime, addIn extension.AddInStatus)
}
LifecycleRuntimeAddInDeactivated 在 add-in 完成 Shut 后接收回调。
type LifecycleRuntimeAddInDeactivating ¶ added in v0.2.85
type LifecycleRuntimeAddInDeactivating interface {
OnAddInDeactivating(rt IRuntime, addIn extension.AddInStatus)
}
LifecycleRuntimeAddInDeactivating 在 add-in 调用 Shut 前接收回调。
type LifecycleRuntimeBirth ¶
type LifecycleRuntimeBirth interface {
OnBirth(rt IRuntime)
}
LifecycleRuntimeBirth 在运行时上下文创建后、framework add-in 装配前接收回调。
type LifecycleRuntimeBuilt ¶ added in v0.1.45
type LifecycleRuntimeBuilt interface {
OnBuilt(rt IRuntime)
}
LifecycleRuntimeBuilt 在运行时完成 framework add-in 装配后接收回调。 此时运行时尚未进入 Starting,仍可补充初始状态。
type LifecycleRuntimeEntityActivated ¶ added in v0.3.68
LifecycleRuntimeEntityActivated 在实体及其初始组件激活完成后接收回调。
type LifecycleRuntimeEntityActivating ¶ added in v0.3.68
type LifecycleRuntimeEntityActivating interface {
OnEntityActivating(rt IRuntime, entity ec.Entity)
}
LifecycleRuntimeEntityActivating 在实体开始激活时接收回调。
type LifecycleRuntimeEntityActivationAborted ¶ added in v0.3.68
type LifecycleRuntimeEntityActivationAborted interface {
OnEntityActivationAborted(rt IRuntime, entity ec.Entity)
}
LifecycleRuntimeEntityActivationAborted 在实体激活流程被中止时接收回调。
type LifecycleRuntimeEntityComponentDeactivated ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentDeactivated interface {
OnEntityComponentDeactivated(rt IRuntime, entity ec.Entity, component ec.Component)
}
LifecycleRuntimeEntityComponentDeactivated 在组件停用完成、即将从实体删除时接收回调。
type LifecycleRuntimeEntityComponentDeactivating ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentDeactivating interface {
OnEntityComponentDeactivating(rt IRuntime, entity ec.Entity, component ec.Component)
}
LifecycleRuntimeEntityComponentDeactivating 在即将删除的组件开始停用时接收回调。
type LifecycleRuntimeEntityComponentDeactivationAborted ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentDeactivationAborted interface {
OnEntityComponentDeactivationAborted(rt IRuntime, entity ec.Entity, component ec.Component)
}
LifecycleRuntimeEntityComponentDeactivationAborted 在组件停用回调流程被中止时接收回调。 该事件不会取消组件删除。
type LifecycleRuntimeEntityComponentsActivated ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentsActivated interface {
OnEntityComponentsActivated(rt IRuntime, entity ec.Entity, components []ec.Component)
}
LifecycleRuntimeEntityComponentsActivated 在一批新增组件激活完成后接收回调。
type LifecycleRuntimeEntityComponentsActivating ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentsActivating interface {
OnEntityComponentsActivating(rt IRuntime, entity ec.Entity, components []ec.Component)
}
LifecycleRuntimeEntityComponentsActivating 在一批新增组件开始激活时接收回调。
type LifecycleRuntimeEntityComponentsActivationAborted ¶ added in v0.3.68
type LifecycleRuntimeEntityComponentsActivationAborted interface {
OnEntityComponentsActivationAborted(rt IRuntime, entity ec.Entity, components []ec.Component)
}
LifecycleRuntimeEntityComponentsActivationAborted 在新增组件的激活流程被中止时接收回调。
type LifecycleRuntimeEntityDeactivated ¶ added in v0.3.68
type LifecycleRuntimeEntityDeactivated interface {
OnEntityDeactivated(rt IRuntime, entity ec.Entity)
}
LifecycleRuntimeEntityDeactivated 在实体停用完成时接收回调。
type LifecycleRuntimeEntityDeactivating ¶ added in v0.3.68
type LifecycleRuntimeEntityDeactivating interface {
OnEntityDeactivating(rt IRuntime, entity ec.Entity)
}
LifecycleRuntimeEntityDeactivating 在实体开始停用时接收回调。
type LifecycleRuntimeFrameLoopBegin ¶
type LifecycleRuntimeFrameLoopBegin interface {
OnFrameLoopBegin(rt IRuntime)
}
LifecycleRuntimeFrameLoopBegin 在一次完整帧循环开始时接收回调。
type LifecycleRuntimeFrameLoopEnd ¶
type LifecycleRuntimeFrameLoopEnd interface {
OnFrameLoopEnd(rt IRuntime)
}
LifecycleRuntimeFrameLoopEnd 在一次完整帧循环结束时接收回调。
type LifecycleRuntimeFrameUpdateBegin ¶
type LifecycleRuntimeFrameUpdateBegin interface {
OnFrameUpdateBegin(rt IRuntime)
}
LifecycleRuntimeFrameUpdateBegin 在一次帧更新开始时接收回调。
type LifecycleRuntimeFrameUpdateEnd ¶
type LifecycleRuntimeFrameUpdateEnd interface {
OnFrameUpdateEnd(rt IRuntime)
}
LifecycleRuntimeFrameUpdateEnd 在一次帧更新结束时接收回调。
type LifecycleRuntimeRunCallBegin ¶
type LifecycleRuntimeRunCallBegin interface {
OnRunCallBegin(rt IRuntime)
}
LifecycleRuntimeRunCallBegin 在运行时开始执行一个普通异步调用任务时接收回调。
type LifecycleRuntimeRunCallEnd ¶
type LifecycleRuntimeRunCallEnd interface {
OnRunCallEnd(rt IRuntime)
}
LifecycleRuntimeRunCallEnd 在运行时执行完一个普通异步调用任务时接收回调。
type LifecycleRuntimeRunGCBegin ¶
type LifecycleRuntimeRunGCBegin interface {
OnRunGCBegin(rt IRuntime)
}
LifecycleRuntimeRunGCBegin 在运行时开始执行一次 GC 时接收回调。
type LifecycleRuntimeRunGCEnd ¶
type LifecycleRuntimeRunGCEnd interface {
OnRunGCEnd(rt IRuntime)
}
LifecycleRuntimeRunGCEnd 在运行时执行完一次 GC 时接收回调。
type LifecycleRuntimeStarted ¶
type LifecycleRuntimeStarted interface {
OnStarted(rt IRuntime)
}
LifecycleRuntimeStarted 在运行时工作循环及实体事件监听就绪后接收回调。
type LifecycleRuntimeStarting ¶
type LifecycleRuntimeStarting interface {
OnStarting(rt IRuntime)
}
LifecycleRuntimeStarting 在运行时工作循环启动时接收回调。 预装 add-in 已在回调前激活。
type LifecycleRuntimeTerminated ¶
type LifecycleRuntimeTerminated interface {
OnTerminated(rt IRuntime)
}
LifecycleRuntimeTerminated 在运行时等待组清空且 add-in 停用后接收回调。
type LifecycleRuntimeTerminating ¶
type LifecycleRuntimeTerminating interface {
OnTerminating(rt IRuntime)
}
LifecycleRuntimeTerminating 在运行时开始停止、等待子任务退出前接收回调。
type LifecycleServiceBirth ¶
type LifecycleServiceBirth interface {
OnBirth(svc IService)
}
LifecycleServiceBirth 在服务上下文及基础配置创建后、framework add-in 装配前接收回调。
type LifecycleServiceBuilt ¶ added in v0.1.45
type LifecycleServiceBuilt interface {
OnBuilt(svc IService)
}
LifecycleServiceBuilt 在 framework add-in 装配完成后接收回调。 这是服务进入 Starting 并冻结 add-in 管理器前补充服务 add-in 的最后阶段。
type LifecycleServiceComponentPTDeclared ¶ added in v0.3.68
type LifecycleServiceComponentPTDeclared interface {
OnComponentPTDeclared(svc IService, componentPT ec.ComponentPT)
}
LifecycleServiceComponentPTDeclared 在服务组件库声明组件原型后接收回调。
type LifecycleServiceEntityDeregistered ¶ added in v0.3.68
type LifecycleServiceEntityDeregistered interface {
OnEntityDeregistered(svc IService, entity ec.ConcurrentEntity)
}
LifecycleServiceEntityDeregistered 在全局实体从服务实体库注销后接收回调。
type LifecycleServiceEntityPTDeclared ¶ added in v0.2.85
type LifecycleServiceEntityPTDeclared interface {
OnEntityPTDeclared(svc IService, entityPT ec.EntityPT)
}
LifecycleServiceEntityPTDeclared 在服务实体库声明实体原型后接收回调。
type LifecycleServiceEntityRegistered ¶ added in v0.3.68
type LifecycleServiceEntityRegistered interface {
OnEntityRegistered(svc IService, entity ec.ConcurrentEntity)
}
LifecycleServiceEntityRegistered 在全局实体注册到服务实体库后接收回调。
type LifecycleServiceHeartbeat ¶ added in v0.3.68
type LifecycleServiceHeartbeat interface {
OnHeartbeat(svc IService)
}
LifecycleServiceHeartbeat 在服务运行期间接收每秒一次的心跳回调。
type LifecycleServiceStarted ¶
type LifecycleServiceStarted interface {
OnStarted(svc IService)
}
LifecycleServiceStarted 在服务完成启动并加入分布式网络后接收回调。
type LifecycleServiceStarting ¶
type LifecycleServiceStarting interface {
OnStarting(svc IService)
}
LifecycleServiceStarting 在服务开始运行时接收回调。 服务 add-in 已在回调前冻结并激活,之后不能再安装或卸载。
type LifecycleServiceTerminated ¶
type LifecycleServiceTerminated interface {
OnTerminated(svc IService)
}
LifecycleServiceTerminated 在服务等待组清空且 add-in 停用后接收回调。
type LifecycleServiceTerminating ¶
type LifecycleServiceTerminating interface {
OnTerminating(svc IService)
}
LifecycleServiceTerminating 在服务开始停止、等待子任务退出前接收回调。
type RuntimeAssembler ¶ added in v0.3.68
type RuntimeAssembler struct {
// contains filtered or unexported fields
}
RuntimeAssembler 将 IRuntime 实例接入 framework 的 add-in、生命周期及实体事件。 自定义运行时装配类型通常匿名嵌入它并实现所需的生命周期或安装钩子接口。
type RuntimeBehavior ¶
type RuntimeBehavior struct {
runtime.ContextBehavior
// contains filtered or unexported fields
}
RuntimeBehavior 提供 IRuntime 的默认实现,供自定义运行时匿名嵌入。
func (*RuntimeBehavior) AutoInjection ¶ added in v0.3.68
func (rt *RuntimeBehavior) AutoInjection() bool
AutoInjection 报告实体或组件激活时是否自动注入组件依赖。
func (*RuntimeBehavior) BuildEntity ¶ added in v0.3.53
func (rt *RuntimeBehavior) BuildEntity(prototype string) *core.EntityCreator
BuildEntity 创建绑定当前运行时及 prototype 名称的 core 实体构建器。
func (*RuntimeBehavior) DistEntityRegistry ¶ added in v0.3.68
func (rt *RuntimeBehavior) DistEntityRegistry() dent.IDistEntityRegistry
DistEntityRegistry 返回分布式实体注册 add-in;未安装时会 panic。
func (*RuntimeBehavior) L ¶ added in v0.3.68
func (rt *RuntimeBehavior) L() *zap.Logger
L 返回当前运行时的结构化日志器。
func (*RuntimeBehavior) MainEntity ¶ added in v0.3.68
func (rt *RuntimeBehavior) MainEntity() ec.Entity
MainEntity 返回与运行时生命周期绑定的主实体;主实体停用后运行时会终止。
func (*RuntimeBehavior) RPCStack ¶ added in v0.3.68
func (rt *RuntimeBehavior) RPCStack() rpcstack.IRPCStack
RPCStack 返回 RPC 调用栈 add-in;未安装时会 panic。
func (*RuntimeBehavior) S ¶ added in v0.3.68
func (rt *RuntimeBehavior) S() *zap.SugaredLogger
S 返回当前运行时的 SugaredLogger。
func (*RuntimeBehavior) Service ¶ added in v0.3.68
func (rt *RuntimeBehavior) Service() IService
Service 返回承载当前运行时的服务实例。
type RuntimeCreator ¶
type RuntimeCreator struct {
// contains filtered or unexported fields
}
RuntimeCreator 保存一次运行时构建所需的装配器与选项。 构建器可按值复制,但不应由多个 goroutine 并发修改。
func BuildRuntime ¶ added in v0.3.12
func BuildRuntime(svcInst IService) *RuntimeCreator
BuildRuntime 创建绑定 svcInst 的运行时构建器,并继承服务的 panic 处理配置。
func (*RuntimeCreator) New ¶ added in v0.3.12
func (c *RuntimeCreator) New() (IRuntime, error)
New 装配并自动启动运行时。 返回时运行时 goroutine 可能尚未完成 Starting;装配主实体失败时返回错误。
func (*RuntimeCreator) SetAssembler ¶ added in v0.3.68
func (c *RuntimeCreator) SetAssembler(assembler any) *RuntimeCreator
SetAssembler 设置运行时装配器。 assembler 可以是自定义装配器,也可以是实现 IRuntime 的实例或 reflect.Type; 后两者会被转换为按需创建实例的默认装配器。
func (*RuntimeCreator) SetAutoInjection ¶ added in v0.3.24
func (c *RuntimeCreator) SetAutoInjection(b bool) *RuntimeCreator
SetAutoInjection 设置实体或组件激活时是否自动注入组件依赖。
func (*RuntimeCreator) SetContinueOnActivatingEntityPanic ¶ added in v0.3.68
func (c *RuntimeCreator) SetContinueOnActivatingEntityPanic(b bool) *RuntimeCreator
SetContinueOnActivatingEntityPanic 设置实体激活发生 panic 后是否继续运行。 设置为 false 时,激活失败的实体会被移除。
func (*RuntimeCreator) SetEnableFrame ¶ added in v0.3.68
func (c *RuntimeCreator) SetEnableFrame(b bool) *RuntimeCreator
SetEnableFrame 设置是否启用实时帧循环。
func (*RuntimeCreator) SetFPS ¶ added in v0.3.12
func (c *RuntimeCreator) SetFPS(fps float64) *RuntimeCreator
SetFPS 设置启用帧循环时的目标帧率。
func (*RuntimeCreator) SetMainEntity ¶ added in v0.3.68
func (c *RuntimeCreator) SetMainEntity(entity ec.Entity) *RuntimeCreator
SetMainEntity 设置主实体;主实体停用后运行时会自动终止。
func (*RuntimeCreator) SetName ¶ added in v0.3.12
func (c *RuntimeCreator) SetName(name string) *RuntimeCreator
SetName 设置运行时名称。
func (*RuntimeCreator) SetPanicHandling ¶ added in v0.3.12
func (c *RuntimeCreator) SetPanicHandling(autoRecover bool, reportError chan error) *RuntimeCreator
SetPanicHandling 设置运行时是否自动恢复 panic 以及错误报告通道。 autoRecover 为 true 时,恢复出的错误会尝试写入 reportError。
func (*RuntimeCreator) SetPersistId ¶ added in v0.3.12
func (c *RuntimeCreator) SetPersistId(id uid.Id) *RuntimeCreator
SetPersistId 设置运行时持久化 ID。
type ServiceAssembler ¶ added in v0.3.68
type ServiceAssembler struct {
// contains filtered or unexported fields
}
ServiceAssembler 将 IService 实例接入应用配置、默认 add-in 及生命周期事件。 自定义服务装配类型通常匿名嵌入它并实现所需的生命周期或安装钩子接口。
type ServiceBehavior ¶
type ServiceBehavior struct {
service.ContextBehavior
// contains filtered or unexported fields
}
ServiceBehavior 提供 IService 的默认实现,供自定义服务匿名嵌入。
func (*ServiceBehavior) AppConf ¶ added in v0.3.68
func (svc *ServiceBehavior) AppConf() *viper.Viper
AppConf 返回合并后的应用配置。 服务启动前直接读取装配配置,启动后通过 conf add-in 读取。
func (*ServiceBehavior) Broker ¶ added in v0.3.68
func (svc *ServiceBehavior) Broker() broker.IBroker
Broker 返回消息代理 add-in;未安装时会 panic。
func (*ServiceBehavior) BuildEntity ¶ added in v0.3.68
func (svc *ServiceBehavior) BuildEntity(prototype string) *EntityCreator
BuildEntity 创建绑定当前服务及 prototype 名称的实体构建器。
func (*ServiceBehavior) BuildEntityPT ¶ added in v0.3.53
func (svc *ServiceBehavior) BuildEntityPT(prototype string) *EntityPTCreator
BuildEntityPT 创建绑定当前服务及 prototype 名称的实体原型构建器。
func (*ServiceBehavior) BuildRuntime ¶ added in v0.3.53
func (svc *ServiceBehavior) BuildRuntime() *RuntimeCreator
BuildRuntime 创建绑定当前服务的运行时构建器。
func (*ServiceBehavior) DistEntityQuerier ¶ added in v0.3.68
func (svc *ServiceBehavior) DistEntityQuerier() dent.IDistEntityQuerier
DistEntityQuerier 返回分布式实体查询 add-in;未安装时会 panic。
func (*ServiceBehavior) DistService ¶ added in v0.3.68
func (svc *ServiceBehavior) DistService() dsvc.IDistService
DistService 返回分布式服务 add-in;未安装时会 panic。
func (*ServiceBehavior) DistSync ¶ added in v0.3.68
func (svc *ServiceBehavior) DistSync() dsync.IDistSync
DistSync 返回分布式同步 add-in;未安装时会 panic。
func (*ServiceBehavior) L ¶ added in v0.3.68
func (svc *ServiceBehavior) L() *zap.Logger
L 返回当前服务的结构化日志器。
func (*ServiceBehavior) Memory ¶ added in v0.3.68
func (svc *ServiceBehavior) Memory() *sync.Map
Memory 返回服务私有的并发键值存储。
func (*ServiceBehavior) RPC ¶ added in v0.3.68
func (svc *ServiceBehavior) RPC() rpc.IRPC
RPC 返回 RPC add-in;未安装时会 panic。
func (*ServiceBehavior) Registry ¶ added in v0.3.68
func (svc *ServiceBehavior) Registry() discovery.IRegistry
Registry 返回服务发现 add-in;未安装时会 panic。
func (*ServiceBehavior) ReplicaNo ¶ added in v0.3.68
func (svc *ServiceBehavior) ReplicaNo() int
ReplicaNo 返回当前服务在本次应用启动中的副本序号,从 0 开始。
func (*ServiceBehavior) S ¶ added in v0.3.68
func (svc *ServiceBehavior) S() *zap.SugaredLogger
S 返回当前服务的 SugaredLogger。
func (*ServiceBehavior) ServiceConf ¶ added in v0.3.68
func (svc *ServiceBehavior) ServiceConf() *viper.Viper
ServiceConf 返回以当前服务名为键的配置子树;不存在时可能返回 nil。
Source Files
¶
- app.go
- cachecp.go
- comp.go
- comp_async.go
- comp_rpc.go
- continue.go
- doc.go
- entity.go
- entity_async.go
- entity_rpc.go
- entitycreator.go
- entityptcreator.go
- errors.go
- runtime.go
- runtime_addin.go
- runtime_assembler.go
- runtime_instantiator.go
- runtime_lifecycle.go
- runtimecreator.go
- service.go
- service_addin.go
- service_assembler.go
- service_instantiator.go
- service_lifecycle.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package addins 在单一导入路径下重新导出框架内置 add-in 的描述符和 选项辅助入口。
|
Package addins 在单一导入路径下重新导出框架内置 add-in 的描述符和 选项辅助入口。 |
|
broker
Package broker 定义框架服务使用的发布订阅 broker 抽象。
|
Package broker 定义框架服务使用的发布订阅 broker 抽象。 |
|
broker/broker_nats
Package broker_nats 提供基于 NATS 的 broker add-in 实现。
|
Package broker_nats 提供基于 NATS 的 broker add-in 实现。 |
|
conf
Package conf 提供基于 Viper 的服务配置 add-in。
|
Package conf 提供基于 Viper 的服务配置 add-in。 |
|
db
Package db 为服务代码提供跨数据库的辅助能力。
|
Package db 为服务代码提供跨数据库的辅助能力。 |
|
db/dsn
Package dsn 定义数据库 add-in 共享的带标签连接描述和后端类型常量。
|
Package dsn 定义数据库 add-in 共享的带标签连接描述和后端类型常量。 |
|
db/mongodb
Package mongodb 提供服务侧的 MongoDB 客户端 add-in。
|
Package mongodb 提供服务侧的 MongoDB 客户端 add-in。 |
|
db/redisdb
Package redisdb 提供服务侧的 Redis 客户端 add-in。
|
Package redisdb 提供服务侧的 Redis 客户端 add-in。 |
|
db/sqldb
Package sqldb 提供基于 GORM 的 SQL 数据库 add-in。
|
Package sqldb 提供基于 GORM 的 SQL 数据库 add-in。 |
|
dent
Package dent 提供分布式实体查询与注册 add-in。
|
Package dent 提供分布式实体查询与注册 add-in。 |
|
discovery
Package discovery 定义分布式服务使用的服务发现抽象。
|
Package discovery 定义分布式服务使用的服务发现抽象。 |
|
discovery/discovery_etcd
Package discovery_etcd 提供基于 ETCD 的 discovery registry add-in 实现。
|
Package discovery_etcd 提供基于 ETCD 的 discovery registry add-in 实现。 |
|
dsvc
Package dsvc 提供分布式服务寻址和调用支撑能力。
|
Package dsvc 提供分布式服务寻址和调用支撑能力。 |
|
dsync
Package dsync 定义分布式同步能力的抽象层,供不同锁实现复用。
|
Package dsync 定义分布式同步能力的抽象层,供不同锁实现复用。 |
|
dsync/dsync_etcd
Package dsync_etcd 提供基于 ETCD 的 dsync add-in 实现。
|
Package dsync_etcd 提供基于 ETCD 的 dsync add-in 实现。 |
|
dsync/dsync_redis
Package dsync_redis 提供基于 Redis 的 dsync add-in 实现。
|
Package dsync_redis 提供基于 Redis 的 dsync add-in 实现。 |
|
gate
Package gate 提供构建在 GTP 传输栈之上的网关 add-in。
|
Package gate 提供构建在 GTP 传输栈之上的网关 add-in。 |
|
gate/cli
Package cli 提供面向 gate 服务端的客户端传输层。
|
Package cli 提供面向 gate 服务端的客户端传输层。 |
|
log
Package log 提供共享的基于 Zap 的日志 add-in。
|
Package log 提供共享的基于 Zap 的日志 add-in。 |
|
router
Package router 在 gate session 之上提供会话路由、实体映射和组播辅助。
|
Package router 在 gate session 之上提供会话路由、实体映射和组播辅助。 |
|
rpc
Package rpc 提供服务侧 RPC add-in,以及配套的代理与结果辅助能力。
|
Package rpc 提供服务侧 RPC add-in,以及配套的代理与结果辅助能力。 |
|
rpc/callpath
Package callpath 负责 RPC 目标路径的编码与解码。
|
Package callpath 负责 RPC 目标路径的编码与解码。 |
|
rpc/rpcli
Package rpcli 提供构建在 gate/cli 和 GAP 消息之上的客户端 RPC 辅助能力。
|
Package rpcli 提供构建在 gate/cli 和 GAP 消息之上的客户端 RPC 辅助能力。 |
|
rpc/rpcpcsr
Package rpcpcsr 提供 rpc add-in 使用的内置 RPC 处理器和投递器约定。
|
Package rpcpcsr 提供 rpc add-in 使用的内置 RPC 处理器和投递器约定。 |
|
rpcstack
Package rpcstack 提供 runtime 作用域的 RPC 调用链上下文。
|
Package rpcstack 提供 runtime 作用域的 RPC 调用链上下文。 |
|
Package net 汇总框架中的网络通信相关能力。
|
Package net 汇总框架中的网络通信相关能力。 |
|
gap
Package gap 定义 Golaxy 应用层协议(Golaxy Application Protocol)。
|
Package gap 定义 Golaxy 应用层协议(Golaxy Application Protocol)。 |
|
gap/codec
Package codec 提供 GAP 消息包的编解码能力。
|
Package codec 提供 GAP 消息包的编解码能力。 |
|
gap/variant
Package variant 提供 GAP 消息和 RPC 负载使用的动态值模型。
|
Package variant 提供 GAP 消息和 RPC 负载使用的动态值模型。 |
|
gtp
Package gtp 定义 Golaxy 传输协议(Golaxy Transfer Protocol)。
|
Package gtp 定义 Golaxy 传输协议(Golaxy Transfer Protocol)。 |
|
gtp/codec
Package codec 提供 GTP 消息包的编解码能力。
|
Package codec 提供 GTP 消息包的编解码能力。 |
|
gtp/method
Package method 提供 GTP 使用的密码学与压缩基础能力。
|
Package method 提供 GTP 使用的密码学与压缩基础能力。 |
|
gtp/sign
command
Command sign 用于生成 GTP 签名和验签使用的 RSA 密钥文件。
|
Command sign 用于生成 GTP 签名和验签使用的 RSA 密钥文件。 |
|
gtp/transport
Package transport 提供 GTP 的连接层运行时能力。
|
Package transport 提供 GTP 的连接层运行时能力。 |
|
netpath
Package netpath 提供逻辑网络路径的基础处理函数。
|
Package netpath 提供逻辑网络路径的基础处理函数。 |
|
Package utils 汇总框架中的通用基础工具。
|
Package utils 汇总框架中的通用基础工具。 |
|
binaryutil
Package binaryutil 提供二进制读写和字节缓冲辅助工具。
|
Package binaryutil 提供二进制读写和字节缓冲辅助工具。 |
|
concurrent
Package concurrent 提供轻量级并发控制辅助组件。
|
Package concurrent 提供轻量级并发控制辅助组件。 |