framework

package module
v0.1.56 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: LGPL-2.1 Imports: 38 Imported by: 0

README

framework

Golaxy分布式服务开发框架,基于Actor线程模型(Actor Model)与分布式实体(Distributed Entities)架构,可以快速开发服务器应用。

本框架特点如下:

...

本包提供以下插件:

  • 消息队列与事件驱动架构(MQ and Broker),基于NATS。
  • 服务发现(Service Discovery),基于Etcd或Redis。
  • 分布式锁(Distributed Sync),基于Etcd或Redis。
  • 分布式服务支持(Distributed Service),定义分布式节点地址格式,提供异步模型未来(Future),支持分布式服务间通信,可以横向拓展服务。
  • 分布式实体支持(Distributed Entities),提供分布式实体信息上报与查询功能,支持分布式实体间通信。
  • GTP协议(Golaxy Transfer Protocol),适用于长连接、实时通信的工作场景,需要工作在可靠网络协议(TCP/WebSocket)之上,支持双向签名验证、链路加密、链路鉴权、断线续连重传、自定义消息等特性。
  • GTP协议网关与客户端(GTP Gate and Client),基于TCP/WebSocket的GTP网关与客户端实现。
  • GAP协议(Golaxy Application Protocol),适用于开发应用层通信消息,需要工作在GTP协议或MQ之上,支持消息判重、自定义消息、自定义可变类型等特性。
  • 路由(Router),支持规划路线,映射网关上的会话与实体,使任意服务可以与客户端通信,还可以创建分组,支持消息组播。
  • RPC支持(Remote Procedure Call),支持服务间、实体间、或与客户端和分组间进行RPC调用,基于GAP协议,支持可变类型,整体做到了简单易用。
  • 日志(Logger),基于Zap。
  • 配置(Config),基于Viper。

Install

go get -u git.golaxy.org/framework

Documentation

Overview

Package framework Golaxy分布式服务开发框架。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrComponentNotLiving = errors.New("async/await: component not living")
)

Functions

func ReadChan added in v0.1.56

func ReadChan[T any](cb *ComponentBehavior, ch <-chan T) runtime.AsyncRet

ReadChan 读取channel

Types

type App

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

App 应用

func NewApp

func NewApp() *App

NewApp 创建应用

func (*App) GetStartupConf

func (app *App) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

func (*App) InitCB

func (app *App) InitCB(cb generic.DelegateAction1[*App]) *App

InitCB 初始化回调

func (*App) Run

func (app *App) Run()

Run 运行

func (*App) Setup

func (app *App) Setup(name string, generic any) *App

Setup 安装服务泛化类型

func (*App) StartingCB

func (app *App) StartingCB(cb generic.DelegateAction1[*App]) *App

StartingCB 启动回调

func (*App) TerminateCB added in v0.1.33

func (app *App) TerminateCB(cb generic.DelegateAction1[*App]) *App

TerminateCB 终止回调

type AwaitDirector added in v0.1.56

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

AwaitDirector 异步等待分发器

func (AwaitDirector) All added in v0.1.56

func (ad AwaitDirector) All(fun generic.ActionVar1[[]runtime.Ret, any], va ...any)

All 异步等待所有结果返回

func (AwaitDirector) Any added in v0.1.56

func (ad AwaitDirector) Any(fun generic.ActionVar1[runtime.Ret, any], va ...any)

Any 异步等待任意一个结果返回

func (AwaitDirector) AnyOK added in v0.1.56

func (ad AwaitDirector) AnyOK(fun generic.ActionVar1[runtime.Ret, any], va ...any)

AnyOK 异步等待任意一个结果成功返回

func (AwaitDirector) Pipe added in v0.1.56

func (ad AwaitDirector) Pipe(ctx context.Context, fun generic.ActionVar1[runtime.Ret, any], va ...any)

Pipe 异步等待管道返回

type ComponentBehavior added in v0.1.56

type ComponentBehavior struct {
	ec.ComponentBehavior
}

ComponentBehavior 组件行为,在开发新组件时,匿名嵌入至组件结构体中

func (*ComponentBehavior) Async added in v0.1.56

Async 异步执行代码,有返回值

func (*ComponentBehavior) AsyncVoid added in v0.1.56

func (c *ComponentBehavior) AsyncVoid(fun generic.ActionVar0[any], va ...any) runtime.AsyncRet

AsyncVoid 异步执行代码,无返回值

func (*ComponentBehavior) Await added in v0.1.56

func (c *ComponentBehavior) Await(asyncRet ...runtime.AsyncRet) AwaitDirector

Await 异步等待结果返回

func (*ComponentBehavior) BalanceOneWayRPC added in v0.1.56

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) runtime.AsyncRet

BalanceRPC 使用负载均衡模式,向分布式实体目标服务发送RPC

func (*ComponentBehavior) BroadcastOneWayRPC added in v0.1.56

func (c *ComponentBehavior) BroadcastOneWayRPC(service, comp, method string, args ...any) error

BroadcastOneWayRPC 使用广播模式,向分布式实体目标服务发送单向RPC

func (*ComponentBehavior) CliRPC added in v0.1.56

func (c *ComponentBehavior) CliRPC(method string, args ...any) runtime.AsyncRet

CliRPC 向客户端发送RPC

func (*ComponentBehavior) CliRPCToEntity added in v0.1.56

func (c *ComponentBehavior) CliRPCToEntity(entityId uid.Id, method string, args ...any) runtime.AsyncRet

CliRPCToEntity 向客户端实体发送RPC

func (*ComponentBehavior) GetRuntime added in v0.1.56

func (c *ComponentBehavior) GetRuntime() Runtime

GetRuntime 获取运行时

func (*ComponentBehavior) GetService added in v0.1.56

func (c *ComponentBehavior) GetService() Service

GetService 获取服务

func (*ComponentBehavior) GlobalBalanceOneWayRPC added in v0.1.56

func (c *ComponentBehavior) GlobalBalanceOneWayRPC(comp, method string, args ...any) error

GlobalBalanceOneWayRPC 使用全局负载均衡模式,向分布式实体任意服务发送单向RPC

func (*ComponentBehavior) GlobalBalanceRPC added in v0.1.56

func (c *ComponentBehavior) GlobalBalanceRPC(comp, method string, args ...any) runtime.AsyncRet

GlobalBalanceRPC 使用全局负载均衡模式,向分布式实体任意服务发送RPC

func (*ComponentBehavior) GlobalBroadcastOneWayRPC added in v0.1.56

func (c *ComponentBehavior) GlobalBroadcastOneWayRPC(comp, method string, args ...any) error

GlobalBroadcastOneWayRPC 使用全局广播模式,向分布式实体所有服务发送单向RPC

func (*ComponentBehavior) Go added in v0.1.56

Go 使用新线程执行代码,有返回值(注意线程安全)

func (*ComponentBehavior) GoVoid added in v0.1.56

func (c *ComponentBehavior) GoVoid(fun generic.ActionVar0[any], va ...any) runtime.AsyncRet

GoVoid 使用新线程执行代码,无返回值(注意线程安全)

func (*ComponentBehavior) OneWayCliRPC added in v0.1.56

func (c *ComponentBehavior) OneWayCliRPC(method string, args ...any) error

OneWayCliRPC 向客户端发送单向RPC

func (*ComponentBehavior) OneWayCliRPCToEntity added in v0.1.56

func (c *ComponentBehavior) OneWayCliRPCToEntity(entityId uid.Id, method string, args ...any) error

OneWayCliRPCToEntity 向客户端实体发送单向RPC

func (*ComponentBehavior) OneWayRPC added in v0.1.56

func (c *ComponentBehavior) OneWayRPC(service, comp, method string, args ...any) error

OneWayRPC 向分布式实体目标服务发送单向RPC

func (*ComponentBehavior) RPC added in v0.1.56

func (c *ComponentBehavior) RPC(service, comp, method string, args ...any) runtime.AsyncRet

RPC 向分布式实体目标服务发送RPC

func (*ComponentBehavior) TimeAfter added in v0.1.56

func (c *ComponentBehavior) TimeAfter(dur time.Duration) runtime.AsyncRet

TimeAfter 定时器,指定时长

func (*ComponentBehavior) TimeAt added in v0.1.56

func (c *ComponentBehavior) TimeAt(at time.Time) runtime.AsyncRet

TimeAt 定时器,指定时间点

func (*ComponentBehavior) TimeTick added in v0.1.56

func (c *ComponentBehavior) TimeTick(dur time.Duration) runtime.AsyncRet

TimeTick 心跳器

type IRuntimeInstantiation added in v0.1.45

type IRuntimeInstantiation interface {
	Instantiation() runtime.Context
}

IRuntimeInstantiation 运行时实例化接口

type IServiceInstantiation added in v0.1.45

type IServiceInstantiation interface {
	Instantiation() service.Context
}

IServiceInstantiation 服务实例化接口

type InstallRuntimeDistEntities

type InstallRuntimeDistEntities interface {
	InstallDistEntities(ctx runtime.Context)
}

type InstallRuntimeLogger

type InstallRuntimeLogger interface {
	InstallLogger(ctx runtime.Context)
}

type InstallServiceBroker

type InstallServiceBroker interface {
	InstallBroker(ctx service.Context)
}

type InstallServiceConfig

type InstallServiceConfig interface {
	InstallConfig(ctx service.Context)
}

type InstallServiceDistEntityQuerier

type InstallServiceDistEntityQuerier interface {
	InstallDistEntityQuerier(ctx service.Context)
}

type InstallServiceDistService

type InstallServiceDistService interface {
	InstallDistService(ctx service.Context)
}

type InstallServiceDistSync

type InstallServiceDistSync interface {
	InstallDistSync(ctx service.Context)
}

type InstallServiceLogger

type InstallServiceLogger interface {
	InstallLogger(ctx service.Context)
}

type InstallServiceRPC

type InstallServiceRPC interface {
	InstallRPC(ctx service.Context)
}

type InstallServiceRegistry

type InstallServiceRegistry interface {
	InstallRegistry(ctx service.Context)
}

type LifecycleRuntimeBirth

type LifecycleRuntimeBirth interface {
	Birth(ctx runtime.Context)
}

type LifecycleRuntimeBuilt added in v0.1.45

type LifecycleRuntimeBuilt interface {
	Built(ctx runtime.Context)
}

type LifecycleRuntimeFrameLoopBegin

type LifecycleRuntimeFrameLoopBegin interface {
	FrameLoopBegin(ctx runtime.Context)
}

type LifecycleRuntimeFrameLoopEnd

type LifecycleRuntimeFrameLoopEnd interface {
	FrameLoopEnd(ctx runtime.Context)
}

type LifecycleRuntimeFrameUpdateBegin

type LifecycleRuntimeFrameUpdateBegin interface {
	FrameUpdateBegin(ctx runtime.Context)
}

type LifecycleRuntimeFrameUpdateEnd

type LifecycleRuntimeFrameUpdateEnd interface {
	FrameUpdateEnd(ctx runtime.Context)
}

type LifecycleRuntimeRunCallBegin

type LifecycleRuntimeRunCallBegin interface {
	RunCallBegin(ctx runtime.Context)
}

type LifecycleRuntimeRunCallEnd

type LifecycleRuntimeRunCallEnd interface {
	RunCallEnd(ctx runtime.Context)
}

type LifecycleRuntimeRunGCBegin

type LifecycleRuntimeRunGCBegin interface {
	RunGCBegin(ctx runtime.Context)
}

type LifecycleRuntimeRunGCEnd

type LifecycleRuntimeRunGCEnd interface {
	RunGCEnd(ctx runtime.Context)
}

type LifecycleRuntimeStarted

type LifecycleRuntimeStarted interface {
	Started(ctx runtime.Context)
}

type LifecycleRuntimeStarting

type LifecycleRuntimeStarting interface {
	Starting(ctx runtime.Context)
}

type LifecycleRuntimeTerminated

type LifecycleRuntimeTerminated interface {
	Terminated(ctx runtime.Context)
}

type LifecycleRuntimeTerminating

type LifecycleRuntimeTerminating interface {
	Terminating(ctx runtime.Context)
}

type LifecycleServiceBirth

type LifecycleServiceBirth interface {
	Birth(ctx service.Context)
}

type LifecycleServiceBuilt added in v0.1.45

type LifecycleServiceBuilt interface {
	Built(ctx service.Context)
}

type LifecycleServiceStarted

type LifecycleServiceStarted interface {
	Started(ctx service.Context)
}

type LifecycleServiceStarting

type LifecycleServiceStarting interface {
	Starting(ctx service.Context)
}

type LifecycleServiceTerminated

type LifecycleServiceTerminated interface {
	Terminated(ctx service.Context)
}

type LifecycleServiceTerminating

type LifecycleServiceTerminating interface {
	Terminating(ctx service.Context)
}

type Runtime added in v0.1.56

type Runtime struct {
	Ctx runtime.Context
}

Runtime 运行时

func (Runtime) CreateEntity added in v0.1.56

func (rt Runtime) CreateEntity() core.EntityCreator

CreateEntity 创建实体

func (Runtime) GetDistEntities added in v0.1.56

func (rt Runtime) GetDistEntities() dent.IDistEntities

GetDistEntities 获取分布式实体支持插件

type RuntimeCreator

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

RuntimeCreator 运行时构建器

func CreateRuntime

func CreateRuntime(ctx service.Context) RuntimeCreator

CreateRuntime 创建运行时

func (RuntimeCreator) AutoRun

func (c RuntimeCreator) AutoRun(auto bool) RuntimeCreator

AutoRun 自动开始运行

func (RuntimeCreator) FPS added in v0.1.27

FPS 帧率

func (RuntimeCreator) Name

func (c RuntimeCreator) Name(name string) RuntimeCreator

Name 名称

func (RuntimeCreator) PanicHandling added in v0.1.27

func (c RuntimeCreator) PanicHandling(autoRecover bool, reportError chan error) RuntimeCreator

PanicHandling panic时的处理方式

func (RuntimeCreator) ProcessQueueCapacity

func (c RuntimeCreator) ProcessQueueCapacity(cap int) RuntimeCreator

ProcessQueueCapacity 任务处理流水线大小

func (RuntimeCreator) Setup

func (c RuntimeCreator) Setup(generic any) RuntimeCreator

Setup 安装运行时泛化类型

func (RuntimeCreator) Spawn

func (c RuntimeCreator) Spawn() core.Runtime

Spawn 创建运行时

type RuntimeGeneric added in v0.1.37

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

RuntimeGeneric 运行时泛化类型

func (*RuntimeGeneric) GetMemKVs added in v0.1.37

func (r *RuntimeGeneric) GetMemKVs() *sync.Map

GetMemKVs 获取服务内存KV数据库

func (*RuntimeGeneric) GetServiceCtx added in v0.1.37

func (r *RuntimeGeneric) GetServiceCtx() service.Context

GetServiceCtx 获取服务上下文

func (*RuntimeGeneric) GetStartupConf added in v0.1.37

func (r *RuntimeGeneric) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

type RuntimeInstance added in v0.1.45

type RuntimeInstance struct {
	runtime.ContextBehavior
}

RuntimeInstance 运行时实例

func (*RuntimeInstance) CreateEntity added in v0.1.45

func (instance *RuntimeInstance) CreateEntity() core.EntityCreator

CreateEntity 创建实体

func (*RuntimeInstance) GetMemKVs added in v0.1.45

func (instance *RuntimeInstance) GetMemKVs() *sync.Map

GetMemKVs 获取服务内存KV数据库

func (*RuntimeInstance) GetStartupConf added in v0.1.45

func (instance *RuntimeInstance) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

type Service added in v0.1.56

type Service struct {
	Ctx service.Context
}

Service 服务

func (Service) CreateEntityPT added in v0.1.56

func (serv Service) CreateEntityPT() core.EntityPTCreator

CreateEntityPT 创建实体原型

func (Service) CreateRuntime added in v0.1.56

func (serv Service) CreateRuntime() RuntimeCreator

CreateRuntime 创建运行时

func (Service) GetBroker added in v0.1.56

func (serv Service) GetBroker() broker.IBroker

GetBroker 获取broker插件

func (Service) GetConf added in v0.1.56

func (serv Service) GetConf() conf.IVisitConf

GetConf 获取配置插件

func (Service) GetDistEntityQuerier added in v0.1.56

func (serv Service) GetDistEntityQuerier() dentq.IDistEntityQuerier

GetDistEntityQuerier 获取分布式实体查询插件

func (Service) GetDistService added in v0.1.56

func (serv Service) GetDistService() dserv.IDistService

GetDistService 获取分布式服务插件

func (Service) GetDistSync added in v0.1.56

func (serv Service) GetDistSync() dsync.IDistSync

GetDistSync 获取分布式同步插件

func (Service) GetMemKVs added in v0.1.56

func (serv Service) GetMemKVs() *sync.Map

GetMemKVs 获取服务内存KV数据库

func (Service) GetRPC added in v0.1.56

func (serv Service) GetRPC() rpc.IRPC

GetRPC 获取RPC支持插件

func (Service) GetRegistry added in v0.1.56

func (serv Service) GetRegistry() discovery.IRegistry

GetRegistry 获取服务发现插件

func (Service) GetStartupConf added in v0.1.56

func (serv Service) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

type ServiceGeneric added in v0.1.37

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

ServiceGeneric 服务泛化类型

func (*ServiceGeneric) GetName added in v0.1.37

func (s *ServiceGeneric) GetName() string

GetName 获取服务名称

func (*ServiceGeneric) GetStartupConf added in v0.1.37

func (s *ServiceGeneric) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

type ServiceInstance added in v0.1.45

type ServiceInstance struct {
	service.ContextBehavior
}

ServiceInstance 服务实例

func (*ServiceInstance) CreateEntityPT added in v0.1.45

func (instance *ServiceInstance) CreateEntityPT() core.EntityPTCreator

CreateEntityPT 创建实体原型

func (*ServiceInstance) CreateRuntime added in v0.1.45

func (instance *ServiceInstance) CreateRuntime() RuntimeCreator

CreateRuntime 创建运行时

func (*ServiceInstance) GetBroker added in v0.1.45

func (instance *ServiceInstance) GetBroker() broker.IBroker

GetBroker 获取broker插件

func (*ServiceInstance) GetConf added in v0.1.45

func (instance *ServiceInstance) GetConf() conf.IVisitConf

GetConf 获取配置插件

func (*ServiceInstance) GetDistEntityQuerier added in v0.1.45

func (instance *ServiceInstance) GetDistEntityQuerier() dentq.IDistEntityQuerier

GetDistEntityQuerier 获取分布式实体查询插件

func (*ServiceInstance) GetDistService added in v0.1.45

func (instance *ServiceInstance) GetDistService() dserv.IDistService

GetDistService 获取分布式服务插件

func (*ServiceInstance) GetDistSync added in v0.1.45

func (instance *ServiceInstance) GetDistSync() dsync.IDistSync

GetDistSync 获取分布式同步插件

func (*ServiceInstance) GetMemKVs added in v0.1.45

func (instance *ServiceInstance) GetMemKVs() *sync.Map

GetMemKVs 获取服务内存KV数据库

func (*ServiceInstance) GetRPC added in v0.1.45

func (instance *ServiceInstance) GetRPC() rpc.IRPC

GetRPC 获取RPC支持插件

func (*ServiceInstance) GetRegistry added in v0.1.45

func (instance *ServiceInstance) GetRegistry() discovery.IRegistry

GetRegistry 获取服务发现插件

func (*ServiceInstance) GetStartupConf added in v0.1.45

func (instance *ServiceInstance) GetStartupConf() *viper.Viper

GetStartupConf 获取启动参数配置

func (*ServiceInstance) GetStartupIdx added in v0.1.48

func (instance *ServiceInstance) GetStartupIdx() int

GetStartupIdx 获取启动索引

Directories

Path Synopsis
net
gap
Package gap Golaxy应用层协议(golaxy application protocol),适用于开发应用层通信消息,需要工作在GTP协议或MQ之上,支持消息判重,解决了幂等性问题。
Package gap Golaxy应用层协议(golaxy application protocol),适用于开发应用层通信消息,需要工作在GTP协议或MQ之上,支持消息判重,解决了幂等性问题。
gtp
Package gtp Golaxy传输层协议(golaxy transfer protocol),适用于长连接、实时通信的工作场景,需要工作在可靠网络协议(TCP/WebSocket)之上,支持链路加密、链路鉴权、断线续连等特性。
Package gtp Golaxy传输层协议(golaxy transfer protocol),适用于长连接、实时通信的工作场景,需要工作在可靠网络协议(TCP/WebSocket)之上,支持链路加密、链路鉴权、断线续连等特性。
plugins
dentq
+k8s:deepcopy-gen=package
+k8s:deepcopy-gen=package
discovery
+k8s:deepcopy-gen=package
+k8s:deepcopy-gen=package
log
rpc
util

Jump to

Keyboard shortcuts

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