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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
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.RemoteAddr()) // prevent closing closed channel select { case <-a.chDie: // expect default: close(a.chStopWrite) close(a.chStopHeartbeat) close(a.chDie) onSessionClosed(a.Session) } metrics.ReportNumberOfConnectedClients(a.metricsReporters, session.SessionCount) return a.conn.Close() }
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.RemoteAddr()) // prevent closing closed channel select { case <-a.chDie: // expect default: close(a.chStopWrite) close(a.chStopHeartbeat) close(a.chDie) onSessionClosed(a.Session) } metrics.ReportNumberOfConnectedClients(a.metricsReporters, session.SessionCount) return a.conn.Close() }
[ "func", "(", "a", "*", "Agent", ")", "Close", "(", ")", "error", "{", "a", ".", "closeMutex", ".", "Lock", "(", ")", "\n", "defer", "a", ".", "closeMutex", ".", "Unlock", "(", ")", "\n", "if", "a", ".", "GetStatus", "(", ")", "==", "constants", ".", "StatusClosed", "{", "return", "constants", ".", "ErrCloseClosedSession", "\n", "}", "\n", "a", ".", "SetStatus", "(", "constants", ".", "StatusClosed", ")", "\n\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "a", ".", "Session", ".", "ID", "(", ")", ",", "a", ".", "Session", ".", "UID", "(", ")", ",", "a", ".", "conn", ".", "RemoteAddr", "(", ")", ")", "\n\n", "// prevent closing closed channel", "select", "{", "case", "<-", "a", ".", "chDie", ":", "// expect", "default", ":", "close", "(", "a", ".", "chStopWrite", ")", "\n", "close", "(", "a", ".", "chStopHeartbeat", ")", "\n", "close", "(", "a", ".", "chDie", ")", "\n", "onSessionClosed", "(", "a", ".", "Session", ")", "\n", "}", "\n\n", "metrics", ".", "ReportNumberOfConnectedClients", "(", "a", ".", "metricsReporters", ",", "session", ".", "SessionCount", ")", "\n\n", "return", "a", ".", "conn", ".", "Close", "(", ")", "\n", "}" ]
// 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", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "a", ".", "conn", ".", "Write", "(", "p", ")", "\n", "return", "err", "\n", "}" ]
// 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", ".", "Session", ".", "UID", "(", ")", ")", "\n", "}", "(", ")", "\n\n", "go", "a", ".", "write", "(", ")", "\n", "go", "a", ".", "heartbeat", "(", ")", "\n", "select", "{", "case", "<-", "a", ".", "chDie", ":", "// agent closed signal", "return", "\n", "}", "\n", "}" ]
// 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 an error: %s", e.Error()) return } e = a.Session.ResponseMID(ctx, mid, p, true) if e != nil { logger.Log.Errorf("error answering the user with an error: %s", e.Error()) } }
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 an error: %s", e.Error()) return } e = a.Session.ResponseMID(ctx, mid, p, true) if e != nil { logger.Log.Errorf("error answering the user with an error: %s", e.Error()) } }
[ "func", "(", "a", "*", "Agent", ")", "AnswerWithError", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "err", "error", ")", "{", "if", "ctx", "!=", "nil", "&&", "err", "!=", "nil", "{", "s", ":=", "opentracing", ".", "SpanFromContext", "(", "ctx", ")", "\n", "if", "s", "!=", "nil", "{", "tracing", ".", "LogError", "(", "s", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "p", ",", "e", ":=", "util", ".", "GetErrorPayload", "(", "a", ".", "serializer", ",", "err", ")", "\n", "if", "e", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "e", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "e", "=", "a", ".", "Session", ".", "ResponseMID", "(", "ctx", ",", "mid", ",", "p", ",", "true", ")", "\n", "if", "e", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "e", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}" ]
// 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: frontend, } if frontend { sessionsByID.Store(s.id, s) atomic.AddInt64(&SessionCount, 1) } if len(UID) > 0 { s.uid = UID[0] } return s }
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: frontend, } if frontend { sessionsByID.Store(s.id, s) atomic.AddInt64(&SessionCount, 1) } if len(UID) > 0 { s.uid = UID[0] } return s }
[ "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", ":", "frontend", ",", "}", "\n", "if", "frontend", "{", "sessionsByID", ".", "Store", "(", "s", ".", "id", ",", "s", ")", "\n", "atomic", ".", "AddInt64", "(", "&", "SessionCount", ",", "1", ")", "\n", "}", "\n", "if", "len", "(", "UID", ")", ">", "0", "{", "s", ".", "uid", "=", "UID", "[", "0", "]", "\n", "}", "\n", "return", "s", "\n", "}" ]
// 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", ".", "(", "*", "Session", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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(sessionBindCallbacks, f) }
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(sessionBindCallbacks, f) }
[ "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", "for", "_", ",", "fun", ":=", "range", "sessionBindCallbacks", "{", "sf2", ":=", "reflect", ".", "ValueOf", "(", "fun", ")", "\n", "if", "sf1", ".", "Pointer", "(", ")", "==", "sf2", ".", "Pointer", "(", ")", "{", "return", "\n", "}", "\n", "}", "\n", "sessionBindCallbacks", "=", "append", "(", "sessionBindCallbacks", ",", "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 = append(afterBindCallbacks, f) }
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 = append(afterBindCallbacks, f) }
[ "func", "OnAfterSessionBind", "(", "f", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "Session", ")", "error", ")", "{", "// Prevents the same function to be added twice in onSessionBind", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\n", "for", "_", ",", "fun", ":=", "range", "afterBindCallbacks", "{", "sf2", ":=", "reflect", ".", "ValueOf", "(", "fun", ")", "\n", "if", "sf1", ".", "Pointer", "(", ")", "==", "sf2", ".", "Pointer", "(", ")", "{", "return", "\n", "}", "\n", "}", "\n", "afterBindCallbacks", "=", "append", "(", "afterBindCallbacks", ",", "f", ")", "\n", "}" ]
// 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", ".", "ValueOf", "(", "fun", ")", "\n", "if", "sf1", ".", "Pointer", "(", ")", "==", "sf2", ".", "Pointer", "(", ")", "{", "return", "\n", "}", "\n", "}", "\n", "SessionCloseCallbacks", "=", "append", "(", "SessionCloseCallbacks", ",", "f", ")", "\n", "}" ]
// 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", "(", "ctx", ",", "mid", ",", "v", ",", "err", "...", ")", "\n", "}" ]
// 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", "\n", "return", "s", ".", "updateEncodedData", "(", ")", "\n", "}" ]
// 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", "]", "interface", "{", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "encodedData", ",", "&", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "s", ".", "SetData", "(", "data", ")", "\n", "}" ]
// 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 _, cb := range afterBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } // if code running on frontend server if s.IsFrontend { sessionsByUID.Store(uid, s) } else { // If frontentID is set this means it is a remote call and the current server // is not the frontend server that received the user request err := s.bindInFront(ctx) if err != nil { logger.Log.Error("error while trying to push session to front: ", err) s.uid = "" return err } } return nil }
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 _, cb := range afterBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } // if code running on frontend server if s.IsFrontend { sessionsByUID.Store(uid, s) } else { // If frontentID is set this means it is a remote call and the current server // is not the frontend server that received the user request err := s.bindInFront(ctx) if err != nil { logger.Log.Error("error while trying to push session to front: ", err) s.uid = "" return err } } return nil }
[ "func", "(", "s", "*", "Session", ")", "Bind", "(", "ctx", "context", ".", "Context", ",", "uid", "string", ")", "error", "{", "if", "uid", "==", "\"", "\"", "{", "return", "constants", ".", "ErrIllegalUID", "\n", "}", "\n\n", "if", "s", ".", "UID", "(", ")", "!=", "\"", "\"", "{", "return", "constants", ".", "ErrSessionAlreadyBound", "\n", "}", "\n\n", "s", ".", "uid", "=", "uid", "\n", "for", "_", ",", "cb", ":=", "range", "sessionBindCallbacks", "{", "err", ":=", "cb", "(", "ctx", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "uid", "=", "\"", "\"", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "cb", ":=", "range", "afterBindCallbacks", "{", "err", ":=", "cb", "(", "ctx", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "s", ".", "uid", "=", "\"", "\"", "\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "// if code running on frontend server", "if", "s", ".", "IsFrontend", "{", "sessionsByUID", ".", "Store", "(", "uid", ",", "s", ")", "\n", "}", "else", "{", "// If frontentID is set this means it is a remote call and the current server", "// is not the frontend server that received the user request", "err", ":=", "s", ".", "bindInFront", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Error", "(", "\"", "\"", ",", "err", ")", "\n", "s", ".", "uid", "=", "\"", "\"", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "(", "s", ".", "OnCloseCallbacks", ",", "c", ")", "\n", "return", "nil", "\n", "}" ]
// 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 used we need to unsubscribe for _, sub := range s.Subscriptions { err := sub.Unsubscribe() if err != nil { logger.Log.Errorf("error unsubscribing to user's messages channel: %s, this can cause performance and leak issues", err.Error()) } else { logger.Log.Debugf("successfully unsubscribed to user's %s messages channel", s.UID()) } } } s.entity.Close() }
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 used we need to unsubscribe for _, sub := range s.Subscriptions { err := sub.Unsubscribe() if err != nil { logger.Log.Errorf("error unsubscribing to user's messages channel: %s, this can cause performance and leak issues", err.Error()) } else { logger.Log.Debugf("successfully unsubscribed to user's %s messages channel", s.UID()) } } } s.entity.Close() }
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "{", "atomic", ".", "AddInt64", "(", "&", "SessionCount", ",", "-", "1", ")", "\n", "sessionsByID", ".", "Delete", "(", "s", ".", "ID", "(", ")", ")", "\n", "sessionsByUID", ".", "Delete", "(", "s", ".", "UID", "(", ")", ")", "\n", "// 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 used we need to unsubscribe", "for", "_", ",", "sub", ":=", "range", "s", ".", "Subscriptions", "{", "err", ":=", "sub", ".", "Unsubscribe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "else", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "s", ".", "UID", "(", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "s", ".", "entity", ".", "Close", "(", ")", "\n", "}" ]
// 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", ".", "updateEncodedData", "(", ")", "\n", "}" ]
// 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", "return", "has", "\n", "}" ]
// 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", "]", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "v", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "int", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "int8", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "int16", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "int32", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "int64", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "uint", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "uint8", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "uint16", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "uint32", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "uint64", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "float32", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "0", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "float64", ")", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n\n", "value", ",", "ok", ":=", "v", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "value", "\n", "}" ]
// 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", ".", "sendRequestToFront", "(", "ctx", ",", "constants", ".", "SessionPushRoute", ",", "true", ")", "\n", "}" ]
// 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", "]", "interface", "{", "}", "{", "}", "\n", "s", ".", "updateEncodedData", "(", ")", "\n", "}" ]
// 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", "nil", ",", "constants", ".", "ErrWrongValueType", "\n", "}", "\n", "return", "proto", ".", "Marshal", "(", "pb", ")", "\n", "}" ]
// 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", "constants", ".", "ErrWrongValueType", "\n", "}", "\n", "return", "proto", ".", "Unmarshal", "(", "data", ",", "pb", ")", "\n", "}" ]
// 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, } // add to manager Manager.ChCreatedTimer <- t return t }
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, } // add to manager Manager.ChCreatedTimer <- t return t }
[ "func", "NewTimer", "(", "fn", "Func", ",", "interval", "time", ".", "Duration", ",", "counter", "int", ")", "*", "Timer", "{", "id", ":=", "atomic", ".", "AddInt64", "(", "&", "Manager", ".", "incrementID", ",", "1", ")", "\n", "t", ":=", "&", "Timer", "{", "ID", ":", "id", ",", "fn", ":", "fn", ",", "createAt", ":", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ",", "interval", ":", "interval", ",", "elapse", ":", "int64", "(", "interval", ")", ",", "// first execution will be after interval", "counter", ":", "counter", ",", "}", "\n\n", "// add to manager", "Manager", ".", "ChCreatedTimer", "<-", "t", "\n", "return", "t", "\n", "}" ]
// 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", ".", "ChClosingTimer", ")", "<", "timerBacklog", "{", "Manager", ".", "ChClosingTimer", "<-", "t", ".", "ID", "\n", "atomic", ".", "StoreInt32", "(", "&", "t", ".", "closed", ",", "1", ")", "\n", "}", "else", "{", "t", ".", "counter", "=", "0", "// automatically closed in next Cron", "\n", "}", "\n", "}" ]
// 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", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "fn", "(", ")", "\n", "}" ]
// 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", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// 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", ".", "Error", "(", ")", ")", "\n", "return", "\"", "\"", "\n", "}", "\n", "return", "string", "(", "str", ")", "\n", "}" ]
// 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", ",", "reply", ",", "arg", ")", "\n", "}" ]
// 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", ",", "routeStr", ",", "reply", ",", "arg", ")", "\n", "}" ]
// 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", ".", "worker", ".", "EnqueueRPC", "(", "routeStr", ",", "metadata", ",", "reply", ",", "arg", ")", "\n", "}" ]
// 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", "string", ",", "err", "error", ")", "{", "return", "app", ".", "worker", ".", "EnqueueRPCWithOptions", "(", "routeStr", ",", "metadata", ",", "reply", ",", "arg", ",", "opts", ")", "\n", "}" ]
// 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, bindingStorage: bindingStorage, infoRetriever: infoRetriever, } gs.configure() return gs, nil }
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, bindingStorage: bindingStorage, infoRetriever: infoRetriever, } gs.configure() return gs, nil }
[ "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", ",", "bindingStorage", ":", "bindingStorage", ",", "infoRetriever", ":", "infoRetriever", ",", "}", "\n\n", "gs", ".", "configure", "(", ")", "\n\n", "return", "gs", ",", "nil", "\n", "}" ]
// 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 := opentracing.Tags{ "span.kind": "client", "local.id": gs.server.ID, "peer.serverType": server.Type, "peer.id": server.ID, } ctx = tracing.StartSpan(ctx, "RPC Call", tags, parent) defer tracing.FinishSpan(ctx, err) req, err := buildRequest(ctx, rpcType, route, session, msg, gs.server) if err != nil { return nil, err } if c, ok := gs.clientMap.Load(server.ID); ok { ctxT, done := context.WithTimeout(ctx, gs.reqTimeout) defer done() if gs.metricsReporters != nil { startTime := time.Now() ctxT = pcontext.AddToPropagateCtx(ctxT, constants.StartTimeKey, startTime.UnixNano()) ctxT = pcontext.AddToPropagateCtx(ctxT, constants.RouteKey, route.String()) defer metrics.ReportTimingFromCtx(ctxT, gs.metricsReporters, "rpc", err) } res, err := c.(protos.PitayaClient).Call(ctxT, &req) if err != nil { return nil, err } if res.Error != nil { if res.Error.Code == "" { res.Error.Code = pitErrors.ErrUnknownCode } err = &pitErrors.Error{ Code: res.Error.Code, Message: res.Error.Msg, Metadata: res.Error.Metadata, } return nil, err } return res, nil } return nil, constants.ErrNoConnectionToServer }
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 := opentracing.Tags{ "span.kind": "client", "local.id": gs.server.ID, "peer.serverType": server.Type, "peer.id": server.ID, } ctx = tracing.StartSpan(ctx, "RPC Call", tags, parent) defer tracing.FinishSpan(ctx, err) req, err := buildRequest(ctx, rpcType, route, session, msg, gs.server) if err != nil { return nil, err } if c, ok := gs.clientMap.Load(server.ID); ok { ctxT, done := context.WithTimeout(ctx, gs.reqTimeout) defer done() if gs.metricsReporters != nil { startTime := time.Now() ctxT = pcontext.AddToPropagateCtx(ctxT, constants.StartTimeKey, startTime.UnixNano()) ctxT = pcontext.AddToPropagateCtx(ctxT, constants.RouteKey, route.String()) defer metrics.ReportTimingFromCtx(ctxT, gs.metricsReporters, "rpc", err) } res, err := c.(protos.PitayaClient).Call(ctxT, &req) if err != nil { return nil, err } if res.Error != nil { if res.Error.Code == "" { res.Error.Code = pitErrors.ErrUnknownCode } err = &pitErrors.Error{ Code: res.Error.Code, Message: res.Error.Msg, Metadata: res.Error.Metadata, } return nil, err } return res, nil } return nil, constants.ErrNoConnectionToServer }
[ "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", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Warnf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "tags", ":=", "opentracing", ".", "Tags", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "gs", ".", "server", ".", "ID", ",", "\"", "\"", ":", "server", ".", "Type", ",", "\"", "\"", ":", "server", ".", "ID", ",", "}", "\n", "ctx", "=", "tracing", ".", "StartSpan", "(", "ctx", ",", "\"", "\"", ",", "tags", ",", "parent", ")", "\n", "defer", "tracing", ".", "FinishSpan", "(", "ctx", ",", "err", ")", "\n\n", "req", ",", "err", ":=", "buildRequest", "(", "ctx", ",", "rpcType", ",", "route", ",", "session", ",", "msg", ",", "gs", ".", "server", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "c", ",", "ok", ":=", "gs", ".", "clientMap", ".", "Load", "(", "server", ".", "ID", ")", ";", "ok", "{", "ctxT", ",", "done", ":=", "context", ".", "WithTimeout", "(", "ctx", ",", "gs", ".", "reqTimeout", ")", "\n", "defer", "done", "(", ")", "\n\n", "if", "gs", ".", "metricsReporters", "!=", "nil", "{", "startTime", ":=", "time", ".", "Now", "(", ")", "\n", "ctxT", "=", "pcontext", ".", "AddToPropagateCtx", "(", "ctxT", ",", "constants", ".", "StartTimeKey", ",", "startTime", ".", "UnixNano", "(", ")", ")", "\n", "ctxT", "=", "pcontext", ".", "AddToPropagateCtx", "(", "ctxT", ",", "constants", ".", "RouteKey", ",", "route", ".", "String", "(", ")", ")", "\n", "defer", "metrics", ".", "ReportTimingFromCtx", "(", "ctxT", ",", "gs", ".", "metricsReporters", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "res", ",", "err", ":=", "c", ".", "(", "protos", ".", "PitayaClient", ")", ".", "Call", "(", "ctxT", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "res", ".", "Error", "!=", "nil", "{", "if", "res", ".", "Error", ".", "Code", "==", "\"", "\"", "{", "res", ".", "Error", ".", "Code", "=", "pitErrors", ".", "ErrUnknownCode", "\n", "}", "\n", "err", "=", "&", "pitErrors", ".", "Error", "{", "Code", ":", "res", ".", "Error", ".", "Code", ",", "Message", ":", "res", ".", "Error", ".", "Msg", ",", "Metadata", ":", "res", ".", "Error", ".", "Metadata", ",", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "res", ",", "nil", "\n\n", "}", "\n", "return", "nil", ",", "constants", ".", "ErrNoConnectionToServer", "\n", "}" ]
// 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: gs.server.ID, } ctxT, done := context.WithTimeout(context.Background(), gs.reqTimeout) defer done() _, err := c.(protos.PitayaClient).SessionBindRemote(ctxT, msg) return err } } return nil }
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: gs.server.ID, } ctxT, done := context.WithTimeout(context.Background(), gs.reqTimeout) defer done() _, err := c.(protos.PitayaClient).SessionBindRemote(ctxT, msg) return err } } return nil }
[ "func", "(", "gs", "*", "GRPCClient", ")", "BroadcastSessionBind", "(", "uid", "string", ")", "error", "{", "if", "gs", ".", "bindingStorage", "==", "nil", "{", "return", "constants", ".", "ErrNoBindingStorageModule", "\n", "}", "\n", "fid", ",", "_", ":=", "gs", ".", "bindingStorage", ".", "GetUserFrontendID", "(", "uid", ",", "gs", ".", "server", ".", "Type", ")", "\n", "if", "fid", "!=", "\"", "\"", "{", "if", "c", ",", "ok", ":=", "gs", ".", "clientMap", ".", "Load", "(", "fid", ")", ";", "ok", "{", "msg", ":=", "&", "protos", ".", "BindMsg", "{", "Uid", ":", "uid", ",", "Fid", ":", "gs", ".", "server", ".", "ID", ",", "}", "\n", "ctxT", ",", "done", ":=", "context", ".", "WithTimeout", "(", "context", ".", "Background", "(", ")", ",", "gs", ".", "reqTimeout", ")", "\n", "defer", "done", "(", ")", "\n", "_", ",", "err", ":=", "c", ".", "(", "protos", ".", "PitayaClient", ")", ".", "SessionBindRemote", "(", "ctxT", ",", "msg", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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 := gs.clientMap.Load(svID); ok { ctxT, done := context.WithTimeout(context.Background(), gs.reqTimeout) defer done() _, err := c.(protos.PitayaClient).KickUser(ctxT, kick) return err } return constants.ErrNoConnectionToServer }
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 := gs.clientMap.Load(svID); ok { ctxT, done := context.WithTimeout(context.Background(), gs.reqTimeout) defer done() _, err := c.(protos.PitayaClient).KickUser(ctxT, kick) return err } return constants.ErrNoConnectionToServer }
[ "func", "(", "gs", "*", "GRPCClient", ")", "SendKick", "(", "userID", "string", ",", "serverType", "string", ",", "kick", "*", "protos", ".", "KickMsg", ")", "error", "{", "var", "svID", "string", "\n", "var", "err", "error", "\n\n", "if", "gs", ".", "bindingStorage", "==", "nil", "{", "return", "constants", ".", "ErrNoBindingStorageModule", "\n", "}", "\n\n", "svID", ",", "err", "=", "gs", ".", "bindingStorage", ".", "GetUserFrontendID", "(", "userID", ",", "serverType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "c", ",", "ok", ":=", "gs", ".", "clientMap", ".", "Load", "(", "svID", ")", ";", "ok", "{", "ctxT", ",", "done", ":=", "context", ".", "WithTimeout", "(", "context", ".", "Background", "(", ")", ",", "gs", ".", "reqTimeout", ")", "\n", "defer", "done", "(", ")", "\n", "_", ",", "err", ":=", "c", ".", "(", "protos", ".", "PitayaClient", ")", ".", "KickUser", "(", "ctxT", ",", "kick", ")", "\n", "return", "err", "\n", "}", "\n", "return", "constants", ".", "ErrNoConnectionToServer", "\n", "}" ]
// 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 %s specified in metadata", sv.ID, portKey) return } address := fmt.Sprintf("%s:%s", host, port) conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { logger.Log.Errorf("unable to connect to server %s at %s: %v", sv.ID, address, err) return } c := protos.NewPitayaClient(conn) gs.clientMap.Store(sv.ID, c) logger.Log.Debugf("[grpc client] added server %s at %s", sv.ID, address) }
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 %s specified in metadata", sv.ID, portKey) return } address := fmt.Sprintf("%s:%s", host, port) conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { logger.Log.Errorf("unable to connect to server %s at %s: %v", sv.ID, address, err) return } c := protos.NewPitayaClient(conn) gs.clientMap.Store(sv.ID, c) logger.Log.Debugf("[grpc client] added server %s at %s", sv.ID, address) }
[ "func", "(", "gs", "*", "GRPCClient", ")", "AddServer", "(", "sv", "*", "Server", ")", "{", "var", "host", ",", "port", ",", "portKey", "string", "\n", "var", "ok", "bool", "\n\n", "host", ",", "portKey", "=", "gs", ".", "getServerHost", "(", "sv", ")", "\n", "if", "host", "==", "\"", "\"", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "sv", ".", "ID", ")", "\n", "return", "\n", "}", "\n\n", "if", "port", ",", "ok", "=", "sv", ".", "Metadata", "[", "portKey", "]", ";", "!", "ok", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "sv", ".", "ID", ",", "portKey", ")", "\n", "return", "\n", "}", "\n\n", "address", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "host", ",", "port", ")", "\n", "conn", ",", "err", ":=", "grpc", ".", "Dial", "(", "address", ",", "grpc", ".", "WithInsecure", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "sv", ".", "ID", ",", "address", ",", "err", ")", "\n", "return", "\n", "}", "\n", "c", ":=", "protos", ".", "NewPitayaClient", "(", "conn", ")", "\n", "gs", ".", "clientMap", ".", "Store", "(", "sv", ".", "ID", ",", "c", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "sv", ".", "ID", ",", "address", ")", "\n", "}" ]
// 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", ".", "clientMap", ".", "Delete", "(", "sv", ".", "ID", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "sv", ".", "ID", ")", "\n", "}", "\n", "}" ]
// 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", "\n", "}" ]
// 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", ".", "GetDefaultLoggerFromCtx", "(", "ctx", ")", "\n", "logger", ".", "Infof", "(", "\"", "\"", ",", "resp", ",", "err", ")", "\n\n", "return", "resp", ",", "err", "\n", "}" ]
// 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 } s.Subscriptions = []*nats.Subscription{subu, subk} } return nil }
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 } s.Subscriptions = []*nats.Subscription{subu, subk} } return nil }
[ "func", "(", "ns", "*", "NatsRPCServer", ")", "onSessionBind", "(", "ctx", "context", ".", "Context", ",", "s", "*", "session", ".", "Session", ")", "error", "{", "if", "ns", ".", "server", ".", "Frontend", "{", "subu", ",", "err", ":=", "ns", ".", "subscribeToUserMessages", "(", "s", ".", "UID", "(", ")", ",", "ns", ".", "server", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "subk", ",", "err", ":=", "ns", ".", "subscribeToUserKickChannel", "(", "s", ".", "UID", "(", ")", ",", "ns", ".", "server", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "s", ".", "Subscriptions", "=", "[", "]", "*", "nats", ".", "Subscription", "{", "subu", ",", "subk", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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(getChannel(ns.server.Type, ns.server.ID)); err != nil { return err } err = ns.subscribeToBindingsChannel() if err != nil { return err } // this handles remote messages for i := 0; i < ns.config.GetInt("pitaya.concurrency.remote.service"); i++ { go ns.processMessages(i) } session.OnSessionBind(ns.onSessionBind) // this should be so fast that we shoudn't need concurrency go ns.processPushes() go ns.processSessionBindings() go ns.processKick() return nil }
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(getChannel(ns.server.Type, ns.server.ID)); err != nil { return err } err = ns.subscribeToBindingsChannel() if err != nil { return err } // this handles remote messages for i := 0; i < ns.config.GetInt("pitaya.concurrency.remote.service"); i++ { go ns.processMessages(i) } session.OnSessionBind(ns.onSessionBind) // this should be so fast that we shoudn't need concurrency go ns.processPushes() go ns.processSessionBindings() go ns.processKick() return nil }
[ "func", "(", "ns", "*", "NatsRPCServer", ")", "Init", "(", ")", "error", "{", "// TODO should we have concurrency here? it feels like we should", "go", "ns", ".", "handleMessages", "(", ")", "\n", "conn", ",", "err", ":=", "setupNatsConn", "(", "ns", ".", "connString", ",", "ns", ".", "appDieChan", ",", "nats", ".", "MaxReconnects", "(", "ns", ".", "maxReconnectionRetries", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "ns", ".", "conn", "=", "conn", "\n", "if", "ns", ".", "sub", ",", "err", "=", "ns", ".", "subscribe", "(", "getChannel", "(", "ns", ".", "server", ".", "Type", ",", "ns", ".", "server", ".", "ID", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "ns", ".", "subscribeToBindingsChannel", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// this handles remote messages", "for", "i", ":=", "0", ";", "i", "<", "ns", ".", "config", ".", "GetInt", "(", "\"", "\"", ")", ";", "i", "++", "{", "go", "ns", ".", "processMessages", "(", "i", ")", "\n", "}", "\n\n", "session", ".", "OnSessionBind", "(", "ns", ".", "onSessionBind", ")", "\n\n", "// this should be so fast that we shoudn't need concurrency", "go", "ns", ".", "processPushes", "(", ")", "\n", "go", "ns", ".", "processSessionBindings", "(", ")", "\n", "go", "ns", ".", "processKick", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", ".", "Method", ")", "\n", "}", "\n", "return", "r", ".", "Short", "(", ")", "\n", "}" ]
// 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.Errorf("invalid route: " + route) return nil, ErrInvalidRoute } }
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.Errorf("invalid route: " + route) return nil, ErrInvalidRoute } }
[ "func", "Decode", "(", "route", "string", ")", "(", "*", "Route", ",", "error", ")", "{", "r", ":=", "strings", ".", "Split", "(", "route", ",", "\"", "\"", ")", "\n", "for", "_", ",", "s", ":=", "range", "r", "{", "if", "strings", ".", "TrimSpace", "(", "s", ")", "==", "\"", "\"", "{", "return", "nil", ",", "ErrRouteFieldCantEmpty", "\n", "}", "\n", "}", "\n", "switch", "len", "(", "r", ")", "{", "case", "3", ":", "return", "NewRoute", "(", "r", "[", "0", "]", ",", "r", "[", "1", "]", ",", "r", "[", "2", "]", ")", ",", "nil", "\n", "case", "2", ":", "return", "NewRoute", "(", "\"", "\"", ",", "r", "[", "0", "]", ",", "r", "[", "1", "]", ")", ",", "nil", "\n", "default", ":", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", "+", "route", ")", "\n", "return", "nil", ",", "ErrInvalidRoute", "\n", "}", "\n", "}" ]
// 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) } return messages.OKResponse(), nil }
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) } return messages.OKResponse(), nil }
[ "func", "(", "*", "Room", ")", "SetCounter", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetCounterArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n", "for", "_", ",", "reporter", ":=", "range", "pitaya", ".", "GetMetricsReporters", "(", ")", "{", "reporter", ".", "ReportCount", "(", "counterMetricName", ",", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "arg", ".", "Tag1", ",", "\"", "\"", ":", "arg", ".", "Tag2", ",", "}", ",", "arg", ".", "Value", ")", "\n", "}", "\n\n", "return", "messages", ".", "OKResponse", "(", ")", ",", "nil", "\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.OKResponse(), nil }
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.OKResponse(), nil }
[ "func", "(", "*", "Room", ")", "SetGauge1", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetGaugeArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n", "for", "_", ",", "reporter", ":=", "range", "pitaya", ".", "GetMetricsReporters", "(", ")", "{", "reporter", ".", "ReportGauge", "(", "counterMetricName", ",", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "arg", ".", "Tag", ",", "}", ",", "arg", ".", "Value", ")", "\n", "}", "\n\n", "return", "messages", ".", "OKResponse", "(", ")", ",", "nil", "\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 messages.OKResponse(), nil }
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 messages.OKResponse(), nil }
[ "func", "(", "*", "Room", ")", "SetSummary", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "messages", ".", "SetSummaryArg", ",", ")", "(", "*", "messages", ".", "Response", ",", "error", ")", "{", "counterMetricName", ":=", "\"", "\"", "\n\n", "for", "_", ",", "reporter", ":=", "range", "pitaya", ".", "GetMetricsReporters", "(", ")", "{", "reporter", ".", "ReportSummary", "(", "counterMetricName", ",", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "arg", ".", "Tag", ",", "}", ",", "arg", ".", "Value", ")", "\n", "}", "\n\n", "return", "messages", ".", "OKResponse", "(", ")", ",", "nil", "\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: make(map[string]*component.Service), rpcClient: rpcClient, rpcServer: rpcServer, encoder: encoder, serviceDiscovery: sd, serializer: serializer, router: router, messageEncoder: messageEncoder, server: server, remoteBindingListeners: make([]cluster.RemoteBindingListener, 0), } }
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: make(map[string]*component.Service), rpcClient: rpcClient, rpcServer: rpcServer, encoder: encoder, serviceDiscovery: sd, serializer: serializer, router: router, messageEncoder: messageEncoder, server: server, remoteBindingListeners: make([]cluster.RemoteBindingListener, 0), } }
[ "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", ":", "make", "(", "map", "[", "string", "]", "*", "component", ".", "Service", ")", ",", "rpcClient", ":", "rpcClient", ",", "rpcServer", ":", "rpcServer", ",", "encoder", ":", "encoder", ",", "serviceDiscovery", ":", "sd", ",", "serializer", ":", "serializer", ",", "router", ":", "router", ",", "messageEncoder", ":", "messageEncoder", ",", "server", ":", "server", ",", "remoteBindingListeners", ":", "make", "(", "[", "]", "cluster", ".", "RemoteBindingListener", ",", "0", ")", ",", "}", "\n", "}" ]
// 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", ")", "\n", "}" ]
// 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 { res = processRemoteMessage(c, req, r) } if res.Error != nil { err = errors.New(res.Error.Msg) } defer tracing.FinishSpan(c, err) return res, nil }
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 { res = processRemoteMessage(c, req, r) } if res.Error != nil { err = errors.New(res.Error.Msg) } defer tracing.FinishSpan(c, err) return res, nil }
[ "func", "(", "r", "*", "RemoteService", ")", "Call", "(", "ctx", "context", ".", "Context", ",", "req", "*", "protos", ".", "Request", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "c", ",", "err", ":=", "util", ".", "GetContextFromRequest", "(", "req", ",", "r", ".", "server", ".", "ID", ")", "\n", "var", "res", "*", "protos", ".", "Response", "\n", "if", "err", "!=", "nil", "{", "res", "=", "&", "protos", ".", "Response", "{", "Error", ":", "&", "protos", ".", "Error", "{", "Code", ":", "e", ".", "ErrInternalCode", ",", "Msg", ":", "err", ".", "Error", "(", ")", ",", "}", ",", "}", "\n", "}", "else", "{", "res", "=", "processRemoteMessage", "(", "c", ",", "req", ",", "r", ")", "\n", "}", "\n\n", "if", "res", ".", "Error", "!=", "nil", "{", "err", "=", "errors", ".", "New", "(", "res", ".", "Error", ".", "Msg", ")", "\n", "}", "\n\n", "defer", "tracing", ".", "FinishSpan", "(", "c", ",", "err", ")", "\n", "return", "res", ",", "nil", "\n", "}" ]
// 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", "r", ".", "remoteBindingListeners", "{", "r", ".", "OnUserBind", "(", "msg", ".", "Uid", ",", "msg", ".", "Fid", ")", "\n", "}", "\n", "return", "&", "protos", ".", "Response", "{", "Data", ":", "[", "]", "byte", "(", "\"", "\"", ")", ",", "}", ",", "nil", "\n", "}" ]
// 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, err } return &protos.Response{ Data: []byte("ack"), }, nil } return nil, constants.ErrSessionNotFound }
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, err } return &protos.Response{ Data: []byte("ack"), }, nil } return nil, constants.ErrSessionNotFound }
[ "func", "(", "r", "*", "RemoteService", ")", "PushToUser", "(", "ctx", "context", ".", "Context", ",", "push", "*", "protos", ".", "Push", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "push", ".", "GetUid", "(", ")", ",", "string", "(", "push", ".", "Data", ")", ")", "\n", "s", ":=", "session", ".", "GetSessionByUID", "(", "push", ".", "GetUid", "(", ")", ")", "\n", "if", "s", "!=", "nil", "{", "err", ":=", "s", ".", "Push", "(", "push", ".", "Route", ",", "push", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "protos", ".", "Response", "{", "Data", ":", "[", "]", "byte", "(", "\"", "\"", ")", ",", "}", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "constants", ".", "ErrSessionNotFound", "\n", "}" ]
// 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.KickAnswer{ Kicked: true, }, nil } return nil, constants.ErrSessionNotFound }
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.KickAnswer{ Kicked: true, }, nil } return nil, constants.ErrSessionNotFound }
[ "func", "(", "r", "*", "RemoteService", ")", "KickUser", "(", "ctx", "context", ".", "Context", ",", "kick", "*", "protos", ".", "KickMsg", ")", "(", "*", "protos", ".", "KickAnswer", ",", "error", ")", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "kick", ".", "GetUserId", "(", ")", ")", "\n", "s", ":=", "session", ".", "GetSessionByUID", "(", "kick", ".", "GetUserId", "(", ")", ")", "\n", "if", "s", "!=", "nil", "{", "err", ":=", "s", ".", "Kick", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "protos", ".", "KickAnswer", "{", "Kicked", ":", "true", ",", "}", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "constants", ".", "ErrSessionNotFound", "\n", "}" ]
// 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 == nil { return nil, constants.ErrServerNotFound } return r.remoteCall(ctx, target, protos.RPCType_User, route, nil, msg) }
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 == nil { return nil, constants.ErrServerNotFound } return r.remoteCall(ctx, target, protos.RPCType_User, route, nil, msg) }
[ "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", ",", "}", "\n\n", "target", ",", "_", ":=", "r", ".", "serviceDiscovery", ".", "GetServer", "(", "serverID", ")", "\n", "if", "serverID", "!=", "\"", "\"", "&&", "target", "==", "nil", "{", "return", "nil", ",", "constants", ".", "ErrServerNotFound", "\n", "}", "\n\n", "return", "r", ".", "remoteCall", "(", "ctx", ",", "target", ",", "protos", ".", "RPCType_User", ",", "route", ",", "nil", ",", "msg", ")", "\n", "}" ]
// 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 { return err } if res.Error != nil { return &e.Error{ Code: res.Error.Code, Message: res.Error.Msg, Metadata: res.Error.Metadata, } } if reply != nil { err = proto.Unmarshal(res.GetData(), reply) if err != nil { return err } } return 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 { return err } if res.Error != nil { return &e.Error{ Code: res.Error.Code, Message: res.Error.Msg, Metadata: res.Error.Metadata, } } if reply != nil { err = proto.Unmarshal(res.GetData(), reply) if err != nil { return err } } return nil }
[ "func", "(", "r", "*", "RemoteService", ")", "RPC", "(", "ctx", "context", ".", "Context", ",", "serverID", "string", ",", "route", "*", "route", ".", "Route", ",", "reply", "proto", ".", "Message", ",", "arg", "proto", ".", "Message", ")", "error", "{", "var", "data", "[", "]", "byte", "\n", "var", "err", "error", "\n", "if", "arg", "!=", "nil", "{", "data", ",", "err", "=", "proto", ".", "Marshal", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "res", ",", "err", ":=", "r", ".", "DoRPC", "(", "ctx", ",", "serverID", ",", "route", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "res", ".", "Error", "!=", "nil", "{", "return", "&", "e", ".", "Error", "{", "Code", ":", "res", ".", "Error", ".", "Code", ",", "Message", ":", "res", ".", "Error", ".", "Msg", ",", "Metadata", ":", "res", ".", "Error", ".", "Metadata", ",", "}", "\n", "}", "\n\n", "if", "reply", "!=", "nil", "{", "err", "=", "proto", ".", "Unmarshal", "(", "res", ".", "GetData", "(", ")", ",", "reply", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "}", "{", "}", ",", "nil", "\n", "}", "\n", "return", "docgenerator", ".", "RemotesDocs", "(", "r", ".", "server", ".", "Type", ",", "r", ".", "services", ",", "getPtrNames", ")", "\n", "}" ]
// 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) { return false } if mt.NumIn() == 3 { if t2 := mt.In(2); !t2.Implements(typeOfProtoMsg) { return false } } // Method needs two outs: interface{}(that implements proto.Message), error if mt.NumOut() != 2 { return false } if (mt.Out(0).Kind() != reflect.Ptr) || mt.Out(1) != typeOfError { return false } if o0 := mt.Out(0); !o0.Implements(typeOfProtoMsg) { return false } return true }
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) { return false } if mt.NumIn() == 3 { if t2 := mt.In(2); !t2.Implements(typeOfProtoMsg) { return false } } // Method needs two outs: interface{}(that implements proto.Message), error if mt.NumOut() != 2 { return false } if (mt.Out(0).Kind() != reflect.Ptr) || mt.Out(1) != typeOfError { return false } if o0 := mt.Out(0); !o0.Implements(typeOfProtoMsg) { return false } return true }
[ "func", "isRemoteMethod", "(", "method", "reflect", ".", "Method", ")", "bool", "{", "mt", ":=", "method", ".", "Type", "\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "// Method needs at least two ins: receiver and context.Context", "if", "mt", ".", "NumIn", "(", ")", "!=", "2", "&&", "mt", ".", "NumIn", "(", ")", "!=", "3", "{", "return", "false", "\n", "}", "\n\n", "if", "t1", ":=", "mt", ".", "In", "(", "1", ")", ";", "!", "t1", ".", "Implements", "(", "typeOfContext", ")", "{", "return", "false", "\n", "}", "\n\n", "if", "mt", ".", "NumIn", "(", ")", "==", "3", "{", "if", "t2", ":=", "mt", ".", "In", "(", "2", ")", ";", "!", "t2", ".", "Implements", "(", "typeOfProtoMsg", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "// Method needs two outs: interface{}(that implements proto.Message), error", "if", "mt", ".", "NumOut", "(", ")", "!=", "2", "{", "return", "false", "\n", "}", "\n\n", "if", "(", "mt", ".", "Out", "(", "0", ")", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", ")", "||", "mt", ".", "Out", "(", "1", ")", "!=", "typeOfError", "{", "return", "false", "\n", "}", "\n\n", "if", "o0", ":=", "mt", ".", "Out", "(", "0", ")", ";", "!", "o0", ".", "Implements", "(", "typeOfProtoMsg", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// 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); !t1.Implements(typeOfContext) { return false } if mt.NumIn() == 3 && mt.In(2).Kind() != reflect.Ptr && mt.In(2) != typeOfBytes { return false } // Method needs either no out or two outs: interface{}(or []byte), error if mt.NumOut() != 0 && mt.NumOut() != 2 { return false } if mt.NumOut() == 2 && (mt.Out(1) != typeOfError || mt.Out(0) != typeOfBytes && mt.Out(0).Kind() != reflect.Ptr) { return false } return true }
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); !t1.Implements(typeOfContext) { return false } if mt.NumIn() == 3 && mt.In(2).Kind() != reflect.Ptr && mt.In(2) != typeOfBytes { return false } // Method needs either no out or two outs: interface{}(or []byte), error if mt.NumOut() != 0 && mt.NumOut() != 2 { return false } if mt.NumOut() == 2 && (mt.Out(1) != typeOfError || mt.Out(0) != typeOfBytes && mt.Out(0).Kind() != reflect.Ptr) { return false } return true }
[ "func", "isHandlerMethod", "(", "method", "reflect", ".", "Method", ")", "bool", "{", "mt", ":=", "method", ".", "Type", "\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "// Method needs two or three ins: receiver, context.Context and optional []byte or pointer.", "if", "mt", ".", "NumIn", "(", ")", "!=", "2", "&&", "mt", ".", "NumIn", "(", ")", "!=", "3", "{", "return", "false", "\n", "}", "\n\n", "if", "t1", ":=", "mt", ".", "In", "(", "1", ")", ";", "!", "t1", ".", "Implements", "(", "typeOfContext", ")", "{", "return", "false", "\n", "}", "\n\n", "if", "mt", ".", "NumIn", "(", ")", "==", "3", "&&", "mt", ".", "In", "(", "2", ")", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "&&", "mt", ".", "In", "(", "2", ")", "!=", "typeOfBytes", "{", "return", "false", "\n", "}", "\n\n", "// Method needs either no out or two outs: interface{}(or []byte), error", "if", "mt", ".", "NumOut", "(", ")", "!=", "0", "&&", "mt", ".", "NumOut", "(", ")", "!=", "2", "{", "return", "false", "\n", "}", "\n\n", "if", "mt", ".", "NumOut", "(", ")", "==", "2", "&&", "(", "mt", ".", "Out", "(", "1", ")", "!=", "typeOfError", "||", "mt", ".", "Out", "(", "0", ")", "!=", "typeOfBytes", "&&", "mt", ".", "Out", "(", "0", ")", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// 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{Data: []byte("ack")}, nil }
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{Data: []byte("ack")}, nil }
[ "func", "(", "s", "*", "Sys", ")", "BindSession", "(", "ctx", "context", ".", "Context", ",", "sessionData", "*", "protos", ".", "Session", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "sess", ":=", "session", ".", "GetSessionByID", "(", "sessionData", ".", "Id", ")", "\n", "if", "sess", "==", "nil", "{", "return", "nil", ",", "constants", ".", "ErrSessionNotFound", "\n", "}", "\n", "if", "err", ":=", "sess", ".", "Bind", "(", "ctx", ",", "sessionData", ".", "Uid", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "protos", ".", "Response", "{", "Data", ":", "[", "]", "byte", "(", "\"", "\"", ")", "}", ",", "nil", "\n", "}" ]
// 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.Kicked = true return res, nil }
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.Kicked = true return res, nil }
[ "func", "(", "s", "*", "Sys", ")", "Kick", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "protos", ".", "KickMsg", ")", "(", "*", "protos", ".", "KickAnswer", ",", "error", ")", "{", "res", ":=", "&", "protos", ".", "KickAnswer", "{", "Kicked", ":", "false", ",", "}", "\n", "sess", ":=", "session", ".", "GetSessionByUID", "(", "msg", ".", "GetUserId", "(", ")", ")", "\n", "if", "sess", "==", "nil", "{", "return", "res", ",", "constants", ".", "ErrSessionNotFound", "\n", "}", "\n", "err", ":=", "sess", ".", "Kick", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "res", ",", "err", "\n", "}", "\n", "res", ".", "Kicked", "=", "true", "\n", "return", "res", ",", "nil", "\n", "}" ]
// 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", "\"", ",", "message", ")", "\n", "return", "&", "protos", ".", "Response", "{", "Msg", ":", "string", "(", "message", ")", ",", "}", ",", "nil", "\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", "[", "name", "]", "=", "module", "\n", "modulesArr", "=", "append", "(", "modulesArr", ",", "moduleWrapper", "{", "module", ":", "module", ",", "name", ":", "name", ",", "}", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}" ]
// 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()) } } for _, modWrapper := range modulesArr { modWrapper.module.AfterInit() logger.Log.Infof("module: %s successfully loaded", modWrapper.name) } }
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()) } } for _, modWrapper := range modulesArr { modWrapper.module.AfterInit() logger.Log.Infof("module: %s successfully loaded", modWrapper.name) } }
[ "func", "startModules", "(", ")", "{", "logger", ".", "Log", ".", "Debug", "(", "\"", "\"", ")", "\n", "for", "_", ",", "modWrapper", ":=", "range", "modulesArr", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "modWrapper", ".", "name", ")", "\n", "if", "err", ":=", "modWrapper", ".", "module", ".", "Init", "(", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Fatalf", "(", "\"", "\"", ",", "modWrapper", ".", "name", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "modWrapper", ":=", "range", "modulesArr", "{", "modWrapper", ".", "module", ".", "AfterInit", "(", ")", "\n", "logger", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "modWrapper", ".", "name", ")", "\n", "}", "\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.Log.Warnf("error stopping module: %s", name) } logger.Log.Infof("module: %s stopped!", name) } }
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.Log.Warnf("error stopping module: %s", name) } logger.Log.Infof("module: %s stopped!", name) } }
[ "func", "shutdownModules", "(", ")", "{", "for", "i", ":=", "len", "(", "modulesArr", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "modulesArr", "[", "i", "]", ".", "module", ".", "BeforeShutdown", "(", ")", "\n", "}", "\n\n", "for", "i", ":=", "len", "(", "modulesArr", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "name", ":=", "modulesArr", "[", "i", "]", ".", "name", "\n", "mod", ":=", "modulesArr", "[", "i", "]", ".", "module", "\n\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "name", ")", "\n", "if", "err", ":=", "mod", ".", "Shutdown", "(", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Warnf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "logger", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "}" ]
// 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("pitaya.metrics.statsd.rate"), 64) if err != nil { return nil, err } sr := &StatsdReporter{ rate: rate, serverType: serverType, } sr.buildDefaultTags(tagsMap) if len(clientOrNil) > 0 { sr.client = clientOrNil[0] } else { c, err := statsd.New(host) if err != nil { return nil, err } c.Namespace = prefix sr.client = c } return sr, nil }
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("pitaya.metrics.statsd.rate"), 64) if err != nil { return nil, err } sr := &StatsdReporter{ rate: rate, serverType: serverType, } sr.buildDefaultTags(tagsMap) if len(clientOrNil) > 0 { sr.client = clientOrNil[0] } else { c, err := statsd.New(host) if err != nil { return nil, err } c.Namespace = prefix sr.client = c } return sr, nil }
[ "func", "NewStatsdReporter", "(", "config", "*", "config", ".", "Config", ",", "serverType", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "clientOrNil", "...", "Client", ",", ")", "(", "*", "StatsdReporter", ",", "error", ")", "{", "host", ":=", "config", ".", "GetString", "(", "\"", "\"", ")", "\n", "prefix", ":=", "config", ".", "GetString", "(", "\"", "\"", ")", "\n", "rate", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "config", ".", "GetString", "(", "\"", "\"", ")", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sr", ":=", "&", "StatsdReporter", "{", "rate", ":", "rate", ",", "serverType", ":", "serverType", ",", "}", "\n\n", "sr", ".", "buildDefaultTags", "(", "tagsMap", ")", "\n\n", "if", "len", "(", "clientOrNil", ")", ">", "0", "{", "sr", ".", "client", "=", "clientOrNil", "[", "0", "]", "\n", "}", "else", "{", "c", ",", "err", ":=", "statsd", ".", "New", "(", "host", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "Namespace", "=", "prefix", "\n", "sr", ".", "client", "=", "c", "\n", "}", "\n", "return", "sr", ",", "nil", "\n", "}" ]
// 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("failed to report count: %q", err) } return err }
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("failed to report count: %q", err) } return err }
[ "func", "(", "s", "*", "StatsdReporter", ")", "ReportCount", "(", "metric", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "count", "float64", ")", "error", "{", "fullTags", ":=", "s", ".", "defaultTags", "\n\n", "for", "k", ",", "v", ":=", "range", "tagsMap", "{", "fullTags", "=", "append", "(", "fullTags", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n\n", "err", ":=", "s", ".", "client", ".", "Count", "(", "metric", ",", "int64", "(", "count", ")", ",", "fullTags", ",", "s", ".", "rate", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// 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("failed to report gauge: %q", err) } return err }
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("failed to report gauge: %q", err) } return err }
[ "func", "(", "s", "*", "StatsdReporter", ")", "ReportGauge", "(", "metric", "string", ",", "tagsMap", "map", "[", "string", "]", "string", ",", "value", "float64", ")", "error", "{", "fullTags", ":=", "s", ".", "defaultTags", "\n\n", "for", "k", ",", "v", ":=", "range", "tagsMap", "{", "fullTags", "=", "append", "(", "fullTags", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n\n", "err", ":=", "s", ".", "client", ".", "Gauge", "(", "metric", ",", "value", ",", "fullTags", ",", "s", ".", "rate", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// 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", ")", "\n", "}" ]
// 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", ",", "v", ")", "\n\n", "members", ",", "err", ":=", "GroupMembers", "(", "ctx", ",", "groupName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "sendDataToMembers", "(", "members", ",", "frontendType", ",", "route", ",", "v", ")", "\n", "}" ]
// 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