Documentation
¶
Index ¶
- Constants
- func AddComponent(self Component, c Component) error
- func FormatAppFullName(appType string, appId int32, zone string, env string) string
- func GetComponent[T Component](self Component, t T) (c T)
- func Make1Key_int[T any](arr []*T, dict map[int]*T, key string) error
- func Make1Key_int32[T any](arr []*T, dict map[int32]*T, key string) error
- func Make1Key_int64[T any](arr []*T, dict map[int64]*T, key string) error
- func Make1Key_string[T any](arr []*T, dict map[string]*T, key string) error
- func Make2Key_int64_int64[T any](arr []*T, dict map[int64]map[int64]*T, key1 string, key2 string) error
- func Make2Key_int64_string[T any](arr []*T, dict map[int64]map[string]*T, key1 string, key2 string) error
- func Make2Key_int_int[T any](arr []*T, dict map[int]map[int]*T, key1 string, key2 string) error
- func Make2Key_string_int64[T any](arr []*T, dict map[string]map[int64]*T, key1 string, key2 string) error
- func Make3Key_int64_int64_int64[T any](arr []*T, dict map[int64]map[int64]map[int64]*T, key1 string, key2 string, ...) error
- func OnApplicationCreate(r Runtime)
- func ParseAppFullName(fullName string) (name string, id int32, err error)
- func TypeOf[T any]() reflect.Type
- type A4399PlatformConfig
- type AdminClient
- type AdminConfig
- type AdminService
- type Application
- type ApplicationArgs
- type ApplicationFramework
- type BaseComponent
- func (c *BaseComponent) AddComponent(component Component) error
- func (c *BaseComponent) Awake() error
- func (c *BaseComponent) Create() error
- func (c *BaseComponent) Destory() error
- func (c *BaseComponent) GetComponents(t reflect.Type) []Component
- func (c *BaseComponent) GetObject() *Object
- func (c *BaseComponent) SetObject(object *Object) error
- func (c *BaseComponent) Start() error
- type BehaviorConfig
- type BroadcastReloadResourceResult
- type Component
- type Config
- type Cron
- type DbClient
- type DbClientComponent
- type DbConfig
- type DbDao
- type DouyinPlatformConfig
- type EtcdClientConfig
- type EtcdConfig
- type Framework
- type GatewayClient
- type GatewayConfig
- type GatewayConn
- type GatewayHandler
- type GatewayMessage
- type GrpcConfig
- type GrpcServer
- type HttpConfig
- type HttpHandler
- type JwtConfig
- type KuaishouPlatformConfig
- type LocalPlayer
- type LocalPlayerWatchHandler
- type LogConfig
- type Logger
- type MongoClient
- type MysqlClient
- type Object
- type Peer
- type PeerWatchHandler
- type PlatformConfig
- type PlatformSdk
- type PprofConfig
- type Proto
- type ProtoHandler
- type ProtoPush
- type ProtoRequest
- type ProtoResponse
- type PwdPlatformConfig
- type RedisClient
- type Registry
- type RegistryClient
- type ResourceConfig
- type ResourceHandler
- type ResourceLoader
- type ResourceSource
- type Runtime
- type Scene
- type SdkAccount
- type SdkPayOrder
- type Service
- type ServiceContainer
- type ServiceName
- type ServiceWatchHandler
- type TestPlatformConfig
- type UltraPlatformConfig
- type WeixinPlatformConfig
Constants ¶
View Source
const ( Env_DEV = "dev" Env_QA = "qa" Env_prd = "prd" )
环境枚举
View Source
const ( GAMEDB_NAME = "gamedb" RESOURCEDB_NAME = "resourcedb" STATDB_NAME = "statdb" ACCOUNTDB_NAME = "accountdb" LOGDB_NAME = "logdb" BEHAVIORDB_NAME = "behaviordb" ACCOUNTCACHE_NAME = "accountcache" GAMECACHE_NAME = "gamecache" ADMINCACHE_NAME = "admincache" ADMINDB_NAME = "admindb" )
View Source
const ( MONGODB_NAME = "mongodb" REDIS_NAME = "redis" MYSQL_NAME = "mysql" )
View Source
const ( GatewayMessageType_RESPONSE = 2 GatewayMessageType_PUSH = 3 )
View Source
const GRPC_PATH_KEY = "girapath"
Variables ¶
This section is empty.
Functions ¶
func AddComponent ¶
func FormatAppFullName ¶
func GetComponent ¶
func Make2Key_int64_int64 ¶
func Make2Key_int64_string ¶
func Make2Key_int_int ¶
func Make2Key_string_int64 ¶
Types ¶
type A4399PlatformConfig ¶
type A4399PlatformConfig struct {
Secret string `yaml:"secret"`
}
type AdminClient ¶
type AdminClient interface { // 广播所有节点重载资源 BroadcastReloadResource(ctx context.Context, name string) (result BroadcastReloadResourceResult, err error) }
type AdminConfig ¶
type AdminConfig struct {
None string `yaml:"none"`
}
type AdminService ¶
type AdminService interface {
ResourceReload() error
}
type Application ¶
type Application interface { // ======= 生命周期回调 =========== // 配置加载完成后接收通知 OnConfigLoad(c *Config) error OnCreate() error OnStart() error OnStop() error }
func GetApplication ¶
func GetApplication() Application
type ApplicationArgs ¶
type ApplicationFramework ¶
type ApplicationFramework interface {
OnFrameworkInit() []Framework
}
type BaseComponent ¶
type BaseComponent struct {
// contains filtered or unexported fields
}
func (*BaseComponent) AddComponent ¶
func (c *BaseComponent) AddComponent(component Component) error
func (*BaseComponent) Awake ¶
func (c *BaseComponent) Awake() error
func (*BaseComponent) Create ¶
func (c *BaseComponent) Create() error
func (*BaseComponent) Destory ¶
func (c *BaseComponent) Destory() error
func (*BaseComponent) GetComponents ¶
func (c *BaseComponent) GetComponents(t reflect.Type) []Component
func (*BaseComponent) GetObject ¶
func (c *BaseComponent) GetObject() *Object
func (*BaseComponent) SetObject ¶
func (c *BaseComponent) SetObject(object *Object) error
func (*BaseComponent) Start ¶
func (c *BaseComponent) Start() error
type BehaviorConfig ¶
type Component ¶
type Component interface { GetObject() *Object SetObject(object *Object) error Create() error Awake() error Start() error Destory() error GetComponents(t reflect.Type) []Component AddComponent(c Component) error }
func GetComponents ¶
type Config ¶
type Config struct { Raw []byte Thread int `yaml:"thread"` Env string `yaml:"env"` Zone string `yaml:"zone"` Log *LogConfig `yaml:"log"` CoreLog *LogConfig `yaml:"core-log"` BehaviorLog *LogConfig `yaml:"behavior-log"` Pprof PprofConfig `yaml:"pprof"` Sandbox int `yaml:"sandbox"` Db map[string]*DbConfig Resource ResourceConfig `yaml:"resource"` Module struct { Behavior *BehaviorConfig `yaml:"behavior"` Http *HttpConfig `yaml:"http,omitempty"` Etcd *EtcdConfig `yaml:"etcd"` EtcdClient *EtcdClientConfig `yaml:"etcd-client"` Grpc *GrpcConfig `yaml:"grpc"` Plat *PlatformConfig `yaml:"plat"` Jwt *JwtConfig `yaml:"jwt"` Gateway *GatewayConfig `yaml:"gateway"` Admin *AdminConfig `yaml:"admin"` } `yaml:"module"` }
type DbClientComponent ¶
type DbClientComponent interface { GetGameDbClient() DbClient GetStatDbClient() DbClient GetAccountDbClient() DbClient GetResourceDbClient() DbClient GetAdminDbClient() DbClient GetAccountCacheClient() DbClient GetGameCacheClient() DbClient GetLogDbClient() DbClient GetBehaviorDbClient() DbClient GetAdminCacheClient() DbClient }
type DbConfig ¶
type DbConfig struct { Driver string `yaml:"driver"` Host string `yaml:"host"` Port int `yaml:"port"` User string `yaml:"user"` Password string `yaml:"password"` Db string `yaml:"db"` Query string `yaml:"query"` MaxOpenConns int `yaml:"max-open-conns"` MaxIdleConns int `yaml:"max-idle-conns"` ConnMaxIdleTime time.Duration `yaml:"conn-max-idle-time"` ConnMaxLifetime time.Duration `yaml:"conn-max-lifetime"` ConnnectTimeout time.Duration `yaml:"connect-timeout"` }
type DouyinPlatformConfig ¶
type DouyinPlatformConfig struct {
Secret string `yaml:"secret"`
}
type EtcdClientConfig ¶
type EtcdClientConfig struct { Endpoints []struct { Host string `yaml:"host"` Port int `yaml:"port"` } `yaml:"endpoints"` Username string `yaml:"username"` Password string `yaml:"password"` DialTimeout int `yaml:"dial-timeout"` LeaseTimeout int64 `yaml:"lease-timeout"` Address string `yaml:"address"` }
registry配置
type EtcdConfig ¶
type EtcdConfig struct { Endpoints []struct { Host string `yaml:"host"` Port int `yaml:"port"` } `yaml:"endpoints"` Username string `yaml:"username"` Password string `yaml:"password"` DialTimeout int `yaml:"dial-timeout"` LeaseTimeout int64 `yaml:"lease-timeout"` Address string `yaml:"address"` Advertise []struct { Name string `yaml:"name"` Value string `yaml:"value"` } `yaml:"advertise"` }
registry配置
type GatewayClient ¶
type GatewayClient interface { Recv(ctx context.Context) (typ int, route string, reqId uint64, data []byte, err error) Notify(route string, data []byte) error Request(route string, reqId uint64, data []byte) error Close() error }
client端接口
type GatewayConfig ¶
type GatewayConfig struct { IsWebsocket bool `yaml:"is-websocket"` Bind string `yaml:"bind"` Address string `yaml:"address"` Debug bool `yaml:"debug"` Ssl bool `yaml:"ssl"` CertFile string `yaml:"cert-file"` KeyFile string `yaml:"key-file"` WsPath string `yaml:"ws-path"` RecvBuffSize int `yaml:"recv-buff-size"` RecvBacklog int `yaml:"recv-backlog"` SendBacklog int `yaml:"send-backlog"` HandshakeTimeout time.Duration `yaml:"handshake-timeout"` Heartbeat time.Duration `yaml:"heartbeat"` }
网关模块配置
type GatewayConn ¶
type GatewayConn interface { Id() uint64 Close() error Kick(reason string) SendServerSuspend(reason string) SendServerResume(reason string) SendServerMaintain(reason string) SendServerDown(reason string) Recv(ctx context.Context) (GatewayMessage, error) Push(route string, data []byte) error Response(mid uint64, data []byte) error Value(key string) interface{} Set(key string, value interface{}) Uint64(key string) uint64 Int32(key string) int32 SetUserData(value interface{}) UserData() interface{} }
服务端conn接口
type GatewayHandler ¶
type GatewayHandler interface {
ServeClientStream(conn GatewayConn)
}
type GatewayMessage ¶
type GrpcConfig ¶
type GrpcServer ¶
type GrpcServer interface { RegisterService(desc *grpc.ServiceDesc, impl interface{}) GetServer(name string) (svr interface{}, ok bool) }
type HttpConfig ¶
type HttpConfig struct { Addr string `yaml:"addr"` ReadTimeout int64 `yaml:"read-timeout"` WriteTimeout int64 `yaml:"write-timeout"` Ssl bool `yaml:"ssl"` CertFile string `yaml:"cert-file"` KeyFile string `yaml:"key-file"` }
http模块配置
type HttpHandler ¶
type JwtConfig ¶
type JwtConfig struct { Secret string `yaml:"secret"` Expiretime int64 `yaml:"expiretime"` RefreshExpiretime int64 `yaml:"refresh-expiretime"` }
jwt配置
type KuaishouPlatformConfig ¶
type KuaishouPlatformConfig struct {
Secret string `yaml:"secret"`
}
type LocalPlayer ¶
玩家位置
type LocalPlayerWatchHandler ¶
type LocalPlayerWatchHandler interface { OnLocalPlayerAdd(player *LocalPlayer) OnLocalPlayerDelete(player *LocalPlayer) OnLocalPlayerUpdate(player *LocalPlayer) }
侦听玩家位置
type LogConfig ¶
type LogConfig struct { Console bool `yaml:"console"` Db bool `yaml:"db"` Level string `yaml:"level"` // ERROR|WARN|INFO|DEBUG DbLevel string `yaml:"db-level"` TraceErrorStack bool `yaml:"trace-error-stack"` // 输出到文件 Files []struct { Level string `yaml:"level"` // 大于level的都会被输出 Filter string `yaml:"filter"` // 等于filter的才会被输出, filter比level优先级更高 MaxSize int `yaml:"max-size"` MaxBackups int `yaml:"max-backups"` MaxAge int `yaml:"max-age"` Compress bool `yaml:"compress"` Path string `yaml:"path"` Format string `yaml:"format"` // json|console } `yaml:"files"` }
日志配置
type Logger ¶
type Logger interface { Infow(msg string, kvs ...interface{}) Errorw(msg string, kvs ...interface{}) Debugw(msg string, kvs ...interface{}) Fatalw(msg string, kvs ...interface{}) Warnw(msg string, kvs ...interface{}) Info(args ...interface{}) Error(args ...interface{}) Debug(args ...interface{}) Fatal(args ...interface{}) Warn(args ...interface{}) Infof(format string, args ...interface{}) Errorf(format string, args ...interface{}) Debugf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Named(s string) Logger }
type MongoClient ¶
type MysqlClient ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
func (*Object) AddComponent ¶
type Peer ¶
type Peer struct { Name string // 服务类型 Id int32 // 服务id FullName string // 服务全名 Address string // grpc地址 Url string Metadata map[string]string // /server/account_1/ 下的键 }
伙伴节点
type PeerWatchHandler ¶
type PeerWatchHandler interface { OnPeerAdd(peer *Peer) OnPeerDelete(peer *Peer) OnPeerUpdate(peer *Peer) }
侦听伙伴节点
type PlatformConfig ¶
type PlatformConfig struct { Test *TestPlatformConfig `yaml:"test"` Pwd *PwdPlatformConfig `yaml:"pwd"` Ultra *UltraPlatformConfig `yaml:"ultra"` Douyin *DouyinPlatformConfig `yaml:"douyin"` Weixin *WeixinPlatformConfig `yaml:"weixin"` Kuaishou *KuaishouPlatformConfig `yaml:"kuaishou"` A4399 *A4399PlatformConfig `yaml:"a4399"` }
type PlatformSdk ¶
type PprofConfig ¶
type Proto ¶
type Proto interface { // request解码 RequestEncode(name string, session int32, req interface{}) (data []byte, err error) // response编码 ResponseEncode(name string, session int32, response interface{}) (data []byte, err error) // push解码 PushEncode(req ProtoPush) (data []byte, err error) // struct编码 StructEncode(req interface{}) (data []byte, err error) // request解码 RequestDecode(packed []byte) (route string, session int32, resp ProtoRequest, err error) // response解码 ResponseDecode(packed []byte) (route string, session int32, resp ProtoResponse, err error) // push解码 PushDecode(packed []byte) (route string, session int32, resp ProtoPush, err error) // struct编码 StructDecode(data []byte, req interface{}) error // 创建response NewResponse(req ProtoRequest) (resp ProtoResponse, err error) // 生成handler RegisterHandler(handler interface{}) ProtoHandler // 将request路由到handler的相应方法 RequestDispatch(ctx context.Context, handler ProtoHandler, receiver interface{}, route string, session int32, req interface{}, traceDebugMsg bool) (dataResp []byte, pushArr []ProtoPush, err error) // 将push路由到handler的相应方法 PushDispatch(ctx context.Context, handler ProtoHandler, receiver interface{}, route string, req ProtoPush) error }
协议
type ProtoHandler ¶
type ProtoHandler interface { HasRoute(route string) bool // 将push路由到handler的相应方法 PushDispatch(ctx context.Context, receiver interface{}, route string, r interface{}) (err error) // 将request路由到handler的相应方法 RequestDispatch(ctx context.Context, receiver interface{}, route string, r interface{}) (resp interface{}, push []ProtoPush, err error) }
type ProtoRequest ¶
type ProtoRequest interface {
GetRequestName() string
}
type ProtoResponse ¶
type PwdPlatformConfig ¶
type PwdPlatformConfig struct {
Secret string `yaml:"secret"`
}
type RedisClient ¶
type RedisClient interface { DbClient GetRedisClient() *redis.Client }
type Registry ¶
type Registry interface { // 如果失败,则返回当前所在的节点 LockLocalUser(userId string) (*Peer, error) UnlockLocalUser(userId string) (*Peer, error) ListLocalUser() []string WhereIsUser(userId string) (*Peer, error) RangePeers(f func(k any, v any) bool) NewServiceName(serviceName string, opt ...service_options.RegisterOption) string // 注册服务 RegisterService(serviceName string, opt ...service_options.RegisterOption) (*Peer, error) // 反注册服务 UnregisterService(serviceName string) (*Peer, error) // 查找服务 WhereIsService(serviceName string, opt ...service_options.WhereOption) ([]*Peer, error) // 查找节点 WhereIsPeer(appFullName string) (*Peer, error) // 自身节点 SelfPeer() *Peer }
type RegistryClient ¶
type RegistryClient interface { NewServiceName(serviceName string, opt ...service_options.RegisterOption) string WhereIsUser(userId string) (*Peer, error) // 查找服务 WhereIsService(serviceName string, opt ...service_options.WhereOption) ([]*Peer, error) UnregisterPeer(appFullName string) error ListPeerKvs() (peers map[string]string, err error) ListServiceKvs() (services map[string][]string, err error) // 查找节点 WhereIsPeer(appFullName string) (*Peer, error) }
type ResourceConfig ¶
type ResourceConfig struct {
Compress bool `yaml:"compress"`
}
type ResourceHandler ¶
loader加载完成后,由handler进行转换处理
type ResourceLoader ¶
type ResourceLoader interface { // 加载资源 LoadResource(ctx context.Context, client DbClient, dir string, compress bool) error // 加载资源 ReloadResource(ctx context.Context, client DbClient, dir string, compress bool) error // 配置版本 GetResVersion() string // loader版本 GetLoaderVersion() string }
loader由gen生成
type ResourceSource ¶
type ResourceSource interface { // 返回资源加载器 GetResourceLoader() ResourceLoader OnResourcePreLoad(reload bool) // 资源加载完成 OnResourcePostLoad(reload bool) }
application需要实现的接口,返回loader,和接收loader的事件回调
type Runtime ¶
type Runtime interface { // ======= 状态数据 =========== GetConfig() *Config GetAppType() string GetAppName() string GetAppFullName() string GetEnv() string GetZone() string GetAppId() int32 GetLogDir() string GetWorkDir() string GetAppVersion() string GetBuildTime() int64 GetUpTime() int64 // ======= 同步接口 =========== Wait() error Stop() error Context() context.Context Go(f func() error) Done() <-chan struct{} Frameworks() []Framework Application() Application // ======= 组件 =========== GetServiceContainer() ServiceContainer GetPlatformSdk() PlatformSdk GetCron() Cron GetGrpcServer() GrpcServer GetRegistry() Registry GetRegistryClient() RegistryClient }
func GetRuntime ¶
func GetRuntime() Runtime
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
func CreateScene ¶
func CreateScene() *Scene
func (*Scene) CreateObject ¶
type SdkAccount ¶
type SdkAccount struct { UnionId string OpenId string AccessToken string // access token RefreshToken string // refresh token TokenExpireTime int64 // token过期时间 NickName string // 昵称 Gender int32 // 性别 SmallPic string // 小头像地址 LargePic string // 大头像地址 }
sdk账号
type SdkPayOrder ¶
type SdkPayOrder struct { CporderId string OrderId string PayTime int64 Amount int64 // 单位 分 UserDefine string Response string }
sdk支付订单
type Service ¶
type Service interface { // 服务启动 OnStart(ctx context.Context) error // 服务函数 Serve() error // 服务停止 OnStop() error }
服务
type ServiceContainer ¶
type ServiceContainer interface { // 启动服务 StartService(name string, service Service) error // 停止服务 StopService(service Service) error }
服务容器
type ServiceName ¶
type ServiceName struct { // <<GroupName>>/<<ShortName>> Peer *Peer ServiceFullName string ServiceTypeName string IsSelf bool CreateRevision int64 }
服务名
type ServiceWatchHandler ¶
type ServiceWatchHandler interface { OnServiceAdd(service *ServiceName) OnServiceDelete(service *ServiceName) OnServiceUpdate(service *ServiceName) }
侦听服务状态
type TestPlatformConfig ¶
type TestPlatformConfig struct {
Secret string `yaml:"secret"`
}
type UltraPlatformConfig ¶
type UltraPlatformConfig struct {
Secret string `yaml:"secret"`
}
type WeixinPlatformConfig ¶
type WeixinPlatformConfig struct {
Secret string `yaml:"secret"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.