Documentation ¶
Index ¶
- func AddGRPCInfoToMetadata(metadata map[string]string, region string, host, port string, ...) map[string]string
- func AddMetricTagsToPropagateCtx(ctx context.Context, tags map[string]string) context.Context
- func AddRoute(serverType string, routingFunction router.RoutingFunc) error
- func AddToPropagateCtx(ctx context.Context, key string, val interface{}) context.Context
- func Configure(isFrontend bool, serverType string, serverMode ServerMode, ...)
- func CreatePrometheusReporter(serverType string, config config.MetricsConfig, ...) (*metrics.PrometheusReporter, error)
- func CreateStatsdReporter(serverType string, config config.MetricsConfig) (*metrics.StatsdReporter, error)
- func Descriptor(protoName string) ([]byte, error)
- func Documentation(getPtrNames bool) (map[string]interface{}, error)
- func Error(err error, code string, metadata ...map[string]string) *errors.Error
- func ExtractSpan(ctx context.Context) (trace.SpanContext, error)
- func GetDefaultLoggerFromCtx(ctx context.Context) logging.Logger
- func GetDieChan() chan bool
- func GetFromPropagateCtx(ctx context.Context, key string) interface{}
- func GetMetricsReporters() []metrics.Reporter
- func GetModule(name string) (interfaces.Module, error)
- func GetServer() *cluster.Server
- func GetServerByID(id string) (*cluster.Server, error)
- func GetServerID() string
- func GetServers() []*cluster.Server
- func GetServersByType(t string) (map[string]*cluster.Server, error)
- func GetSessionFromCtx(ctx context.Context) session.Session
- func GroupAddMember(ctx context.Context, groupName, uid string) error
- func GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error
- func GroupContainsMember(ctx context.Context, groupName, uid string) (bool, error)
- func GroupCountMembers(ctx context.Context, groupName string) (int, error)
- func GroupCreate(ctx context.Context, groupName string) error
- func GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error
- func GroupDelete(ctx context.Context, groupName string) error
- func GroupMembers(ctx context.Context, groupName string) ([]string, error)
- func GroupRemoveAll(ctx context.Context, groupName string) error
- func GroupRemoveMember(ctx context.Context, groupName, uid string) error
- func GroupRenewTTL(ctx context.Context, groupName string) error
- func IsRunning() bool
- func NewAfterTimer(duration time.Duration, fn timer.Func) *timer.Timer
- func NewCondTimer(condition timer.Condition, fn timer.Func) (*timer.Timer, error)
- func NewCountTimer(interval time.Duration, count int, fn timer.Func) *timer.Timer
- func NewTimer(interval time.Duration, fn timer.Func) *timer.Timer
- func RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error
- func RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, ...) error
- func Register(c component.Component, options ...component.Option)
- func RegisterModule(module interfaces.Module, name string) error
- func RegisterModuleAfter(module interfaces.Module, name string) error
- func RegisterModuleBefore(module interfaces.Module, name string) error
- func RegisterRPCJob(rpcJob worker.RPCJob) error
- func RegisterRemote(c component.Component, options ...component.Option)
- func ReliableRPC(routeStr string, metadata map[string]interface{}, reply, arg proto.Message) (jid string, err error)
- func ReliableRPCWithOptions(routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ...) (jid string, err error)
- func SendKickToUsers(uids []string, frontendType string) ([]string, error)
- func SendPushToUsers(route string, v interface{}, uids []string, frontendType string) ([]string, error)
- func SetDebug(debug bool)
- func SetDictionary(dict map[string]uint16) error
- func SetHeartbeatTime(interval time.Duration)
- func SetLogger(l logging.Logger)
- func SetTimerBacklog(c int)
- func SetTimerPrecision(precision time.Duration)
- func Shutdown()
- func Start()
- func StartWorker()
- type App
- func (app *App) AddRoute(serverType string, routingFunction router.RoutingFunc) error
- func (app *App) Documentation(getPtrNames bool) (map[string]interface{}, error)
- func (app *App) GetDieChan() chan bool
- func (app *App) GetMetricsReporters() []metrics.Reporter
- func (app *App) GetModule(name string) (interfaces.Module, error)
- func (app *App) GetServer() *cluster.Server
- func (app *App) GetServerByID(id string) (*cluster.Server, error)
- func (app *App) GetServerID() string
- func (app *App) GetServers() []*cluster.Server
- func (app *App) GetServersByType(t string) (map[string]*cluster.Server, error)
- func (app *App) GetSessionFromCtx(ctx context.Context) session.Session
- func (app *App) GroupAddMember(ctx context.Context, groupName, uid string) error
- func (app *App) GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error
- func (app *App) GroupContainsMember(ctx context.Context, groupName, uid string) (bool, error)
- func (app *App) GroupCountMembers(ctx context.Context, groupName string) (int, error)
- func (app *App) GroupCreate(ctx context.Context, groupName string) error
- func (app *App) GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error
- func (app *App) GroupDelete(ctx context.Context, groupName string) error
- func (app *App) GroupMembers(ctx context.Context, groupName string) ([]string, error)
- func (app *App) GroupRemoveAll(ctx context.Context, groupName string) error
- func (app *App) GroupRemoveMember(ctx context.Context, groupName, uid string) error
- func (app *App) GroupRenewTTL(ctx context.Context, groupName string) error
- func (app *App) IsRunning() bool
- func (app *App) RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error
- func (app *App) RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, ...) error
- func (app *App) Register(c component.Component, options ...component.Option)
- func (app *App) RegisterModule(module interfaces.Module, name string) error
- func (app *App) RegisterModuleAfter(module interfaces.Module, name string) error
- func (app *App) RegisterModuleBefore(module interfaces.Module, name string) error
- func (app *App) RegisterRPCJob(rpcJob worker.RPCJob) error
- func (app *App) RegisterRemote(c component.Component, options ...component.Option)
- func (app *App) ReliableRPC(routeStr string, metadata map[string]interface{}, reply, arg proto.Message) (jid string, err error)
- func (app *App) ReliableRPCWithOptions(routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ...) (jid string, err error)
- func (app *App) SendKickToUsers(uids []string, frontendType string) ([]string, error)
- func (app *App) SendPushToUsers(route string, v interface{}, uids []string, frontendType string) ([]string, error)
- func (app *App) SetDebug(debug bool)
- func (app *App) SetDictionary(dict map[string]uint16) error
- func (app *App) SetHeartbeatTime(interval time.Duration)
- func (app *App) Shutdown()
- func (app *App) Start()
- func (app *App) StartWorker()
- type Builder
- type Pitaya
- type PitayaBuilder
- type ServerMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddGRPCInfoToMetadata ¶
func AddGRPCInfoToMetadata( metadata map[string]string, region string, host, port string, externalHost, externalPort string, ) map[string]string
AddGRPCInfoToMetadata adds host, external host and port into metadata
func AddMetricTagsToPropagateCtx ¶
AddMetricTagsToPropagateCtx adds a key and metric tags that will be propagated through RPC calls. Use the same tags that are at 'pitaya.metrics.additionalLabels' config
func AddToPropagateCtx ¶
AddToPropagateCtx adds a key and value that will be propagated through RPC calls
func Configure ¶
func Configure( isFrontend bool, serverType string, serverMode ServerMode, serverMetadata map[string]string, cfgs ...*viper.Viper, )
Configure configures the app
func CreatePrometheusReporter ¶
func CreatePrometheusReporter(serverType string, config config.MetricsConfig, customSpecs models.CustomMetricsSpec) (*metrics.PrometheusReporter, error)
CreatePrometheusReporter create a Prometheus reporter instance
func CreateStatsdReporter ¶
func CreateStatsdReporter(serverType string, config config.MetricsConfig) (*metrics.StatsdReporter, error)
CreateStatsdReporter create a Statsd reporter instance
func Descriptor ¶
Descriptor returns the protobuf message descriptor for a given message name
func Documentation ¶
func ExtractSpan ¶
func ExtractSpan(ctx context.Context) (trace.SpanContext, error)
ExtractSpan retrieves an OpenTelemetry span context from the given context The span context can be received directly or via an RPC call
func GetDefaultLoggerFromCtx ¶
GetDefaultLoggerFromCtx returns the default logger from the given context
func GetDieChan ¶
func GetDieChan() chan bool
func GetFromPropagateCtx ¶
GetFromPropagateCtx adds a key and value that came through RPC calls
func GetMetricsReporters ¶
func GetServerID ¶
func GetServerID() string
func GetServers ¶
func GroupBroadcast ¶
func GroupContainsMember ¶
func GroupCreateWithTTL ¶
func NewAfterTimer ¶
NewAfterTimer returns a new Timer containing a function that will be called after duration that specified by the duration argument. The duration d must be greater than zero; if not, NewAfterTimer will panic. Stop the timer to release associated resources.
func NewCondTimer ¶
NewCondTimer returns a new Timer containing a function that will be called when condition satisfied that specified by the condition argument. The duration d must be greater than zero; if not, NewCondTimer will panic. Stop the timer to release associated resources.
func NewCountTimer ¶
NewCountTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. After count times, timer will be stopped automatically, It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewCountTimer will panic. Stop the timer to release associated resources.
func NewTimer ¶
NewTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewTimer will panic. Stop the timer to release associated resources.
func RegisterModule ¶
func RegisterModule(module interfaces.Module, name string) error
func RegisterModuleAfter ¶
func RegisterModuleAfter(module interfaces.Module, name string) error
func RegisterModuleBefore ¶
func RegisterModuleBefore(module interfaces.Module, name string) error
func RegisterRPCJob ¶
func ReliableRPC ¶
func ReliableRPCWithOptions ¶
func SendPushToUsers ¶
func SetDictionary ¶
func SetHeartbeatTime ¶
func SetTimerBacklog ¶
func SetTimerBacklog(c int)
SetTimerBacklog set the timer created/closing channel backlog, A small backlog may cause the logic to be blocked when call NewTimer/NewCountTimer/timer.Stop in main logic gorontine.
func SetTimerPrecision ¶
SetTimerPrecision set the ticker precision, and time precision can not less than a Millisecond, and can not change after application running. The default precision is time.Second
func StartWorker ¶
func StartWorker()
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the base app struct
func NewApp ¶
func NewApp( serverMode ServerMode, serializer serialize.Serializer, acceptors []acceptor.Acceptor, dieChan chan bool, router *router.Router, server *cluster.Server, rpcClient cluster.RPCClient, rpcServer cluster.RPCServer, worker *worker.Worker, serviceDiscovery cluster.ServiceDiscovery, remoteService *service.RemoteService, handlerService *service.HandlerService, groups groups.GroupService, sessionPool session.SessionPool, metricsReporters []metrics.Reporter, config config.PitayaConfig, ) *App
NewApp is the base constructor for a pitaya app instance
func (*App) AddRoute ¶
func (app *App) AddRoute( serverType string, routingFunction router.RoutingFunc, ) error
AddRoute adds a routing function to a server type
func (*App) Documentation ¶
Documentation returns handler and remotes documentacion
func (*App) GetDieChan ¶
GetDieChan gets the channel that the app sinalizes when its going to die
func (*App) GetMetricsReporters ¶
GetMetricsReporters gets registered metrics reporters
func (*App) GetModule ¶
func (app *App) GetModule(name string) (interfaces.Module, error)
GetModule gets a module with a name
func (*App) GetServerByID ¶
GetServerByID returns the server with the specified id
func (*App) GetServerID ¶
GetServerID returns the generated server id
func (*App) GetServersByType ¶
GetServersByType get all servers of type
func (*App) GetSessionFromCtx ¶
GetSessionFromCtx retrieves a session from a given context
func (*App) GroupAddMember ¶
GroupAddMember adds UID to group
func (*App) GroupBroadcast ¶
func (app *App) GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error
GroupBroadcast pushes the message to all members inside group
func (*App) GroupContainsMember ¶
GroupContainsMember checks whether an UID is contained in group or not
func (*App) GroupCountMembers ¶
GroupCountMembers get current member amount in group
func (*App) GroupCreate ¶
GroupCreate creates a group
func (*App) GroupCreateWithTTL ¶
func (app *App) GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error
GroupCreateWithTTL creates a group with given TTL
func (*App) GroupDelete ¶
GroupDelete deletes whole group, including UIDs and base group
func (*App) GroupMembers ¶
GroupMembers returns all member's UIDs
func (*App) GroupRemoveAll ¶
GroupRemoveAll clears all UIDs
func (*App) GroupRemoveMember ¶
GroupRemoveMember removes specified UID from group
func (*App) GroupRenewTTL ¶
GroupRenewTTL renews group with the initial TTL
func (*App) IsRunning ¶
IsRunning indicates if the Pitaya app has been initialized. Note: This doesn't cover acceptors, only the pitaya internal registration and modules initialization.
func (*App) RPC ¶
func (app *App) RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error
RPC calls a method in a different server
func (*App) RPCTo ¶
func (app *App) RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, arg proto.Message) error
RPCTo send a rpc to a specific server
func (*App) RegisterModule ¶
func (app *App) RegisterModule(module interfaces.Module, name string) error
RegisterModule registers a module, by default it register after registered modules
func (*App) RegisterModuleAfter ¶
func (app *App) RegisterModuleAfter(module interfaces.Module, name string) error
RegisterModuleAfter registers a module after all registered modules
func (*App) RegisterModuleBefore ¶
func (app *App) RegisterModuleBefore(module interfaces.Module, name string) error
RegisterModuleBefore registers a module before all registered modules
func (*App) RegisterRPCJob ¶
RegisterRPCJob registers rpc job to execute jobs with retries
func (*App) RegisterRemote ¶
RegisterRemote register a remote component with options
func (*App) ReliableRPC ¶
func (app *App) ReliableRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error)
ReliableRPC enqueues RPC to worker so it's executed asynchronously Default enqueue options are used
func (*App) ReliableRPCWithOptions ¶
func (app *App) ReliableRPCWithOptions( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, opts *config.EnqueueOpts, ) (jid string, err error)
ReliableRPCWithOptions enqueues RPC to worker Receive worker options for this specific RPC
func (*App) SendKickToUsers ¶
SendKickToUsers sends kick to an user array
func (*App) SendPushToUsers ¶
func (app *App) SendPushToUsers(route string, v interface{}, uids []string, frontendType string) ([]string, error)
SendPushToUsers sends a message to the given list of users
func (*App) SetDictionary ¶
SetDictionary sets routes map
func (*App) SetHeartbeatTime ¶
SetHeartbeatTime sets the heartbeat time
func (*App) Shutdown ¶
func (app *App) Shutdown()
Shutdown send a signal to let 'pitaya' shutdown itself.
func (*App) StartWorker ¶
func (app *App) StartWorker()
StartWorker configures, starts and returns pitaya worker
type Builder ¶
type Builder struct { Config config.PitayaConfig DieChan chan bool PacketDecoder codec.PacketDecoder PacketEncoder codec.PacketEncoder MessageEncoder *message.MessagesEncoder Serializer serialize.Serializer Router *router.Router RPCClient cluster.RPCClient RPCServer cluster.RPCServer MetricsReporters []metrics.Reporter Server *cluster.Server ServerMode ServerMode ServiceDiscovery cluster.ServiceDiscovery Groups groups.GroupService SessionPool session.SessionPool Worker *worker.Worker RemoteHooks *pipeline.RemoteHooks HandlerHooks *pipeline.HandlerHooks // contains filtered or unexported fields }
Builder holds dependency instances for a pitaya App
func NewBuilder ¶
func NewBuilder(isFrontend bool, serverType string, serverMode ServerMode, serverMetadata map[string]string, config config.PitayaConfig, ) *Builder
NewBuilder return a builder instance with default dependency instances for a pitaya App, with configs explicitly defined
func NewBuilderWithConfigs ¶
func NewBuilderWithConfigs( isFrontend bool, serverType string, serverMode ServerMode, serverMetadata map[string]string, conf *config.Config, ) *Builder
NewBuilderWithConfigs return a builder instance with default dependency instances for a pitaya App with configs defined by a config file (config.Config) and default paths (see documentation).
func NewDefaultBuilder ¶
func NewDefaultBuilder(isFrontend bool, serverType string, serverMode ServerMode, serverMetadata map[string]string, pitayaConfig config.PitayaConfig) *Builder
NewDefaultBuilder return a builder instance with default dependency instances for a pitaya App, with default configs
func (*Builder) AddAcceptor ¶
AddAcceptor adds a new acceptor to app
func (*Builder) AddPostBuildHook ¶
AddPostBuildHook adds a post-build hook to the builder, a function receiving a Pitaya instance as parameter.
type Pitaya ¶
type Pitaya interface { GetDieChan() chan bool SetDebug(debug bool) SetHeartbeatTime(interval time.Duration) GetServerID() string GetMetricsReporters() []metrics.Reporter GetServer() *cluster.Server GetServerByID(id string) (*cluster.Server, error) GetServersByType(t string) (map[string]*cluster.Server, error) GetServers() []*cluster.Server GetSessionFromCtx(ctx context.Context) session.Session Start() SetDictionary(dict map[string]uint16) error AddRoute(serverType string, routingFunction router.RoutingFunc) error Shutdown() StartWorker() RegisterRPCJob(rpcJob worker.RPCJob) error Documentation(getPtrNames bool) (map[string]interface{}, error) IsRunning() bool RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, arg proto.Message) error ReliableRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error) ReliableRPCWithOptions( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, opts *config.EnqueueOpts, ) (jid string, err error) SendPushToUsers(route string, v interface{}, uids []string, frontendType string) ([]string, error) SendKickToUsers(uids []string, frontendType string) ([]string, error) GroupCreate(ctx context.Context, groupName string) error GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error GroupMembers(ctx context.Context, groupName string) ([]string, error) GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error GroupContainsMember(ctx context.Context, groupName, uid string) (bool, error) GroupAddMember(ctx context.Context, groupName, uid string) error GroupRemoveMember(ctx context.Context, groupName, uid string) error GroupRemoveAll(ctx context.Context, groupName string) error GroupCountMembers(ctx context.Context, groupName string) (int, error) GroupRenewTTL(ctx context.Context, groupName string) error GroupDelete(ctx context.Context, groupName string) error Register(c component.Component, options ...component.Option) RegisterRemote(c component.Component, options ...component.Option) RegisterModule(module interfaces.Module, name string) error RegisterModuleAfter(module interfaces.Module, name string) error RegisterModuleBefore(module interfaces.Module, name string) error GetModule(name string) (interfaces.Module, error) }
Pitaya App interface
var DefaultApp Pitaya
func NewDefaultApp ¶
func NewDefaultApp(isFrontend bool, serverType string, serverMode ServerMode, serverMetadata map[string]string, config config.PitayaConfig) Pitaya
NewDefaultApp returns a default pitaya app instance
type PitayaBuilder ¶
type PitayaBuilder interface { // AddPostBuildHook adds a post-build hook to the builder, a function receiving a Pitaya instance as parameter. AddPostBuildHook(hook func(app Pitaya)) Build() Pitaya }
PitayaBuilder Builder interface
type ServerMode ¶
type ServerMode byte
ServerMode represents a server mode
const ( // Cluster represents a server running with connection to other servers Cluster ServerMode // Standalone represents a server running without connection to other servers Standalone )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mock_cluster is a generated GoMock package.
|
Package mock_cluster is a generated GoMock package. |
conn
|
|
codec/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
message/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mock_protos is a generated GoMock package.
|
Package mock_protos is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |