Documentation ¶
Index ¶
- Variables
- func NewService(ctx context.Context, logger *zap.Logger, serverNode, serverRole string, ...) runtime.PeerService
- type BroadcastOption
- type Configuration
- type GrpcConfiguration
- type Handler
- type LocalSession
- func (s *LocalSession) Broadcast(m []byte, opts ...BroadcastOption) error
- func (s *LocalSession) Close()
- func (s *LocalSession) Consume()
- func (s *LocalSession) Context() context.Context
- func (s *LocalSession) ID() string
- func (s *LocalSession) Notification(ns []*api.Notification, opts ...BroadcastOption) error
- func (s *LocalSession) Role() string
- func (s *LocalSession) Send(msg *rtapi.NakamaPeer_Envelope) errordeprecated
- type MapOf
- func (m *MapOf[K, V]) Delete(key K)
- func (m *MapOf[K, V]) Load(key K) (value V, ok bool)
- func (m *MapOf[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *MapOf[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *MapOf[K, V]) Range(f func(key K, value V) bool)
- func (m *MapOf[K, V]) Store(key K, value V)
- type Server
- func (s *Server) Call(ctx context.Context, in *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error)
- func (s *Server) ServiceRegistry() *ServiceRegistry
- func (s *Server) SessionRegistry() *SessionRegistry
- func (s *Server) Start(etcd *etcd.ClientV3, h Handler, updated func(serviceRegistry *ServiceRegistry))
- func (s *Server) Stop()
- func (s *Server) Stream(stream rtapi.NakamaPeerApi_StreamServer) error
- type Service
- func (s *Service) Close() error
- func (s *Service) Do(msg *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error)
- func (s *Service) Metadata() *rtapi.NakamaPeer_NodeMeta
- func (s *Service) Name() string
- func (s *Service) Recv(fn func(service runtime.PeerService, msg *rtapi.NakamaPeer_Envelope)) error
- func (s *Service) Send(msg *rtapi.NakamaPeer_Envelope) error
- type ServiceRegistry
- func (s *ServiceRegistry) GetServiceByHashRing(role, key string) (runtime.PeerService, bool)
- func (s *ServiceRegistry) GetServices() map[string]map[string]runtime.PeerService
- func (s *ServiceRegistry) GetServicesByRole(role string) []runtime.PeerService
- func (s *ServiceRegistry) GetServicesWithNakama() []runtime.PeerService
- func (s *ServiceRegistry) Shutdown(timeout time.Duration)
- func (s *ServiceRegistry) Start(client *etcd.ClientV3, updateChan chan struct{})
- type Session
- type SessionRegistry
- func (r *SessionRegistry) Add(session Session)
- func (r *SessionRegistry) Count() int
- func (r *SessionRegistry) Get(sessionID string) (Session, bool)
- func (r *SessionRegistry) Range(fn func(Session) bool)
- func (r *SessionRegistry) RangeRole(role string, fn func(Session) bool)
- func (r *SessionRegistry) Remove(sessionID string)
Constants ¶
This section is empty.
Variables ¶
var ErrSessionQueueFull = errors.New("session outgoing queue full")
Functions ¶
func NewService ¶
Types ¶
type BroadcastOption ¶ added in v1.0.3
type BroadcastOption func(m *rtapi.NakamaPeer_Envelope)
func WithBroadcastContext ¶ added in v1.0.3
func WithBroadcastContext(md map[string]string) BroadcastOption
func WithBroadcastRecipient ¶ added in v1.0.3
func WithBroadcastRecipient(users ...string) BroadcastOption
type Configuration ¶
type Configuration struct { Name string `yaml:"name" json:"name" usage:"服务名称"` Role string `yaml:"role" json:"role" usage:"服务角色"` Grpc *GrpcConfiguration `yaml:"grpc" json:"grpc" usage:"grpc设置"` Etcd *etcd.Clientv3Config `yaml:"etcd" json:"etcd" usage:"etcd设置"` }
func NewConfiguration ¶
func NewConfiguration(name, role string) *Configuration
type GrpcConfiguration ¶
type GrpcConfiguration struct { Addr string `yaml:"addr" json:"addr" usage:"服务监听地址"` Port int `yaml:"port" json:"port" usage:"服务监听端口, 默认为0."` MinPort int `yaml:"min-port" json:"minPort" usage:"当端口为0时,将使用最小端口和最大端口进行随机"` MaxPort int `yaml:"max-port" json:"maxPort" usage:"当端口为0时,将使用最小端口和最大端口进行随机"` Domain string `yaml:"domain" json:"domain" usage:"本机服务地址"` GrpcX509Pem string `yaml:"grpc_x509_pem" json:"grpc_x509_pem" usage:"ssl pem"` GrpcX509Key string `yaml:"grpc_x509_key" json:"grpc_x509_key" usage:"ssl key"` GrpcToken string `yaml:"grpc_token" json:"grpc_token" usage:"token"` GrpcPoolMaxIdle int `yaml:"grpc_pool_max_idle" json:"grpc_pool_max_idle" usage:"Maximum number of idle connections in the grpc pool"` GrpcPoolMaxActive int `` /* 137-byte string literal not displayed */ GrpcPoolMaxConcurrentStreams int `` /* 221-byte string literal not displayed */ GrpcPoolReuse bool `` /* 218-byte string literal not displayed */ GrpcPoolMessageQueueSize int `yaml:"grpc_pool_message_queue_size" json:"grpc_pool_message_queue_size" usage:"grpc message queue size"` }
func NewGrpcConfiguration ¶
func NewGrpcConfiguration() *GrpcConfiguration
func (*GrpcConfiguration) Check ¶
func (c *GrpcConfiguration) Check(logger *zap.Logger)
type Handler ¶
type Handler interface { Call(ctx context.Context, in *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error) NotifyMsg(session Session, in *rtapi.NakamaPeer_Envelope) }
type LocalSession ¶
type LocalSession struct {
// contains filtered or unexported fields
}
func (*LocalSession) Broadcast ¶ added in v1.0.3
func (s *LocalSession) Broadcast(m []byte, opts ...BroadcastOption) error
Broadcast 广播消息会发向nakama, 后续消息要怎么处理需要在nakama组件中去监听和实现
func (*LocalSession) Close ¶
func (s *LocalSession) Close()
func (*LocalSession) Consume ¶
func (s *LocalSession) Consume()
func (*LocalSession) Context ¶
func (s *LocalSession) Context() context.Context
func (*LocalSession) ID ¶
func (s *LocalSession) ID() string
func (*LocalSession) Notification ¶ added in v1.0.3
func (s *LocalSession) Notification(ns []*api.Notification, opts ...BroadcastOption) error
Notification 通知消息将直接发向用户
func (*LocalSession) Role ¶
func (s *LocalSession) Role() string
func (*LocalSession) Send
deprecated
func (s *LocalSession) Send(msg *rtapi.NakamaPeer_Envelope) error
Deprecated: Use Notification or Broadcast
type MapOf ¶
type MapOf[K comparable, V any] struct { // contains filtered or unexported fields }
MapOf is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.
The MapOf type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.
The MapOf type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a MapOf may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.
The zero MapOf is empty and ready for use. A MapOf must not be copied after first use.
func (*MapOf[K, V]) Delete ¶
func (m *MapOf[K, V]) Delete(key K)
Delete deletes the value for a key.
func (*MapOf[K, V]) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*MapOf[K, V]) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*MapOf[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*MapOf[K, V]) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the MapOf's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
type Server ¶
type Server struct { rtapi.NakamaPeerApiServer // contains filtered or unexported fields }
func NewServer ¶
func NewServer(ctx context.Context, logger *zap.Logger, protojsonMarshaler *protojson.MarshalOptions, protojsonUnmarshaler *protojson.UnmarshalOptions, md map[string]string, c *Configuration) *Server
func (*Server) Call ¶
func (s *Server) Call(ctx context.Context, in *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error)
func (*Server) ServiceRegistry ¶
func (s *Server) ServiceRegistry() *ServiceRegistry
func (*Server) SessionRegistry ¶
func (s *Server) SessionRegistry() *SessionRegistry
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) Do ¶
func (s *Service) Do(msg *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error)
func (*Service) Metadata ¶
func (s *Service) Metadata() *rtapi.NakamaPeer_NodeMeta
func (*Service) Recv ¶
func (s *Service) Recv(fn func(service runtime.PeerService, msg *rtapi.NakamaPeer_Envelope)) error
type ServiceRegistry ¶
func NewServiceRegistry ¶
func NewServiceRegistry(ctx context.Context, logger *zap.Logger, meta *rtapi.NakamaPeer_NodeMeta, protojsonMarshaler *protojson.MarshalOptions, protojsonUnmarshaler *protojson.UnmarshalOptions, config *Configuration) *ServiceRegistry
func (*ServiceRegistry) GetServiceByHashRing ¶ added in v1.0.4
func (s *ServiceRegistry) GetServiceByHashRing(role, key string) (runtime.PeerService, bool)
func (*ServiceRegistry) GetServices ¶
func (s *ServiceRegistry) GetServices() map[string]map[string]runtime.PeerService
func (*ServiceRegistry) GetServicesByRole ¶
func (s *ServiceRegistry) GetServicesByRole(role string) []runtime.PeerService
func (*ServiceRegistry) GetServicesWithNakama ¶
func (s *ServiceRegistry) GetServicesWithNakama() []runtime.PeerService
func (*ServiceRegistry) Shutdown ¶
func (s *ServiceRegistry) Shutdown(timeout time.Duration)
func (*ServiceRegistry) Start ¶
func (s *ServiceRegistry) Start(client *etcd.ClientV3, updateChan chan struct{})
type Session ¶
type Session interface { ID() string Role() string Context() context.Context Consume() // Deprecated: Use Notification or Broadcast Send(msg *rtapi.NakamaPeer_Envelope) error Notification(ns []*api.Notification, opts ...BroadcastOption) error Broadcast(m []byte, opts ...BroadcastOption) error }
type SessionRegistry ¶
func NewSessionRegistry ¶
func NewSessionRegistry() *SessionRegistry
func (*SessionRegistry) Add ¶
func (r *SessionRegistry) Add(session Session)
func (*SessionRegistry) Count ¶
func (r *SessionRegistry) Count() int
func (*SessionRegistry) Range ¶
func (r *SessionRegistry) Range(fn func(Session) bool)
func (*SessionRegistry) RangeRole ¶
func (r *SessionRegistry) RangeRole(role string, fn func(Session) bool)
func (*SessionRegistry) Remove ¶
func (r *SessionRegistry) Remove(sessionID string)