repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
topfreegames/pitaya
agent/agent.go
Close
func (a *Agent) Close() error { a.closeMutex.Lock() defer a.closeMutex.Unlock() if a.GetStatus() == constants.StatusClosed { return constants.ErrCloseClosedSession } a.SetStatus(constants.StatusClosed) logger.Log.Debugf("Session closed, ID=%d, UID=%d, IP=%s", a.Session.ID(), a.Session.UID(), a.conn.RemoteAdd...
go
func (a *Agent) Close() error { a.closeMutex.Lock() defer a.closeMutex.Unlock() if a.GetStatus() == constants.StatusClosed { return constants.ErrCloseClosedSession } a.SetStatus(constants.StatusClosed) logger.Log.Debugf("Session closed, ID=%d, UID=%d, IP=%s", a.Session.ID(), a.Session.UID(), a.conn.RemoteAdd...
[ "func", "(", "a", "*", "Agent", ")", "Close", "(", ")", "error", "{", "a", ".", "closeMutex", ".", "Lock", "(", ")", "\n", "defer", "a", ".", "closeMutex", ".", "Unlock", "(", ")", "\n", "if", "a", ".", "GetStatus", "(", ")", "==", "constants", ...
// Close closes the agent, cleans inner state and closes low-level connection. // Any blocked Read or Write operations will be unblocked and return errors.
[ "Close", "closes", "the", "agent", "cleans", "inner", "state", "and", "closes", "low", "-", "level", "connection", ".", "Any", "blocked", "Read", "or", "Write", "operations", "will", "be", "unblocked", "and", "return", "errors", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L197-L222
train
topfreegames/pitaya
agent/agent.go
String
func (a *Agent) String() string { return fmt.Sprintf("Remote=%s, LastTime=%d", a.conn.RemoteAddr().String(), a.lastAt) }
go
func (a *Agent) String() string { return fmt.Sprintf("Remote=%s, LastTime=%d", a.conn.RemoteAddr().String(), a.lastAt) }
[ "func", "(", "a", "*", "Agent", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "conn", ".", "RemoteAddr", "(", ")", ".", "String", "(", ")", ",", "a", ".", "lastAt", ")", "\n", "}" ]
// String, implementation for Stringer interface
[ "String", "implementation", "for", "Stringer", "interface" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L231-L233
train
topfreegames/pitaya
agent/agent.go
Kick
func (a *Agent) Kick(ctx context.Context) error { // packet encode p, err := a.encoder.Encode(packet.Kick, nil) if err != nil { return err } _, err = a.conn.Write(p) return err }
go
func (a *Agent) Kick(ctx context.Context) error { // packet encode p, err := a.encoder.Encode(packet.Kick, nil) if err != nil { return err } _, err = a.conn.Write(p) return err }
[ "func", "(", "a", "*", "Agent", ")", "Kick", "(", "ctx", "context", ".", "Context", ")", "error", "{", "// packet encode", "p", ",", "err", ":=", "a", ".", "encoder", ".", "Encode", "(", "packet", ".", "Kick", ",", "nil", ")", "\n", "if", "err", ...
// Kick sends a kick packet to a client
[ "Kick", "sends", "a", "kick", "packet", "to", "a", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L241-L249
train
topfreegames/pitaya
agent/agent.go
SetStatus
func (a *Agent) SetStatus(state int32) { atomic.StoreInt32(&a.state, state) }
go
func (a *Agent) SetStatus(state int32) { atomic.StoreInt32(&a.state, state) }
[ "func", "(", "a", "*", "Agent", ")", "SetStatus", "(", "state", "int32", ")", "{", "atomic", ".", "StoreInt32", "(", "&", "a", ".", "state", ",", "state", ")", "\n", "}" ]
// SetStatus sets the agent status
[ "SetStatus", "sets", "the", "agent", "status" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L257-L259
train
topfreegames/pitaya
agent/agent.go
Handle
func (a *Agent) Handle() { defer func() { a.Close() logger.Log.Debugf("Session handle goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() go a.write() go a.heartbeat() select { case <-a.chDie: // agent closed signal return } }
go
func (a *Agent) Handle() { defer func() { a.Close() logger.Log.Debugf("Session handle goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() go a.write() go a.heartbeat() select { case <-a.chDie: // agent closed signal return } }
[ "func", "(", "a", "*", "Agent", ")", "Handle", "(", ")", "{", "defer", "func", "(", ")", "{", "a", ".", "Close", "(", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "a", ".", "Session", ".", "ID", "(", ")", ",", "a", ...
// Handle handles the messages from and to a client
[ "Handle", "handles", "the", "messages", "from", "and", "to", "a", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L262-L274
train
topfreegames/pitaya
agent/agent.go
SendHandshakeResponse
func (a *Agent) SendHandshakeResponse() error { _, err := a.conn.Write(hrd) return err }
go
func (a *Agent) SendHandshakeResponse() error { _, err := a.conn.Write(hrd) return err }
[ "func", "(", "a", "*", "Agent", ")", "SendHandshakeResponse", "(", ")", "error", "{", "_", ",", "err", ":=", "a", ".", "conn", ".", "Write", "(", "hrd", ")", "\n", "return", "err", "\n", "}" ]
// SendHandshakeResponse sends a handshake response
[ "SendHandshakeResponse", "sends", "a", "handshake", "response" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L337-L340
train
topfreegames/pitaya
agent/agent.go
AnswerWithError
func (a *Agent) AnswerWithError(ctx context.Context, mid uint, err error) { if ctx != nil && err != nil { s := opentracing.SpanFromContext(ctx) if s != nil { tracing.LogError(s, err.Error()) } } p, e := util.GetErrorPayload(a.serializer, err) if e != nil { logger.Log.Errorf("error answering the user with...
go
func (a *Agent) AnswerWithError(ctx context.Context, mid uint, err error) { if ctx != nil && err != nil { s := opentracing.SpanFromContext(ctx) if s != nil { tracing.LogError(s, err.Error()) } } p, e := util.GetErrorPayload(a.serializer, err) if e != nil { logger.Log.Errorf("error answering the user with...
[ "func", "(", "a", "*", "Agent", ")", "AnswerWithError", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "err", "error", ")", "{", "if", "ctx", "!=", "nil", "&&", "err", "!=", "nil", "{", "s", ":=", "opentracing", ".", "SpanFromContext...
// AnswerWithError answers with an error
[ "AnswerWithError", "answers", "with", "an", "error" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L428-L444
train
topfreegames/pitaya
session/session.go
New
func New(entity NetworkEntity, frontend bool, UID ...string) *Session { s := &Session{ id: sessionIDSvc.sessionID(), entity: entity, data: make(map[string]interface{}), handshakeData: nil, lastTime: time.Now().Unix(), OnCloseCallbacks: []func(){}, IsFrontend...
go
func New(entity NetworkEntity, frontend bool, UID ...string) *Session { s := &Session{ id: sessionIDSvc.sessionID(), entity: entity, data: make(map[string]interface{}), handshakeData: nil, lastTime: time.Now().Unix(), OnCloseCallbacks: []func(){}, IsFrontend...
[ "func", "New", "(", "entity", "NetworkEntity", ",", "frontend", "bool", ",", "UID", "...", "string", ")", "*", "Session", "{", "s", ":=", "&", "Session", "{", "id", ":", "sessionIDSvc", ".", "sessionID", "(", ")", ",", "entity", ":", "entity", ",", "...
// New returns a new session instance // a NetworkEntity is a low-level network instance
[ "New", "returns", "a", "new", "session", "instance", "a", "NetworkEntity", "is", "a", "low", "-", "level", "network", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L114-L132
train
topfreegames/pitaya
session/session.go
GetSessionByUID
func GetSessionByUID(uid string) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByUID.Load(uid); ok { return val.(*Session) } return nil }
go
func GetSessionByUID(uid string) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByUID.Load(uid); ok { return val.(*Session) } return nil }
[ "func", "GetSessionByUID", "(", "uid", "string", ")", "*", "Session", "{", "// TODO: Block this operation in backend servers", "if", "val", ",", "ok", ":=", "sessionsByUID", ".", "Load", "(", "uid", ")", ";", "ok", "{", "return", "val", ".", "(", "*", "Sessi...
// GetSessionByUID return a session bound to an user id
[ "GetSessionByUID", "return", "a", "session", "bound", "to", "an", "user", "id" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L135-L141
train
topfreegames/pitaya
session/session.go
GetSessionByID
func GetSessionByID(id int64) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByID.Load(id); ok { return val.(*Session) } return nil }
go
func GetSessionByID(id int64) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByID.Load(id); ok { return val.(*Session) } return nil }
[ "func", "GetSessionByID", "(", "id", "int64", ")", "*", "Session", "{", "// TODO: Block this operation in backend servers", "if", "val", ",", "ok", ":=", "sessionsByID", ".", "Load", "(", "id", ")", ";", "ok", "{", "return", "val", ".", "(", "*", "Session", ...
// GetSessionByID return a session bound to a frontend server id
[ "GetSessionByID", "return", "a", "session", "bound", "to", "a", "frontend", "server", "id" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L144-L150
train
topfreegames/pitaya
session/session.go
OnSessionBind
func OnSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range sessionBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } sessionBindCallbacks = append...
go
func OnSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range sessionBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } sessionBindCallbacks = append...
[ "func", "OnSessionBind", "(", "f", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "Session", ")", "error", ")", "{", "// Prevents the same function to be added twice in onSessionBind", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\n", ...
// OnSessionBind adds a method to be called when a session is bound // same function cannot be added twice!
[ "OnSessionBind", "adds", "a", "method", "to", "be", "called", "when", "a", "session", "is", "bound", "same", "function", "cannot", "be", "added", "twice!" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L154-L164
train
topfreegames/pitaya
session/session.go
OnAfterSessionBind
func OnAfterSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range afterBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } afterBindCallbacks = appen...
go
func OnAfterSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range afterBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } afterBindCallbacks = appen...
[ "func", "OnAfterSessionBind", "(", "f", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "Session", ")", "error", ")", "{", "// Prevents the same function to be added twice in onSessionBind", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\...
// OnAfterSessionBind adds a method to be called when session is bound and after all sessionBind callbacks
[ "OnAfterSessionBind", "adds", "a", "method", "to", "be", "called", "when", "session", "is", "bound", "and", "after", "all", "sessionBind", "callbacks" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L167-L177
train
topfreegames/pitaya
session/session.go
OnSessionClose
func OnSessionClose(f func(s *Session)) { sf1 := reflect.ValueOf(f) for _, fun := range SessionCloseCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } SessionCloseCallbacks = append(SessionCloseCallbacks, f) }
go
func OnSessionClose(f func(s *Session)) { sf1 := reflect.ValueOf(f) for _, fun := range SessionCloseCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } SessionCloseCallbacks = append(SessionCloseCallbacks, f) }
[ "func", "OnSessionClose", "(", "f", "func", "(", "s", "*", "Session", ")", ")", "{", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\n", "for", "_", ",", "fun", ":=", "range", "SessionCloseCallbacks", "{", "sf2", ":=", "reflect", ".", "Value...
// OnSessionClose adds a method that will be called when every session closes
[ "OnSessionClose", "adds", "a", "method", "that", "will", "be", "called", "when", "every", "session", "closes" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L180-L189
train
topfreegames/pitaya
session/session.go
Push
func (s *Session) Push(route string, v interface{}) error { return s.entity.Push(route, v) }
go
func (s *Session) Push(route string, v interface{}) error { return s.entity.Push(route, v) }
[ "func", "(", "s", "*", "Session", ")", "Push", "(", "route", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "s", ".", "entity", ".", "Push", "(", "route", ",", "v", ")", "\n", "}" ]
// Push message to client
[ "Push", "message", "to", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L202-L204
train
topfreegames/pitaya
session/session.go
ResponseMID
func (s *Session) ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error { return s.entity.ResponseMID(ctx, mid, v, err...) }
go
func (s *Session) ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error { return s.entity.ResponseMID(ctx, mid, v, err...) }
[ "func", "(", "s", "*", "Session", ")", "ResponseMID", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "v", "interface", "{", "}", ",", "err", "...", "bool", ")", "error", "{", "return", "s", ".", "entity", ".", "ResponseMID", "(", "...
// ResponseMID responses message to client, mid is // request message ID
[ "ResponseMID", "responses", "message", "to", "client", "mid", "is", "request", "message", "ID" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L208-L210
train
topfreegames/pitaya
session/session.go
GetData
func (s *Session) GetData() map[string]interface{} { s.RLock() defer s.RUnlock() return s.data }
go
func (s *Session) GetData() map[string]interface{} { s.RLock() defer s.RUnlock() return s.data }
[ "func", "(", "s", "*", "Session", ")", "GetData", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "return", "s", ".", "data", "\n", "}" ]
// GetData gets the data
[ "GetData", "gets", "the", "data" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L223-L228
train
topfreegames/pitaya
session/session.go
SetData
func (s *Session) SetData(data map[string]interface{}) error { s.Lock() defer s.Unlock() s.data = data return s.updateEncodedData() }
go
func (s *Session) SetData(data map[string]interface{}) error { s.Lock() defer s.Unlock() s.data = data return s.updateEncodedData() }
[ "func", "(", "s", "*", "Session", ")", "SetData", "(", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "data", "=", "data", ...
// SetData sets the whole session data
[ "SetData", "sets", "the", "whole", "session", "data" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L231-L237
train
topfreegames/pitaya
session/session.go
SetDataEncoded
func (s *Session) SetDataEncoded(encodedData []byte) error { if len(encodedData) == 0 { return nil } var data map[string]interface{} err := json.Unmarshal(encodedData, &data) if err != nil { return err } return s.SetData(data) }
go
func (s *Session) SetDataEncoded(encodedData []byte) error { if len(encodedData) == 0 { return nil } var data map[string]interface{} err := json.Unmarshal(encodedData, &data) if err != nil { return err } return s.SetData(data) }
[ "func", "(", "s", "*", "Session", ")", "SetDataEncoded", "(", "encodedData", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "encodedData", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "var", "data", "map", "[", "string", "]", "int...
// SetDataEncoded sets the whole session data from an encoded value
[ "SetDataEncoded", "sets", "the", "whole", "session", "data", "from", "an", "encoded", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L245-L255
train
topfreegames/pitaya
session/session.go
SetFrontendData
func (s *Session) SetFrontendData(frontendID string, frontendSessionID int64) { s.frontendID = frontendID s.frontendSessionID = frontendSessionID }
go
func (s *Session) SetFrontendData(frontendID string, frontendSessionID int64) { s.frontendID = frontendID s.frontendSessionID = frontendSessionID }
[ "func", "(", "s", "*", "Session", ")", "SetFrontendData", "(", "frontendID", "string", ",", "frontendSessionID", "int64", ")", "{", "s", ".", "frontendID", "=", "frontendID", "\n", "s", ".", "frontendSessionID", "=", "frontendSessionID", "\n", "}" ]
// SetFrontendData sets frontend id and session id
[ "SetFrontendData", "sets", "frontend", "id", "and", "session", "id" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L258-L261
train
topfreegames/pitaya
session/session.go
Bind
func (s *Session) Bind(ctx context.Context, uid string) error { if uid == "" { return constants.ErrIllegalUID } if s.UID() != "" { return constants.ErrSessionAlreadyBound } s.uid = uid for _, cb := range sessionBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } for _,...
go
func (s *Session) Bind(ctx context.Context, uid string) error { if uid == "" { return constants.ErrIllegalUID } if s.UID() != "" { return constants.ErrSessionAlreadyBound } s.uid = uid for _, cb := range sessionBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } for _,...
[ "func", "(", "s", "*", "Session", ")", "Bind", "(", "ctx", "context", ".", "Context", ",", "uid", "string", ")", "error", "{", "if", "uid", "==", "\"", "\"", "{", "return", "constants", ".", "ErrIllegalUID", "\n", "}", "\n\n", "if", "s", ".", "UID"...
// Bind bind UID to current session
[ "Bind", "bind", "UID", "to", "current", "session" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L264-L304
train
topfreegames/pitaya
session/session.go
OnClose
func (s *Session) OnClose(c func()) error { if !s.IsFrontend { return constants.ErrOnCloseBackend } s.OnCloseCallbacks = append(s.OnCloseCallbacks, c) return nil }
go
func (s *Session) OnClose(c func()) error { if !s.IsFrontend { return constants.ErrOnCloseBackend } s.OnCloseCallbacks = append(s.OnCloseCallbacks, c) return nil }
[ "func", "(", "s", "*", "Session", ")", "OnClose", "(", "c", "func", "(", ")", ")", "error", "{", "if", "!", "s", ".", "IsFrontend", "{", "return", "constants", ".", "ErrOnCloseBackend", "\n", "}", "\n", "s", ".", "OnCloseCallbacks", "=", "append", "(...
// OnClose adds the function it receives to the callbacks that will be called // when the session is closed
[ "OnClose", "adds", "the", "function", "it", "receives", "to", "the", "callbacks", "that", "will", "be", "called", "when", "the", "session", "is", "closed" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L317-L323
train
topfreegames/pitaya
session/session.go
Close
func (s *Session) Close() { atomic.AddInt64(&SessionCount, -1) sessionsByID.Delete(s.ID()) sessionsByUID.Delete(s.UID()) // TODO: this logic should be moved to nats rpc server if s.IsFrontend && s.Subscriptions != nil && len(s.Subscriptions) > 0 { // if the user is bound to an userid and nats rpc server is being...
go
func (s *Session) Close() { atomic.AddInt64(&SessionCount, -1) sessionsByID.Delete(s.ID()) sessionsByUID.Delete(s.UID()) // TODO: this logic should be moved to nats rpc server if s.IsFrontend && s.Subscriptions != nil && len(s.Subscriptions) > 0 { // if the user is bound to an userid and nats rpc server is being...
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "{", "atomic", ".", "AddInt64", "(", "&", "SessionCount", ",", "-", "1", ")", "\n", "sessionsByID", ".", "Delete", "(", "s", ".", "ID", "(", ")", ")", "\n", "sessionsByUID", ".", "Delete", ...
// Close terminates current session, session related data will not be released, // all related data should be cleared explicitly in Session closed callback
[ "Close", "terminates", "current", "session", "session", "related", "data", "will", "not", "be", "released", "all", "related", "data", "should", "be", "cleared", "explicitly", "in", "Session", "closed", "callback" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L327-L344
train
topfreegames/pitaya
session/session.go
Remove
func (s *Session) Remove(key string) error { s.Lock() defer s.Unlock() delete(s.data, key) return s.updateEncodedData() }
go
func (s *Session) Remove(key string) error { s.Lock() defer s.Unlock() delete(s.data, key) return s.updateEncodedData() }
[ "func", "(", "s", "*", "Session", ")", "Remove", "(", "key", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "s", ...
// Remove delete data associated with the key from session storage
[ "Remove", "delete", "data", "associated", "with", "the", "key", "from", "session", "storage" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L352-L358
train
topfreegames/pitaya
session/session.go
HasKey
func (s *Session) HasKey(key string) bool { s.RLock() defer s.RUnlock() _, has := s.data[key] return has }
go
func (s *Session) HasKey(key string) bool { s.RLock() defer s.RUnlock() _, has := s.data[key] return has }
[ "func", "(", "s", "*", "Session", ")", "HasKey", "(", "key", "string", ")", "bool", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "_", ",", "has", ":=", "s", ".", "data", "[", "key", "]", "\n", "retur...
// HasKey decides whether a key has associated value
[ "HasKey", "decides", "whether", "a", "key", "has", "associated", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L370-L376
train
topfreegames/pitaya
session/session.go
Get
func (s *Session) Get(key string) interface{} { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return nil } return v }
go
func (s *Session) Get(key string) interface{} { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return nil } return v }
[ "func", "(", "s", "*", "Session", ")", "Get", "(", "key", "string", ")", "interface", "{", "}", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", ...
// Get returns a key value
[ "Get", "returns", "a", "key", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L379-L388
train
topfreegames/pitaya
session/session.go
Int
func (s *Session) Int(key string) int { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int) if !ok { return 0 } return value }
go
func (s *Session) Int(key string) int { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Int", "(", "key", "string", ")", "int", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", "!"...
// Int returns the value associated with the key as a int.
[ "Int", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "int", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L391-L405
train
topfreegames/pitaya
session/session.go
Int8
func (s *Session) Int8(key string) int8 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int8) if !ok { return 0 } return value }
go
func (s *Session) Int8(key string) int8 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int8) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Int8", "(", "key", "string", ")", "int8", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", "...
// Int8 returns the value associated with the key as a int8.
[ "Int8", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "int8", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L408-L422
train
topfreegames/pitaya
session/session.go
Int16
func (s *Session) Int16(key string) int16 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int16) if !ok { return 0 } return value }
go
func (s *Session) Int16(key string) int16 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int16) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Int16", "(", "key", "string", ")", "int16", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", ...
// Int16 returns the value associated with the key as a int16.
[ "Int16", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "int16", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L425-L439
train
topfreegames/pitaya
session/session.go
Int32
func (s *Session) Int32(key string) int32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int32) if !ok { return 0 } return value }
go
func (s *Session) Int32(key string) int32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int32) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Int32", "(", "key", "string", ")", "int32", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", ...
// Int32 returns the value associated with the key as a int32.
[ "Int32", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "int32", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L442-L456
train
topfreegames/pitaya
session/session.go
Int64
func (s *Session) Int64(key string) int64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int64) if !ok { return 0 } return value }
go
func (s *Session) Int64(key string) int64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(int64) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Int64", "(", "key", "string", ")", "int64", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", ...
// Int64 returns the value associated with the key as a int64.
[ "Int64", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "int64", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L459-L473
train
topfreegames/pitaya
session/session.go
Uint
func (s *Session) Uint(key string) uint { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint) if !ok { return 0 } return value }
go
func (s *Session) Uint(key string) uint { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Uint", "(", "key", "string", ")", "uint", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", "...
// Uint returns the value associated with the key as a uint.
[ "Uint", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "uint", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L476-L490
train
topfreegames/pitaya
session/session.go
Uint8
func (s *Session) Uint8(key string) uint8 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint8) if !ok { return 0 } return value }
go
func (s *Session) Uint8(key string) uint8 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint8) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Uint8", "(", "key", "string", ")", "uint8", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if", ...
// Uint8 returns the value associated with the key as a uint8.
[ "Uint8", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "uint8", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L493-L507
train
topfreegames/pitaya
session/session.go
Uint16
func (s *Session) Uint16(key string) uint16 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint16) if !ok { return 0 } return value }
go
func (s *Session) Uint16(key string) uint16 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint16) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Uint16", "(", "key", "string", ")", "uint16", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if",...
// Uint16 returns the value associated with the key as a uint16.
[ "Uint16", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "uint16", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L510-L524
train
topfreegames/pitaya
session/session.go
Uint32
func (s *Session) Uint32(key string) uint32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint32) if !ok { return 0 } return value }
go
func (s *Session) Uint32(key string) uint32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint32) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Uint32", "(", "key", "string", ")", "uint32", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if",...
// Uint32 returns the value associated with the key as a uint32.
[ "Uint32", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "uint32", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L527-L541
train
topfreegames/pitaya
session/session.go
Uint64
func (s *Session) Uint64(key string) uint64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint64) if !ok { return 0 } return value }
go
func (s *Session) Uint64(key string) uint64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(uint64) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Uint64", "(", "key", "string", ")", "uint64", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if",...
// Uint64 returns the value associated with the key as a uint64.
[ "Uint64", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "uint64", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L544-L558
train
topfreegames/pitaya
session/session.go
Float32
func (s *Session) Float32(key string) float32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(float32) if !ok { return 0 } return value }
go
func (s *Session) Float32(key string) float32 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(float32) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Float32", "(", "key", "string", ")", "float32", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if...
// Float32 returns the value associated with the key as a float32.
[ "Float32", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "float32", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L561-L575
train
topfreegames/pitaya
session/session.go
Float64
func (s *Session) Float64(key string) float64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(float64) if !ok { return 0 } return value }
go
func (s *Session) Float64(key string) float64 { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return 0 } value, ok := v.(float64) if !ok { return 0 } return value }
[ "func", "(", "s", "*", "Session", ")", "Float64", "(", "key", "string", ")", "float64", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if...
// Float64 returns the value associated with the key as a float64.
[ "Float64", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "float64", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L578-L592
train
topfreegames/pitaya
session/session.go
String
func (s *Session) String(key string) string { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return "" } value, ok := v.(string) if !ok { return "" } return value }
go
func (s *Session) String(key string) string { s.RLock() defer s.RUnlock() v, ok := s.data[key] if !ok { return "" } value, ok := v.(string) if !ok { return "" } return value }
[ "func", "(", "s", "*", "Session", ")", "String", "(", "key", "string", ")", "string", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "s", ".", "data", "[", "key", "]", "\n", "if",...
// String returns the value associated with the key as a string.
[ "String", "returns", "the", "value", "associated", "with", "the", "key", "as", "a", "string", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L595-L609
train
topfreegames/pitaya
session/session.go
PushToFront
func (s *Session) PushToFront(ctx context.Context) error { if s.IsFrontend { return constants.ErrFrontSessionCantPushToFront } return s.sendRequestToFront(ctx, constants.SessionPushRoute, true) }
go
func (s *Session) PushToFront(ctx context.Context) error { if s.IsFrontend { return constants.ErrFrontSessionCantPushToFront } return s.sendRequestToFront(ctx, constants.SessionPushRoute, true) }
[ "func", "(", "s", "*", "Session", ")", "PushToFront", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "s", ".", "IsFrontend", "{", "return", "constants", ".", "ErrFrontSessionCantPushToFront", "\n", "}", "\n", "return", "s", ".", "sendReque...
// PushToFront updates the session in the frontend
[ "PushToFront", "updates", "the", "session", "in", "the", "frontend" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L624-L629
train
topfreegames/pitaya
session/session.go
Clear
func (s *Session) Clear() { s.Lock() defer s.Unlock() s.uid = "" s.data = map[string]interface{}{} s.updateEncodedData() }
go
func (s *Session) Clear() { s.Lock() defer s.Unlock() s.uid = "" s.data = map[string]interface{}{} s.updateEncodedData() }
[ "func", "(", "s", "*", "Session", ")", "Clear", "(", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "uid", "=", "\"", "\"", "\n", "s", ".", "data", "=", "map", "[", "string", "]", "inter...
// Clear releases all data related to current session
[ "Clear", "releases", "all", "data", "related", "to", "current", "session" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L632-L639
train
topfreegames/pitaya
session/session.go
SetHandshakeData
func (s *Session) SetHandshakeData(data *HandshakeData) { s.Lock() defer s.Unlock() s.handshakeData = data }
go
func (s *Session) SetHandshakeData(data *HandshakeData) { s.Lock() defer s.Unlock() s.handshakeData = data }
[ "func", "(", "s", "*", "Session", ")", "SetHandshakeData", "(", "data", "*", "HandshakeData", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "handshakeData", "=", "data", "\n", "}" ]
// SetHandshakeData sets the handshake data received by the client.
[ "SetHandshakeData", "sets", "the", "handshake", "data", "received", "by", "the", "client", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L642-L647
train
topfreegames/pitaya
serialize/protobuf/protobuf.go
Marshal
func (s *Serializer) Marshal(v interface{}) ([]byte, error) { pb, ok := v.(proto.Message) if !ok { return nil, constants.ErrWrongValueType } return proto.Marshal(pb) }
go
func (s *Serializer) Marshal(v interface{}) ([]byte, error) { pb, ok := v.(proto.Message) if !ok { return nil, constants.ErrWrongValueType } return proto.Marshal(pb) }
[ "func", "(", "s", "*", "Serializer", ")", "Marshal", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "pb", ",", "ok", ":=", "v", ".", "(", "proto", ".", "Message", ")", "\n", "if", "!", "ok", "{", "return"...
// Marshal returns the protobuf encoding of v.
[ "Marshal", "returns", "the", "protobuf", "encoding", "of", "v", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/protobuf/protobuf.go#L37-L43
train
topfreegames/pitaya
serialize/protobuf/protobuf.go
Unmarshal
func (s *Serializer) Unmarshal(data []byte, v interface{}) error { pb, ok := v.(proto.Message) if !ok { return constants.ErrWrongValueType } return proto.Unmarshal(data, pb) }
go
func (s *Serializer) Unmarshal(data []byte, v interface{}) error { pb, ok := v.(proto.Message) if !ok { return constants.ErrWrongValueType } return proto.Unmarshal(data, pb) }
[ "func", "(", "s", "*", "Serializer", ")", "Unmarshal", "(", "data", "[", "]", "byte", ",", "v", "interface", "{", "}", ")", "error", "{", "pb", ",", "ok", ":=", "v", ".", "(", "proto", ".", "Message", ")", "\n", "if", "!", "ok", "{", "return", ...
// Unmarshal parses the protobuf-encoded data and stores the result // in the value pointed to by v.
[ "Unmarshal", "parses", "the", "protobuf", "-", "encoded", "data", "and", "stores", "the", "result", "in", "the", "value", "pointed", "to", "by", "v", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/protobuf/protobuf.go#L47-L53
train
topfreegames/pitaya
timer/timer.go
NewTimer
func NewTimer(fn Func, interval time.Duration, counter int) *Timer { id := atomic.AddInt64(&Manager.incrementID, 1) t := &Timer{ ID: id, fn: fn, createAt: time.Now().UnixNano(), interval: interval, elapse: int64(interval), // first execution will be after interval counter: counter, } // ...
go
func NewTimer(fn Func, interval time.Duration, counter int) *Timer { id := atomic.AddInt64(&Manager.incrementID, 1) t := &Timer{ ID: id, fn: fn, createAt: time.Now().UnixNano(), interval: interval, elapse: int64(interval), // first execution will be after interval counter: counter, } // ...
[ "func", "NewTimer", "(", "fn", "Func", ",", "interval", "time", ".", "Duration", ",", "counter", "int", ")", "*", "Timer", "{", "id", ":=", "atomic", ".", "AddInt64", "(", "&", "Manager", ".", "incrementID", ",", "1", ")", "\n", "t", ":=", "&", "Ti...
// NewTimer creates a cron job
[ "NewTimer", "creates", "a", "cron", "job" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer/timer.go#L97-L111
train
topfreegames/pitaya
timer/timer.go
Stop
func (t *Timer) Stop() { if atomic.LoadInt32(&t.closed) > 0 { return } // guarantee that logic is not blocked if len(Manager.ChClosingTimer) < timerBacklog { Manager.ChClosingTimer <- t.ID atomic.StoreInt32(&t.closed, 1) } else { t.counter = 0 // automatically closed in next Cron } }
go
func (t *Timer) Stop() { if atomic.LoadInt32(&t.closed) > 0 { return } // guarantee that logic is not blocked if len(Manager.ChClosingTimer) < timerBacklog { Manager.ChClosingTimer <- t.ID atomic.StoreInt32(&t.closed, 1) } else { t.counter = 0 // automatically closed in next Cron } }
[ "func", "(", "t", "*", "Timer", ")", "Stop", "(", ")", "{", "if", "atomic", ".", "LoadInt32", "(", "&", "t", ".", "closed", ")", ">", "0", "{", "return", "\n", "}", "\n\n", "// guarantee that logic is not blocked", "if", "len", "(", "Manager", ".", "...
// Stop turns off a timer. After Stop, fn will not be called forever
[ "Stop", "turns", "off", "a", "timer", ".", "After", "Stop", "fn", "will", "not", "be", "called", "forever" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer/timer.go#L119-L131
train
topfreegames/pitaya
timer/timer.go
pexec
func pexec(id int64, fn Func) { defer func() { if err := recover(); err != nil { logger.Log.Errorf("Call timer function error, TimerID=%d, Error=%v", id, err) } }() fn() }
go
func pexec(id int64, fn Func) { defer func() { if err := recover(); err != nil { logger.Log.Errorf("Call timer function error, TimerID=%d, Error=%v", id, err) } }() fn() }
[ "func", "pexec", "(", "id", "int64", ",", "fn", "Func", ")", "{", "defer", "func", "(", ")", "{", "if", "err", ":=", "recover", "(", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err...
// execute job function with protection
[ "execute", "job", "function", "with", "protection" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer/timer.go#L134-L142
train
topfreegames/pitaya
conn/codec/mocks/packet_encoder.go
NewMockPacketEncoder
func NewMockPacketEncoder(ctrl *gomock.Controller) *MockPacketEncoder { mock := &MockPacketEncoder{ctrl: ctrl} mock.recorder = &MockPacketEncoderMockRecorder{mock} return mock }
go
func NewMockPacketEncoder(ctrl *gomock.Controller) *MockPacketEncoder { mock := &MockPacketEncoder{ctrl: ctrl} mock.recorder = &MockPacketEncoderMockRecorder{mock} return mock }
[ "func", "NewMockPacketEncoder", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockPacketEncoder", "{", "mock", ":=", "&", "MockPacketEncoder", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockPacketEncoderMockRecorder", ...
// NewMockPacketEncoder creates a new mock instance
[ "NewMockPacketEncoder", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/codec/mocks/packet_encoder.go#L25-L29
train
topfreegames/pitaya
cluster/server.go
AsJSONString
func (s *Server) AsJSONString() string { str, err := json.Marshal(s) if err != nil { logger.Log.Errorf("error getting server as json: %s", err.Error()) return "" } return string(str) }
go
func (s *Server) AsJSONString() string { str, err := json.Marshal(s) if err != nil { logger.Log.Errorf("error getting server as json: %s", err.Error()) return "" } return string(str) }
[ "func", "(", "s", "*", "Server", ")", "AsJSONString", "(", ")", "string", "{", "str", ",", "err", ":=", "json", ".", "Marshal", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err"...
// AsJSONString returns the server as a json string
[ "AsJSONString", "returns", "the", "server", "as", "a", "json", "string" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/server.go#L59-L66
train
topfreegames/pitaya
rpc.go
RPC
func RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error { return doSendRPC(ctx, "", routeStr, reply, arg) }
go
func RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error { return doSendRPC(ctx, "", routeStr, reply, arg) }
[ "func", "RPC", "(", "ctx", "context", ".", "Context", ",", "routeStr", "string", ",", "reply", "proto", ".", "Message", ",", "arg", "proto", ".", "Message", ")", "error", "{", "return", "doSendRPC", "(", "ctx", ",", "\"", "\"", ",", "routeStr", ",", ...
// RPC calls a method in a different server
[ "RPC", "calls", "a", "method", "in", "a", "different", "server" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/rpc.go#L34-L36
train
topfreegames/pitaya
rpc.go
RPCTo
func RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, arg proto.Message) error { return doSendRPC(ctx, serverID, routeStr, reply, arg) }
go
func RPCTo(ctx context.Context, serverID, routeStr string, reply proto.Message, arg proto.Message) error { return doSendRPC(ctx, serverID, routeStr, reply, arg) }
[ "func", "RPCTo", "(", "ctx", "context", ".", "Context", ",", "serverID", ",", "routeStr", "string", ",", "reply", "proto", ".", "Message", ",", "arg", "proto", ".", "Message", ")", "error", "{", "return", "doSendRPC", "(", "ctx", ",", "serverID", ",", ...
// RPCTo send a rpc to a specific server
[ "RPCTo", "send", "a", "rpc", "to", "a", "specific", "server" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/rpc.go#L39-L41
train
topfreegames/pitaya
rpc.go
ReliableRPC
func ReliableRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error) { return app.worker.EnqueueRPC(routeStr, metadata, reply, arg) }
go
func ReliableRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error) { return app.worker.EnqueueRPC(routeStr, metadata, reply, arg) }
[ "func", "ReliableRPC", "(", "routeStr", "string", ",", "metadata", "map", "[", "string", "]", "interface", "{", "}", ",", "reply", ",", "arg", "proto", ".", "Message", ",", ")", "(", "jid", "string", ",", "err", "error", ")", "{", "return", "app", "....
// ReliableRPC enqueues RPC to worker so it's executed asynchronously // Default enqueue options are used
[ "ReliableRPC", "enqueues", "RPC", "to", "worker", "so", "it", "s", "executed", "asynchronously", "Default", "enqueue", "options", "are", "used" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/rpc.go#L45-L51
train
topfreegames/pitaya
rpc.go
ReliableRPCWithOptions
func ReliableRPCWithOptions( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, opts *worker.EnqueueOpts, ) (jid string, err error) { return app.worker.EnqueueRPCWithOptions(routeStr, metadata, reply, arg, opts) }
go
func ReliableRPCWithOptions( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, opts *worker.EnqueueOpts, ) (jid string, err error) { return app.worker.EnqueueRPCWithOptions(routeStr, metadata, reply, arg, opts) }
[ "func", "ReliableRPCWithOptions", "(", "routeStr", "string", ",", "metadata", "map", "[", "string", "]", "interface", "{", "}", ",", "reply", ",", "arg", "proto", ".", "Message", ",", "opts", "*", "worker", ".", "EnqueueOpts", ",", ")", "(", "jid", "stri...
// ReliableRPCWithOptions enqueues RPC to worker // Receive worker options for this specific RPC
[ "ReliableRPCWithOptions", "enqueues", "RPC", "to", "worker", "Receive", "worker", "options", "for", "this", "specific", "RPC" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/rpc.go#L55-L62
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
NewGRPCClient
func NewGRPCClient( config *config.Config, server *Server, metricsReporters []metrics.Reporter, bindingStorage interfaces.BindingStorage, infoRetriever InfoRetriever, ) (*GRPCClient, error) { gs := &GRPCClient{ config: config, server: server, metricsReporters: metricsReporters, binding...
go
func NewGRPCClient( config *config.Config, server *Server, metricsReporters []metrics.Reporter, bindingStorage interfaces.BindingStorage, infoRetriever InfoRetriever, ) (*GRPCClient, error) { gs := &GRPCClient{ config: config, server: server, metricsReporters: metricsReporters, binding...
[ "func", "NewGRPCClient", "(", "config", "*", "config", ".", "Config", ",", "server", "*", "Server", ",", "metricsReporters", "[", "]", "metrics", ".", "Reporter", ",", "bindingStorage", "interfaces", ".", "BindingStorage", ",", "infoRetriever", "InfoRetriever", ...
// NewGRPCClient returns a new instance of GRPCClient
[ "NewGRPCClient", "returns", "a", "new", "instance", "of", "GRPCClient" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L58-L76
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
Call
func (gs *GRPCClient) Call(ctx context.Context, rpcType protos.RPCType, route *route.Route, session *session.Session, msg *message.Message, server *Server) (*protos.Response, error) { parent, err := tracing.ExtractSpan(ctx) if err != nil { logger.Log.Warnf("failed to retrieve parent span: %s", err.Error()) } tags...
go
func (gs *GRPCClient) Call(ctx context.Context, rpcType protos.RPCType, route *route.Route, session *session.Session, msg *message.Message, server *Server) (*protos.Response, error) { parent, err := tracing.ExtractSpan(ctx) if err != nil { logger.Log.Warnf("failed to retrieve parent span: %s", err.Error()) } tags...
[ "func", "(", "gs", "*", "GRPCClient", ")", "Call", "(", "ctx", "context", ".", "Context", ",", "rpcType", "protos", ".", "RPCType", ",", "route", "*", "route", ".", "Route", ",", "session", "*", "session", ".", "Session", ",", "msg", "*", "message", ...
// Call makes a RPC Call
[ "Call", "makes", "a", "RPC", "Call" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L89-L137
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
Send
func (gs *GRPCClient) Send(uid string, d []byte) error { return constants.ErrNotImplemented }
go
func (gs *GRPCClient) Send(uid string, d []byte) error { return constants.ErrNotImplemented }
[ "func", "(", "gs", "*", "GRPCClient", ")", "Send", "(", "uid", "string", ",", "d", "[", "]", "byte", ")", "error", "{", "return", "constants", ".", "ErrNotImplemented", "\n", "}" ]
// Send not implemented in grpc client
[ "Send", "not", "implemented", "in", "grpc", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L140-L142
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
BroadcastSessionBind
func (gs *GRPCClient) BroadcastSessionBind(uid string) error { if gs.bindingStorage == nil { return constants.ErrNoBindingStorageModule } fid, _ := gs.bindingStorage.GetUserFrontendID(uid, gs.server.Type) if fid != "" { if c, ok := gs.clientMap.Load(fid); ok { msg := &protos.BindMsg{ Uid: uid, Fid: g...
go
func (gs *GRPCClient) BroadcastSessionBind(uid string) error { if gs.bindingStorage == nil { return constants.ErrNoBindingStorageModule } fid, _ := gs.bindingStorage.GetUserFrontendID(uid, gs.server.Type) if fid != "" { if c, ok := gs.clientMap.Load(fid); ok { msg := &protos.BindMsg{ Uid: uid, Fid: g...
[ "func", "(", "gs", "*", "GRPCClient", ")", "BroadcastSessionBind", "(", "uid", "string", ")", "error", "{", "if", "gs", ".", "bindingStorage", "==", "nil", "{", "return", "constants", ".", "ErrNoBindingStorageModule", "\n", "}", "\n", "fid", ",", "_", ":="...
// BroadcastSessionBind sends the binding information to other servers that may be interested in this info
[ "BroadcastSessionBind", "sends", "the", "binding", "information", "to", "other", "servers", "that", "may", "be", "interested", "in", "this", "info" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L145-L163
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
SendKick
func (gs *GRPCClient) SendKick(userID string, serverType string, kick *protos.KickMsg) error { var svID string var err error if gs.bindingStorage == nil { return constants.ErrNoBindingStorageModule } svID, err = gs.bindingStorage.GetUserFrontendID(userID, serverType) if err != nil { return err } if c, ok...
go
func (gs *GRPCClient) SendKick(userID string, serverType string, kick *protos.KickMsg) error { var svID string var err error if gs.bindingStorage == nil { return constants.ErrNoBindingStorageModule } svID, err = gs.bindingStorage.GetUserFrontendID(userID, serverType) if err != nil { return err } if c, ok...
[ "func", "(", "gs", "*", "GRPCClient", ")", "SendKick", "(", "userID", "string", ",", "serverType", "string", ",", "kick", "*", "protos", ".", "KickMsg", ")", "error", "{", "var", "svID", "string", "\n", "var", "err", "error", "\n\n", "if", "gs", ".", ...
// SendKick sends a kick to an user
[ "SendKick", "sends", "a", "kick", "to", "an", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L166-L186
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
AddServer
func (gs *GRPCClient) AddServer(sv *Server) { var host, port, portKey string var ok bool host, portKey = gs.getServerHost(sv) if host == "" { logger.Log.Errorf("server %s has no grpcHost specified in metadata", sv.ID) return } if port, ok = sv.Metadata[portKey]; !ok { logger.Log.Errorf("server %s has no %...
go
func (gs *GRPCClient) AddServer(sv *Server) { var host, port, portKey string var ok bool host, portKey = gs.getServerHost(sv) if host == "" { logger.Log.Errorf("server %s has no grpcHost specified in metadata", sv.ID) return } if port, ok = sv.Metadata[portKey]; !ok { logger.Log.Errorf("server %s has no %...
[ "func", "(", "gs", "*", "GRPCClient", ")", "AddServer", "(", "sv", "*", "Server", ")", "{", "var", "host", ",", "port", ",", "portKey", "string", "\n", "var", "ok", "bool", "\n\n", "host", ",", "portKey", "=", "gs", ".", "getServerHost", "(", "sv", ...
// AddServer is called when a new server is discovered
[ "AddServer", "is", "called", "when", "a", "new", "server", "is", "discovered" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L214-L238
train
topfreegames/pitaya
cluster/grpc_rpc_client.go
RemoveServer
func (gs *GRPCClient) RemoveServer(sv *Server) { if _, ok := gs.clientMap.Load(sv.ID); ok { // TODO: do I need to disconnect client? gs.clientMap.Delete(sv.ID) logger.Log.Debugf("[grpc client] removed server %s", sv.ID) } }
go
func (gs *GRPCClient) RemoveServer(sv *Server) { if _, ok := gs.clientMap.Load(sv.ID); ok { // TODO: do I need to disconnect client? gs.clientMap.Delete(sv.ID) logger.Log.Debugf("[grpc client] removed server %s", sv.ID) } }
[ "func", "(", "gs", "*", "GRPCClient", ")", "RemoveServer", "(", "sv", "*", "Server", ")", "{", "if", "_", ",", "ok", ":=", "gs", ".", "clientMap", ".", "Load", "(", "sv", ".", "ID", ")", ";", "ok", "{", "// TODO: do I need to disconnect client?", "gs",...
// RemoveServer is called when a server is removed
[ "RemoveServer", "is", "called", "when", "a", "server", "is", "removed" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/grpc_rpc_client.go#L241-L247
train
topfreegames/pitaya
serialize/json/json.go
Unmarshal
func (s *Serializer) Unmarshal(data []byte, v interface{}) error { return json.Unmarshal(data, v) }
go
func (s *Serializer) Unmarshal(data []byte, v interface{}) error { return json.Unmarshal(data, v) }
[ "func", "(", "s", "*", "Serializer", ")", "Unmarshal", "(", "data", "[", "]", "byte", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "json", ".", "Unmarshal", "(", "data", ",", "v", ")", "\n", "}" ]
// Unmarshal parses the JSON-encoded data and stores the result // in the value pointed to by v.
[ "Unmarshal", "parses", "the", "JSON", "-", "encoded", "data", "and", "stores", "the", "result", "in", "the", "value", "pointed", "to", "by", "v", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/json/json.go#L42-L44
train
topfreegames/pitaya
examples/demo/pipeline/main.go
HandlerNoArg
func (g *MetagameServer) HandlerNoArg(ctx context.Context) (*HandlerNoArgResponse, error) { return &HandlerNoArgResponse{ Msg: "ok", }, nil }
go
func (g *MetagameServer) HandlerNoArg(ctx context.Context) (*HandlerNoArgResponse, error) { return &HandlerNoArgResponse{ Msg: "ok", }, nil }
[ "func", "(", "g", "*", "MetagameServer", ")", "HandlerNoArg", "(", "ctx", "context", ".", "Context", ")", "(", "*", "HandlerNoArgResponse", ",", "error", ")", "{", "return", "&", "HandlerNoArgResponse", "{", "Msg", ":", "\"", "\"", ",", "}", ",", "nil", ...
// HandlerNoArg is a simple handler that do not have any arguments
[ "HandlerNoArg", "is", "a", "simple", "handler", "that", "do", "not", "have", "any", "arguments" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/pipeline/main.go#L57-L61
train
topfreegames/pitaya
examples/demo/pipeline/main.go
simpleAfter
func (g *MetagameServer) simpleAfter(ctx context.Context, resp interface{}, err error) (interface{}, error) { logger := pitaya.GetDefaultLoggerFromCtx(ctx) logger.Infof("Simple After exec - response: %v , error: %v", resp, err) return resp, err }
go
func (g *MetagameServer) simpleAfter(ctx context.Context, resp interface{}, err error) (interface{}, error) { logger := pitaya.GetDefaultLoggerFromCtx(ctx) logger.Infof("Simple After exec - response: %v , error: %v", resp, err) return resp, err }
[ "func", "(", "g", "*", "MetagameServer", ")", "simpleAfter", "(", "ctx", "context", ".", "Context", ",", "resp", "interface", "{", "}", ",", "err", "error", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "logger", ":=", "pitaya", ".", "GetD...
// Simple example of an after pipeline. The 2nd argument is the handler response.
[ "Simple", "example", "of", "an", "after", "pipeline", ".", "The", "2nd", "argument", "is", "the", "handler", "response", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/pipeline/main.go#L84-L89
train
topfreegames/pitaya
component.go
Register
func Register(c component.Component, options ...component.Option) { handlerComp = append(handlerComp, regComp{c, options}) }
go
func Register(c component.Component, options ...component.Option) { handlerComp = append(handlerComp, regComp{c, options}) }
[ "func", "Register", "(", "c", "component", ".", "Component", ",", "options", "...", "component", ".", "Option", ")", "{", "handlerComp", "=", "append", "(", "handlerComp", ",", "regComp", "{", "c", ",", "options", "}", ")", "\n", "}" ]
// Register register a component with options
[ "Register", "register", "a", "component", "with", "options" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/component.go#L39-L41
train
topfreegames/pitaya
component.go
RegisterRemote
func RegisterRemote(c component.Component, options ...component.Option) { remoteComp = append(remoteComp, regComp{c, options}) }
go
func RegisterRemote(c component.Component, options ...component.Option) { remoteComp = append(remoteComp, regComp{c, options}) }
[ "func", "RegisterRemote", "(", "c", "component", ".", "Component", ",", "options", "...", "component", ".", "Option", ")", "{", "remoteComp", "=", "append", "(", "remoteComp", ",", "regComp", "{", "c", ",", "options", "}", ")", "\n", "}" ]
// RegisterRemote register a remote component with options
[ "RegisterRemote", "register", "a", "remote", "component", "with", "options" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/component.go#L44-L46
train
topfreegames/pitaya
cluster/nats_rpc_server.go
GetUserMessagesTopic
func GetUserMessagesTopic(uid string, svType string) string { return fmt.Sprintf("pitaya/%s/user/%s/push", svType, uid) }
go
func GetUserMessagesTopic(uid string, svType string) string { return fmt.Sprintf("pitaya/%s/user/%s/push", svType, uid) }
[ "func", "GetUserMessagesTopic", "(", "uid", "string", ",", "svType", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "svType", ",", "uid", ")", "\n", "}" ]
// GetUserMessagesTopic get the topic for user
[ "GetUserMessagesTopic", "get", "the", "topic", "for", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_server.go#L115-L117
train
topfreegames/pitaya
cluster/nats_rpc_server.go
GetUserKickTopic
func GetUserKickTopic(uid string, svType string) string { return fmt.Sprintf("pitaya/%s/user/%s/kick", svType, uid) }
go
func GetUserKickTopic(uid string, svType string) string { return fmt.Sprintf("pitaya/%s/user/%s/kick", svType, uid) }
[ "func", "GetUserKickTopic", "(", "uid", "string", ",", "svType", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "svType", ",", "uid", ")", "\n", "}" ]
// GetUserKickTopic get the topic for kicking an user
[ "GetUserKickTopic", "get", "the", "topic", "for", "kicking", "an", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_server.go#L120-L122
train
topfreegames/pitaya
cluster/nats_rpc_server.go
onSessionBind
func (ns *NatsRPCServer) onSessionBind(ctx context.Context, s *session.Session) error { if ns.server.Frontend { subu, err := ns.subscribeToUserMessages(s.UID(), ns.server.Type) if err != nil { return err } subk, err := ns.subscribeToUserKickChannel(s.UID(), ns.server.Type) if err != nil { return err ...
go
func (ns *NatsRPCServer) onSessionBind(ctx context.Context, s *session.Session) error { if ns.server.Frontend { subu, err := ns.subscribeToUserMessages(s.UID(), ns.server.Type) if err != nil { return err } subk, err := ns.subscribeToUserKickChannel(s.UID(), ns.server.Type) if err != nil { return err ...
[ "func", "(", "ns", "*", "NatsRPCServer", ")", "onSessionBind", "(", "ctx", "context", ".", "Context", ",", "s", "*", "session", ".", "Session", ")", "error", "{", "if", "ns", ".", "server", ".", "Frontend", "{", "subu", ",", "err", ":=", "ns", ".", ...
// onSessionBind should be called on each session bind
[ "onSessionBind", "should", "be", "called", "on", "each", "session", "bind" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_server.go#L130-L143
train
topfreegames/pitaya
cluster/nats_rpc_server.go
Init
func (ns *NatsRPCServer) Init() error { // TODO should we have concurrency here? it feels like we should go ns.handleMessages() conn, err := setupNatsConn(ns.connString, ns.appDieChan, nats.MaxReconnects(ns.maxReconnectionRetries)) if err != nil { return err } ns.conn = conn if ns.sub, err = ns.subscribe(getCh...
go
func (ns *NatsRPCServer) Init() error { // TODO should we have concurrency here? it feels like we should go ns.handleMessages() conn, err := setupNatsConn(ns.connString, ns.appDieChan, nats.MaxReconnects(ns.maxReconnectionRetries)) if err != nil { return err } ns.conn = conn if ns.sub, err = ns.subscribe(getCh...
[ "func", "(", "ns", "*", "NatsRPCServer", ")", "Init", "(", ")", "error", "{", "// TODO should we have concurrency here? it feels like we should", "go", "ns", ".", "handleMessages", "(", ")", "\n", "conn", ",", "err", ":=", "setupNatsConn", "(", "ns", ".", "connS...
// Init inits nats rpc server
[ "Init", "inits", "nats", "rpc", "server" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_server.go#L308-L337
train
topfreegames/pitaya
route/route.go
NewRoute
func NewRoute(server, service, method string) *Route { return &Route{server, service, method} }
go
func NewRoute(server, service, method string) *Route { return &Route{server, service, method} }
[ "func", "NewRoute", "(", "server", ",", "service", ",", "method", "string", ")", "*", "Route", "{", "return", "&", "Route", "{", "server", ",", "service", ",", "method", "}", "\n", "}" ]
// NewRoute creates a new route
[ "NewRoute", "creates", "a", "new", "route" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/route/route.go#L46-L48
train
topfreegames/pitaya
route/route.go
String
func (r *Route) String() string { if r.SvType != "" { return fmt.Sprintf("%s.%s.%s", r.SvType, r.Service, r.Method) } return r.Short() }
go
func (r *Route) String() string { if r.SvType != "" { return fmt.Sprintf("%s.%s.%s", r.SvType, r.Service, r.Method) } return r.Short() }
[ "func", "(", "r", "*", "Route", ")", "String", "(", ")", "string", "{", "if", "r", ".", "SvType", "!=", "\"", "\"", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "SvType", ",", "r", ".", "Service", ",", "r", ".", "Meth...
// String transforms the route into a string
[ "String", "transforms", "the", "route", "into", "a", "string" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/route/route.go#L51-L56
train
topfreegames/pitaya
route/route.go
Short
func (r *Route) Short() string { return fmt.Sprintf("%s.%s", r.Service, r.Method) }
go
func (r *Route) Short() string { return fmt.Sprintf("%s.%s", r.Service, r.Method) }
[ "func", "(", "r", "*", "Route", ")", "Short", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Service", ",", "r", ".", "Method", ")", "\n", "}" ]
// Short transforms the route into a string without the server type
[ "Short", "transforms", "the", "route", "into", "a", "string", "without", "the", "server", "type" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/route/route.go#L59-L61
train
topfreegames/pitaya
route/route.go
Decode
func Decode(route string) (*Route, error) { r := strings.Split(route, ".") for _, s := range r { if strings.TrimSpace(s) == "" { return nil, ErrRouteFieldCantEmpty } } switch len(r) { case 3: return NewRoute(r[0], r[1], r[2]), nil case 2: return NewRoute("", r[0], r[1]), nil default: logger.Log.Erro...
go
func Decode(route string) (*Route, error) { r := strings.Split(route, ".") for _, s := range r { if strings.TrimSpace(s) == "" { return nil, ErrRouteFieldCantEmpty } } switch len(r) { case 3: return NewRoute(r[0], r[1], r[2]), nil case 2: return NewRoute("", r[0], r[1]), nil default: logger.Log.Erro...
[ "func", "Decode", "(", "route", "string", ")", "(", "*", "Route", ",", "error", ")", "{", "r", ":=", "strings", ".", "Split", "(", "route", ",", "\"", "\"", ")", "\n", "for", "_", ",", "s", ":=", "range", "r", "{", "if", "strings", ".", "TrimSp...
// Decode decodes the route
[ "Decode", "decodes", "the", "route" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/route/route.go#L64-L80
train
topfreegames/pitaya
examples/demo/custom_metrics/services/room.go
SetCounter
func (*Room) SetCounter( ctx context.Context, arg *messages.SetCounterArg, ) (*messages.Response, error) { counterMetricName := "my_counter" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportCount(counterMetricName, map[string]string{ "tag1": arg.Tag1, "tag2": arg.Tag2, }, arg.Value)...
go
func (*Room) SetCounter( ctx context.Context, arg *messages.SetCounterArg, ) (*messages.Response, error) { counterMetricName := "my_counter" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportCount(counterMetricName, map[string]string{ "tag1": arg.Tag1, "tag2": arg.Tag2, }, arg.Value)...
[ "func", "(", "*", "Room", ")", "SetCounter", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetCounterArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n...
// SetCounter sets custom my_counter
[ "SetCounter", "sets", "custom", "my_counter" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/custom_metrics/services/room.go#L17-L31
train
topfreegames/pitaya
examples/demo/custom_metrics/services/room.go
SetGauge1
func (*Room) SetGauge1( ctx context.Context, arg *messages.SetGaugeArg, ) (*messages.Response, error) { counterMetricName := "my_gauge_1" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportGauge(counterMetricName, map[string]string{ "tag1": arg.Tag, }, arg.Value) } return messages.OKR...
go
func (*Room) SetGauge1( ctx context.Context, arg *messages.SetGaugeArg, ) (*messages.Response, error) { counterMetricName := "my_gauge_1" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportGauge(counterMetricName, map[string]string{ "tag1": arg.Tag, }, arg.Value) } return messages.OKR...
[ "func", "(", "*", "Room", ")", "SetGauge1", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetGaugeArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n", ...
// SetGauge1 sets custom my_gauge_1
[ "SetGauge1", "sets", "custom", "my_gauge_1" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/custom_metrics/services/room.go#L34-L47
train
topfreegames/pitaya
examples/demo/custom_metrics/services/room.go
SetSummary
func (*Room) SetSummary( ctx context.Context, arg *messages.SetSummaryArg, ) (*messages.Response, error) { counterMetricName := "my_summary" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportSummary(counterMetricName, map[string]string{ "tag1": arg.Tag, }, arg.Value) } return message...
go
func (*Room) SetSummary( ctx context.Context, arg *messages.SetSummaryArg, ) (*messages.Response, error) { counterMetricName := "my_summary" for _, reporter := range pitaya.GetMetricsReporters() { reporter.ReportSummary(counterMetricName, map[string]string{ "tag1": arg.Tag, }, arg.Value) } return message...
[ "func", "(", "*", "Room", ")", "SetSummary", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetSummaryArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n...
// SetSummary sets custom my_summary
[ "SetSummary", "sets", "custom", "my_summary" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/custom_metrics/services/room.go#L66-L79
train
topfreegames/pitaya
service/remote.go
NewRemoteService
func NewRemoteService( rpcClient cluster.RPCClient, rpcServer cluster.RPCServer, sd cluster.ServiceDiscovery, encoder codec.PacketEncoder, serializer serialize.Serializer, router *router.Router, messageEncoder message.Encoder, server *cluster.Server, ) *RemoteService { return &RemoteService{ services: ...
go
func NewRemoteService( rpcClient cluster.RPCClient, rpcServer cluster.RPCServer, sd cluster.ServiceDiscovery, encoder codec.PacketEncoder, serializer serialize.Serializer, router *router.Router, messageEncoder message.Encoder, server *cluster.Server, ) *RemoteService { return &RemoteService{ services: ...
[ "func", "NewRemoteService", "(", "rpcClient", "cluster", ".", "RPCClient", ",", "rpcServer", "cluster", ".", "RPCServer", ",", "sd", "cluster", ".", "ServiceDiscovery", ",", "encoder", "codec", ".", "PacketEncoder", ",", "serializer", "serialize", ".", "Serializer...
// NewRemoteService creates and return a new RemoteService
[ "NewRemoteService", "creates", "and", "return", "a", "new", "RemoteService" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L64-L86
train
topfreegames/pitaya
service/remote.go
AddRemoteBindingListener
func (r *RemoteService) AddRemoteBindingListener(bindingListener cluster.RemoteBindingListener) { r.remoteBindingListeners = append(r.remoteBindingListeners, bindingListener) }
go
func (r *RemoteService) AddRemoteBindingListener(bindingListener cluster.RemoteBindingListener) { r.remoteBindingListeners = append(r.remoteBindingListeners, bindingListener) }
[ "func", "(", "r", "*", "RemoteService", ")", "AddRemoteBindingListener", "(", "bindingListener", "cluster", ".", "RemoteBindingListener", ")", "{", "r", ".", "remoteBindingListeners", "=", "append", "(", "r", ".", "remoteBindingListeners", ",", "bindingListener", ")...
// AddRemoteBindingListener adds a listener
[ "AddRemoteBindingListener", "adds", "a", "listener" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L122-L124
train
topfreegames/pitaya
service/remote.go
Call
func (r *RemoteService) Call(ctx context.Context, req *protos.Request) (*protos.Response, error) { c, err := util.GetContextFromRequest(req, r.server.ID) var res *protos.Response if err != nil { res = &protos.Response{ Error: &protos.Error{ Code: e.ErrInternalCode, Msg: err.Error(), }, } } else {...
go
func (r *RemoteService) Call(ctx context.Context, req *protos.Request) (*protos.Response, error) { c, err := util.GetContextFromRequest(req, r.server.ID) var res *protos.Response if err != nil { res = &protos.Response{ Error: &protos.Error{ Code: e.ErrInternalCode, Msg: err.Error(), }, } } else {...
[ "func", "(", "r", "*", "RemoteService", ")", "Call", "(", "ctx", "context", ".", "Context", ",", "req", "*", "protos", ".", "Request", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "c", ",", "err", ":=", "util", ".", "GetContext...
// Call processes a remote call
[ "Call", "processes", "a", "remote", "call" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L127-L147
train
topfreegames/pitaya
service/remote.go
SessionBindRemote
func (r *RemoteService) SessionBindRemote(ctx context.Context, msg *protos.BindMsg) (*protos.Response, error) { for _, r := range r.remoteBindingListeners { r.OnUserBind(msg.Uid, msg.Fid) } return &protos.Response{ Data: []byte("ack"), }, nil }
go
func (r *RemoteService) SessionBindRemote(ctx context.Context, msg *protos.BindMsg) (*protos.Response, error) { for _, r := range r.remoteBindingListeners { r.OnUserBind(msg.Uid, msg.Fid) } return &protos.Response{ Data: []byte("ack"), }, nil }
[ "func", "(", "r", "*", "RemoteService", ")", "SessionBindRemote", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "protos", ".", "BindMsg", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "for", "_", ",", "r", ":=", "range",...
// SessionBindRemote is called when a remote server binds a user session and want us to acknowledge it
[ "SessionBindRemote", "is", "called", "when", "a", "remote", "server", "binds", "a", "user", "session", "and", "want", "us", "to", "acknowledge", "it" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L150-L157
train
topfreegames/pitaya
service/remote.go
PushToUser
func (r *RemoteService) PushToUser(ctx context.Context, push *protos.Push) (*protos.Response, error) { logger.Log.Debugf("sending push to user %s: %v", push.GetUid(), string(push.Data)) s := session.GetSessionByUID(push.GetUid()) if s != nil { err := s.Push(push.Route, push.Data) if err != nil { return nil, e...
go
func (r *RemoteService) PushToUser(ctx context.Context, push *protos.Push) (*protos.Response, error) { logger.Log.Debugf("sending push to user %s: %v", push.GetUid(), string(push.Data)) s := session.GetSessionByUID(push.GetUid()) if s != nil { err := s.Push(push.Route, push.Data) if err != nil { return nil, e...
[ "func", "(", "r", "*", "RemoteService", ")", "PushToUser", "(", "ctx", "context", ".", "Context", ",", "push", "*", "protos", ".", "Push", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "logger", ".", "Log", ".", "Debugf", "(", "...
// PushToUser sends a push to user
[ "PushToUser", "sends", "a", "push", "to", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L160-L173
train
topfreegames/pitaya
service/remote.go
KickUser
func (r *RemoteService) KickUser(ctx context.Context, kick *protos.KickMsg) (*protos.KickAnswer, error) { logger.Log.Debugf("sending kick to user %s", kick.GetUserId()) s := session.GetSessionByUID(kick.GetUserId()) if s != nil { err := s.Kick(ctx) if err != nil { return nil, err } return &protos.KickAnsw...
go
func (r *RemoteService) KickUser(ctx context.Context, kick *protos.KickMsg) (*protos.KickAnswer, error) { logger.Log.Debugf("sending kick to user %s", kick.GetUserId()) s := session.GetSessionByUID(kick.GetUserId()) if s != nil { err := s.Kick(ctx) if err != nil { return nil, err } return &protos.KickAnsw...
[ "func", "(", "r", "*", "RemoteService", ")", "KickUser", "(", "ctx", "context", ".", "Context", ",", "kick", "*", "protos", ".", "KickMsg", ")", "(", "*", "protos", ".", "KickAnswer", ",", "error", ")", "{", "logger", ".", "Log", ".", "Debugf", "(", ...
// KickUser sends a kick to user
[ "KickUser", "sends", "a", "kick", "to", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L176-L189
train
topfreegames/pitaya
service/remote.go
DoRPC
func (r *RemoteService) DoRPC(ctx context.Context, serverID string, route *route.Route, protoData []byte) (*protos.Response, error) { msg := &message.Message{ Type: message.Request, Route: route.Short(), Data: protoData, } target, _ := r.serviceDiscovery.GetServer(serverID) if serverID != "" && target == n...
go
func (r *RemoteService) DoRPC(ctx context.Context, serverID string, route *route.Route, protoData []byte) (*protos.Response, error) { msg := &message.Message{ Type: message.Request, Route: route.Short(), Data: protoData, } target, _ := r.serviceDiscovery.GetServer(serverID) if serverID != "" && target == n...
[ "func", "(", "r", "*", "RemoteService", ")", "DoRPC", "(", "ctx", "context", ".", "Context", ",", "serverID", "string", ",", "route", "*", "route", ".", "Route", ",", "protoData", "[", "]", "byte", ")", "(", "*", "protos", ".", "Response", ",", "erro...
// DoRPC do rpc and get answer
[ "DoRPC", "do", "rpc", "and", "get", "answer" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L192-L205
train
topfreegames/pitaya
service/remote.go
RPC
func (r *RemoteService) RPC(ctx context.Context, serverID string, route *route.Route, reply proto.Message, arg proto.Message) error { var data []byte var err error if arg != nil { data, err = proto.Marshal(arg) if err != nil { return err } } res, err := r.DoRPC(ctx, serverID, route, data) if err != nil {...
go
func (r *RemoteService) RPC(ctx context.Context, serverID string, route *route.Route, reply proto.Message, arg proto.Message) error { var data []byte var err error if arg != nil { data, err = proto.Marshal(arg) if err != nil { return err } } res, err := r.DoRPC(ctx, serverID, route, data) if err != nil {...
[ "func", "(", "r", "*", "RemoteService", ")", "RPC", "(", "ctx", "context", ".", "Context", ",", "serverID", "string", ",", "route", "*", "route", ".", "Route", ",", "reply", "proto", ".", "Message", ",", "arg", "proto", ".", "Message", ")", "error", ...
// RPC makes rpcs
[ "RPC", "makes", "rpcs" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L208-L237
train
topfreegames/pitaya
service/remote.go
Docs
func (r *RemoteService) Docs(getPtrNames bool) (map[string]interface{}, error) { if r == nil { return map[string]interface{}{}, nil } return docgenerator.RemotesDocs(r.server.Type, r.services, getPtrNames) }
go
func (r *RemoteService) Docs(getPtrNames bool) (map[string]interface{}, error) { if r == nil { return map[string]interface{}{}, nil } return docgenerator.RemotesDocs(r.server.Type, r.services, getPtrNames) }
[ "func", "(", "r", "*", "RemoteService", ")", "Docs", "(", "getPtrNames", "bool", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "if", "r", "==", "nil", "{", "return", "map", "[", "string", "]", "interface", "{",...
// Docs returns documentation for remotes
[ "Docs", "returns", "documentation", "for", "remotes" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/remote.go#L450-L455
train
topfreegames/pitaya
component/method.go
isRemoteMethod
func isRemoteMethod(method reflect.Method) bool { mt := method.Type // Method must be exported. if method.PkgPath != "" { return false } // Method needs at least two ins: receiver and context.Context if mt.NumIn() != 2 && mt.NumIn() != 3 { return false } if t1 := mt.In(1); !t1.Implements(typeOfContext) { ...
go
func isRemoteMethod(method reflect.Method) bool { mt := method.Type // Method must be exported. if method.PkgPath != "" { return false } // Method needs at least two ins: receiver and context.Context if mt.NumIn() != 2 && mt.NumIn() != 3 { return false } if t1 := mt.In(1); !t1.Implements(typeOfContext) { ...
[ "func", "isRemoteMethod", "(", "method", "reflect", ".", "Method", ")", "bool", "{", "mt", ":=", "method", ".", "Type", "\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "// Me...
// isRemoteMethod decide a method is suitable remote method
[ "isRemoteMethod", "decide", "a", "method", "is", "suitable", "remote", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/component/method.go#L46-L82
train
topfreegames/pitaya
component/method.go
isHandlerMethod
func isHandlerMethod(method reflect.Method) bool { mt := method.Type // Method must be exported. if method.PkgPath != "" { return false } // Method needs two or three ins: receiver, context.Context and optional []byte or pointer. if mt.NumIn() != 2 && mt.NumIn() != 3 { return false } if t1 := mt.In(1); !t...
go
func isHandlerMethod(method reflect.Method) bool { mt := method.Type // Method must be exported. if method.PkgPath != "" { return false } // Method needs two or three ins: receiver, context.Context and optional []byte or pointer. if mt.NumIn() != 2 && mt.NumIn() != 3 { return false } if t1 := mt.In(1); !t...
[ "func", "isHandlerMethod", "(", "method", "reflect", ".", "Method", ")", "bool", "{", "mt", ":=", "method", ".", "Type", "\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "// M...
// isHandlerMethod decide a method is suitable handler method
[ "isHandlerMethod", "decide", "a", "method", "is", "suitable", "handler", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/component/method.go#L85-L115
train
topfreegames/pitaya
remote/sys.go
BindSession
func (s *Sys) BindSession(ctx context.Context, sessionData *protos.Session) (*protos.Response, error) { sess := session.GetSessionByID(sessionData.Id) if sess == nil { return nil, constants.ErrSessionNotFound } if err := sess.Bind(ctx, sessionData.Uid); err != nil { return nil, err } return &protos.Response{D...
go
func (s *Sys) BindSession(ctx context.Context, sessionData *protos.Session) (*protos.Response, error) { sess := session.GetSessionByID(sessionData.Id) if sess == nil { return nil, constants.ErrSessionNotFound } if err := sess.Bind(ctx, sessionData.Uid); err != nil { return nil, err } return &protos.Response{D...
[ "func", "(", "s", "*", "Sys", ")", "BindSession", "(", "ctx", "context", ".", "Context", ",", "sessionData", "*", "protos", ".", "Session", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "sess", ":=", "session", ".", "GetSessionByID"...
// BindSession binds the local session
[ "BindSession", "binds", "the", "local", "session" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/remote/sys.go#L38-L47
train
topfreegames/pitaya
remote/sys.go
Kick
func (s *Sys) Kick(ctx context.Context, msg *protos.KickMsg) (*protos.KickAnswer, error) { res := &protos.KickAnswer{ Kicked: false, } sess := session.GetSessionByUID(msg.GetUserId()) if sess == nil { return res, constants.ErrSessionNotFound } err := sess.Kick(ctx) if err != nil { return res, err } res.K...
go
func (s *Sys) Kick(ctx context.Context, msg *protos.KickMsg) (*protos.KickAnswer, error) { res := &protos.KickAnswer{ Kicked: false, } sess := session.GetSessionByUID(msg.GetUserId()) if sess == nil { return res, constants.ErrSessionNotFound } err := sess.Kick(ctx) if err != nil { return res, err } res.K...
[ "func", "(", "s", "*", "Sys", ")", "Kick", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "protos", ".", "KickMsg", ")", "(", "*", "protos", ".", "KickAnswer", ",", "error", ")", "{", "res", ":=", "&", "protos", ".", "KickAnswer", "{", "...
// Kick kicks a local user
[ "Kick", "kicks", "a", "local", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/remote/sys.go#L62-L76
train
topfreegames/pitaya
examples/demo/cluster_protobuf/services/connector.go
RemoteFunc
func (c *ConnectorRemote) RemoteFunc(ctx context.Context, message []byte) (*protos.Response, error) { fmt.Printf("received a remote call with this message: %s\n", message) return &protos.Response{ Msg: string(message), }, nil }
go
func (c *ConnectorRemote) RemoteFunc(ctx context.Context, message []byte) (*protos.Response, error) { fmt.Printf("received a remote call with this message: %s\n", message) return &protos.Response{ Msg: string(message), }, nil }
[ "func", "(", "c", "*", "ConnectorRemote", ")", "RemoteFunc", "(", "ctx", "context", ".", "Context", ",", "message", "[", "]", "byte", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",...
// RemoteFunc is a function that will be called remotelly
[ "RemoteFunc", "is", "a", "function", "that", "will", "be", "called", "remotelly" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_protobuf/services/connector.go#L27-L32
train
topfreegames/pitaya
module.go
RegisterModule
func RegisterModule(module interfaces.Module, name string) error { return RegisterModuleAfter(module, name) }
go
func RegisterModule(module interfaces.Module, name string) error { return RegisterModuleAfter(module, name) }
[ "func", "RegisterModule", "(", "module", "interfaces", ".", "Module", ",", "name", "string", ")", "error", "{", "return", "RegisterModuleAfter", "(", "module", ",", "name", ")", "\n", "}" ]
// RegisterModule registers a module, by default it register after registered modules
[ "RegisterModule", "registers", "a", "module", "by", "default", "it", "register", "after", "registered", "modules" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/module.go#L41-L43
train
topfreegames/pitaya
module.go
RegisterModuleAfter
func RegisterModuleAfter(module interfaces.Module, name string) error { if err := alreadyRegistered(name); err != nil { return err } modulesMap[name] = module modulesArr = append(modulesArr, moduleWrapper{ module: module, name: name, }) return nil }
go
func RegisterModuleAfter(module interfaces.Module, name string) error { if err := alreadyRegistered(name); err != nil { return err } modulesMap[name] = module modulesArr = append(modulesArr, moduleWrapper{ module: module, name: name, }) return nil }
[ "func", "RegisterModuleAfter", "(", "module", "interfaces", ".", "Module", ",", "name", "string", ")", "error", "{", "if", "err", ":=", "alreadyRegistered", "(", "name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "modulesMap", ...
// RegisterModuleAfter registers a module after all registered modules
[ "RegisterModuleAfter", "registers", "a", "module", "after", "all", "registered", "modules" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/module.go#L46-L58
train
topfreegames/pitaya
module.go
GetModule
func GetModule(name string) (interfaces.Module, error) { if m, ok := modulesMap[name]; ok { return m, nil } return nil, fmt.Errorf("module with name %s not found", name) }
go
func GetModule(name string) (interfaces.Module, error) { if m, ok := modulesMap[name]; ok { return m, nil } return nil, fmt.Errorf("module with name %s not found", name) }
[ "func", "GetModule", "(", "name", "string", ")", "(", "interfaces", ".", "Module", ",", "error", ")", "{", "if", "m", ",", "ok", ":=", "modulesMap", "[", "name", "]", ";", "ok", "{", "return", "m", ",", "nil", "\n", "}", "\n", "return", "nil", ",...
// GetModule gets a module with a name
[ "GetModule", "gets", "a", "module", "with", "a", "name" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/module.go#L78-L83
train
topfreegames/pitaya
module.go
startModules
func startModules() { logger.Log.Debug("initializing all modules") for _, modWrapper := range modulesArr { logger.Log.Debugf("initializing module: %s", modWrapper.name) if err := modWrapper.module.Init(); err != nil { logger.Log.Fatalf("error starting module %s, error: %s", modWrapper.name, err.Error()) } }...
go
func startModules() { logger.Log.Debug("initializing all modules") for _, modWrapper := range modulesArr { logger.Log.Debugf("initializing module: %s", modWrapper.name) if err := modWrapper.module.Init(); err != nil { logger.Log.Fatalf("error starting module %s, error: %s", modWrapper.name, err.Error()) } }...
[ "func", "startModules", "(", ")", "{", "logger", ".", "Log", ".", "Debug", "(", "\"", "\"", ")", "\n", "for", "_", ",", "modWrapper", ":=", "range", "modulesArr", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "modWrapper", ".", "n...
// startModules starts all modules in order
[ "startModules", "starts", "all", "modules", "in", "order" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/module.go#L94-L107
train
topfreegames/pitaya
module.go
shutdownModules
func shutdownModules() { for i := len(modulesArr) - 1; i >= 0; i-- { modulesArr[i].module.BeforeShutdown() } for i := len(modulesArr) - 1; i >= 0; i-- { name := modulesArr[i].name mod := modulesArr[i].module logger.Log.Debugf("stopping module: %s", name) if err := mod.Shutdown(); err != nil { logger.L...
go
func shutdownModules() { for i := len(modulesArr) - 1; i >= 0; i-- { modulesArr[i].module.BeforeShutdown() } for i := len(modulesArr) - 1; i >= 0; i-- { name := modulesArr[i].name mod := modulesArr[i].module logger.Log.Debugf("stopping module: %s", name) if err := mod.Shutdown(); err != nil { logger.L...
[ "func", "shutdownModules", "(", ")", "{", "for", "i", ":=", "len", "(", "modulesArr", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "modulesArr", "[", "i", "]", ".", "module", ".", "BeforeShutdown", "(", ")", "\n", "}", "\n\n", "for", ...
// shutdownModules starts all modules in reverse order
[ "shutdownModules", "starts", "all", "modules", "in", "reverse", "order" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/module.go#L110-L125
train
topfreegames/pitaya
metrics/statsd_reporter.go
NewStatsdReporter
func NewStatsdReporter( config *config.Config, serverType string, tagsMap map[string]string, clientOrNil ...Client, ) (*StatsdReporter, error) { host := config.GetString("pitaya.metrics.statsd.host") prefix := config.GetString("pitaya.metrics.statsd.prefix") rate, err := strconv.ParseFloat(config.GetString("pita...
go
func NewStatsdReporter( config *config.Config, serverType string, tagsMap map[string]string, clientOrNil ...Client, ) (*StatsdReporter, error) { host := config.GetString("pitaya.metrics.statsd.host") prefix := config.GetString("pitaya.metrics.statsd.prefix") rate, err := strconv.ParseFloat(config.GetString("pita...
[ "func", "NewStatsdReporter", "(", "config", "*", "config", ".", "Config", ",", "serverType", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "clientOrNil", "...", "Client", ",", ")", "(", "*", "StatsdReporter", ",", "error", ")", "{", ...
// NewStatsdReporter returns an instance of statsd reportar and an error if something fails
[ "NewStatsdReporter", "returns", "an", "instance", "of", "statsd", "reportar", "and", "an", "error", "if", "something", "fails" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/statsd_reporter.go#L48-L78
train
topfreegames/pitaya
metrics/statsd_reporter.go
ReportCount
func (s *StatsdReporter) ReportCount(metric string, tagsMap map[string]string, count float64) error { fullTags := s.defaultTags for k, v := range tagsMap { fullTags = append(fullTags, fmt.Sprintf("%s:%s", k, v)) } err := s.client.Count(metric, int64(count), fullTags, s.rate) if err != nil { logger.Log.Errorf...
go
func (s *StatsdReporter) ReportCount(metric string, tagsMap map[string]string, count float64) error { fullTags := s.defaultTags for k, v := range tagsMap { fullTags = append(fullTags, fmt.Sprintf("%s:%s", k, v)) } err := s.client.Count(metric, int64(count), fullTags, s.rate) if err != nil { logger.Log.Errorf...
[ "func", "(", "s", "*", "StatsdReporter", ")", "ReportCount", "(", "metric", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "count", "float64", ")", "error", "{", "fullTags", ":=", "s", ".", "defaultTags", "\n\n", "for", "k", ",", "...
// ReportCount sends count reports to statsd
[ "ReportCount", "sends", "count", "reports", "to", "statsd" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/statsd_reporter.go#L95-L108
train
topfreegames/pitaya
metrics/statsd_reporter.go
ReportGauge
func (s *StatsdReporter) ReportGauge(metric string, tagsMap map[string]string, value float64) error { fullTags := s.defaultTags for k, v := range tagsMap { fullTags = append(fullTags, fmt.Sprintf("%s:%s", k, v)) } err := s.client.Gauge(metric, value, fullTags, s.rate) if err != nil { logger.Log.Errorf("faile...
go
func (s *StatsdReporter) ReportGauge(metric string, tagsMap map[string]string, value float64) error { fullTags := s.defaultTags for k, v := range tagsMap { fullTags = append(fullTags, fmt.Sprintf("%s:%s", k, v)) } err := s.client.Gauge(metric, value, fullTags, s.rate) if err != nil { logger.Log.Errorf("faile...
[ "func", "(", "s", "*", "StatsdReporter", ")", "ReportGauge", "(", "metric", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "value", "float64", ")", "error", "{", "fullTags", ":=", "s", ".", "defaultTags", "\n\n", "for", "k", ",", "...
// ReportGauge sents the gauge value and reports to statsd
[ "ReportGauge", "sents", "the", "gauge", "value", "and", "reports", "to", "statsd" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/statsd_reporter.go#L111-L124
train
topfreegames/pitaya
group.go
GroupCreate
func GroupCreate(ctx context.Context, groupName string) error { return groupServiceInstance.GroupCreate(ctx, groupName) }
go
func GroupCreate(ctx context.Context, groupName string) error { return groupServiceInstance.GroupCreate(ctx, groupName) }
[ "func", "GroupCreate", "(", "ctx", "context", ".", "Context", ",", "groupName", "string", ")", "error", "{", "return", "groupServiceInstance", ".", "GroupCreate", "(", "ctx", ",", "groupName", ")", "\n", "}" ]
// GroupCreate creates a group
[ "GroupCreate", "creates", "a", "group" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/group.go#L49-L51
train
topfreegames/pitaya
group.go
GroupCreateWithTTL
func GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error { return groupServiceInstance.GroupCreateWithTTL(ctx, groupName, ttlTime) }
go
func GroupCreateWithTTL(ctx context.Context, groupName string, ttlTime time.Duration) error { return groupServiceInstance.GroupCreateWithTTL(ctx, groupName, ttlTime) }
[ "func", "GroupCreateWithTTL", "(", "ctx", "context", ".", "Context", ",", "groupName", "string", ",", "ttlTime", "time", ".", "Duration", ")", "error", "{", "return", "groupServiceInstance", ".", "GroupCreateWithTTL", "(", "ctx", ",", "groupName", ",", "ttlTime"...
// GroupCreateWithTTL creates a group with given TTL
[ "GroupCreateWithTTL", "creates", "a", "group", "with", "given", "TTL" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/group.go#L54-L56
train
topfreegames/pitaya
group.go
GroupBroadcast
func GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error { logger.Log.Debugf("Type=Broadcast Route=%s, Data=%+v", route, v) members, err := GroupMembers(ctx, groupName) if err != nil { return err } return sendDataToMembers(members, frontendType, route, v) }
go
func GroupBroadcast(ctx context.Context, frontendType, groupName, route string, v interface{}) error { logger.Log.Debugf("Type=Broadcast Route=%s, Data=%+v", route, v) members, err := GroupMembers(ctx, groupName) if err != nil { return err } return sendDataToMembers(members, frontendType, route, v) }
[ "func", "GroupBroadcast", "(", "ctx", "context", ".", "Context", ",", "frontendType", ",", "groupName", ",", "route", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "route", ",",...
// GroupBroadcast pushes the message to all members inside group
[ "GroupBroadcast", "pushes", "the", "message", "to", "all", "members", "inside", "group" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/group.go#L64-L72
train