id
int32
0
167k
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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
28,200
topfreegames/pitaya
component/service.go
ValidateMessageType
func (h *Handler) ValidateMessageType(msgType message.Type) (exitOnError bool, err error) { if h.MessageType != msgType { switch msgType { case message.Request: err = constants.ErrRequestOnNotify exitOnError = true case message.Notify: err = constants.ErrNotifyOnRequest } } return }
go
func (h *Handler) ValidateMessageType(msgType message.Type) (exitOnError bool, err error) { if h.MessageType != msgType { switch msgType { case message.Request: err = constants.ErrRequestOnNotify exitOnError = true case message.Notify: err = constants.ErrNotifyOnRequest } } return }
[ "func", "(", "h", "*", "Handler", ")", "ValidateMessageType", "(", "msgType", "message", ".", "Type", ")", "(", "exitOnError", "bool", ",", "err", "error", ")", "{", "if", "h", ".", "MessageType", "!=", "msgType", "{", "switch", "msgType", "{", "case", ...
// ValidateMessageType validates a given message type against the handler's one // and returns an error if it is a mismatch and a boolean indicating if the caller should // exit in the presence of this error or not.
[ "ValidateMessageType", "validates", "a", "given", "message", "type", "against", "the", "handler", "s", "one", "and", "returns", "an", "error", "if", "it", "is", "a", "mismatch", "and", "a", "boolean", "indicating", "if", "the", "caller", "should", "exit", "i...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/component/service.go#L161-L173
28,201
topfreegames/pitaya
examples/demo/cluster_protobuf/services/room.go
Init
func (r *Room) Init() { gsi := groups.NewMemoryGroupService(config.NewConfig()) pitaya.InitGroups(gsi) pitaya.GroupCreate(context.Background(), "room") }
go
func (r *Room) Init() { gsi := groups.NewMemoryGroupService(config.NewConfig()) pitaya.InitGroups(gsi) pitaya.GroupCreate(context.Background(), "room") }
[ "func", "(", "r", "*", "Room", ")", "Init", "(", ")", "{", "gsi", ":=", "groups", ".", "NewMemoryGroupService", "(", "config", ".", "NewConfig", "(", ")", ")", "\n", "pitaya", ".", "InitGroups", "(", "gsi", ")", "\n", "pitaya", ".", "GroupCreate", "(...
// Init runs on service initialization
[ "Init", "runs", "on", "service", "initialization" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_protobuf/services/room.go#L53-L57
28,202
topfreegames/pitaya
tracing/log.go
LogError
func LogError(span opentracing.Span, message string) { span.SetTag("error", true) span.LogFields( log.String("event", "error"), log.String("message", message), ) }
go
func LogError(span opentracing.Span, message string) { span.SetTag("error", true) span.LogFields( log.String("event", "error"), log.String("message", message), ) }
[ "func", "LogError", "(", "span", "opentracing", ".", "Span", ",", "message", "string", ")", "{", "span", ".", "SetTag", "(", "\"", "\"", ",", "true", ")", "\n", "span", ".", "LogFields", "(", "log", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ...
// LogError logs an error to an opentracing span
[ "LogError", "logs", "an", "error", "to", "an", "opentracing", "span" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/tracing/log.go#L31-L37
28,203
topfreegames/pitaya
cluster/nats_rpc_client.go
BroadcastSessionBind
func (ns *NatsRPCClient) BroadcastSessionBind(uid string) error { msg := &protos.BindMsg{ Uid: uid, Fid: ns.server.ID, } msgData, err := proto.Marshal(msg) if err != nil { return err } return ns.Send(GetBindBroadcastTopic(ns.server.Type), msgData) }
go
func (ns *NatsRPCClient) BroadcastSessionBind(uid string) error { msg := &protos.BindMsg{ Uid: uid, Fid: ns.server.ID, } msgData, err := proto.Marshal(msg) if err != nil { return err } return ns.Send(GetBindBroadcastTopic(ns.server.Type), msgData) }
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "BroadcastSessionBind", "(", "uid", "string", ")", "error", "{", "msg", ":=", "&", "protos", ".", "BindMsg", "{", "Uid", ":", "uid", ",", "Fid", ":", "ns", ".", "server", ".", "ID", ",", "}", "\n", "msg...
// BroadcastSessionBind sends the binding information to other servers that may br interested in this info
[ "BroadcastSessionBind", "sends", "the", "binding", "information", "to", "other", "servers", "that", "may", "br", "interested", "in", "this", "info" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L91-L101
28,204
topfreegames/pitaya
cluster/nats_rpc_client.go
Send
func (ns *NatsRPCClient) Send(topic string, data []byte) error { if !ns.running { return constants.ErrRPCClientNotInitialized } return ns.conn.Publish(topic, data) }
go
func (ns *NatsRPCClient) Send(topic string, data []byte) error { if !ns.running { return constants.ErrRPCClientNotInitialized } return ns.conn.Publish(topic, data) }
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "Send", "(", "topic", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "if", "!", "ns", ".", "running", "{", "return", "constants", ".", "ErrRPCClientNotInitialized", "\n", "}", "\n", "return", "...
// Send publishes a message in a given topic
[ "Send", "publishes", "a", "message", "in", "a", "given", "topic" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L104-L109
28,205
topfreegames/pitaya
cluster/nats_rpc_client.go
SendPush
func (ns *NatsRPCClient) SendPush(userID string, frontendSv *Server, push *protos.Push) error { topic := GetUserMessagesTopic(userID, frontendSv.Type) msg, err := proto.Marshal(push) if err != nil { return err } return ns.Send(topic, msg) }
go
func (ns *NatsRPCClient) SendPush(userID string, frontendSv *Server, push *protos.Push) error { topic := GetUserMessagesTopic(userID, frontendSv.Type) msg, err := proto.Marshal(push) if err != nil { return err } return ns.Send(topic, msg) }
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "SendPush", "(", "userID", "string", ",", "frontendSv", "*", "Server", ",", "push", "*", "protos", ".", "Push", ")", "error", "{", "topic", ":=", "GetUserMessagesTopic", "(", "userID", ",", "frontendSv", ".", ...
// SendPush sends a message to a user
[ "SendPush", "sends", "a", "message", "to", "a", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L112-L119
28,206
topfreegames/pitaya
cluster/nats_rpc_client.go
SendKick
func (ns *NatsRPCClient) SendKick(userID string, serverType string, kick *protos.KickMsg) error { topic := GetUserKickTopic(userID, serverType) msg, err := proto.Marshal(kick) if err != nil { return err } return ns.Send(topic, msg) }
go
func (ns *NatsRPCClient) SendKick(userID string, serverType string, kick *protos.KickMsg) error { topic := GetUserKickTopic(userID, serverType) msg, err := proto.Marshal(kick) if err != nil { return err } return ns.Send(topic, msg) }
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "SendKick", "(", "userID", "string", ",", "serverType", "string", ",", "kick", "*", "protos", ".", "KickMsg", ")", "error", "{", "topic", ":=", "GetUserKickTopic", "(", "userID", ",", "serverType", ")", "\n", ...
// SendKick kicks an user
[ "SendKick", "kicks", "an", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L122-L129
28,207
topfreegames/pitaya
cluster/nats_rpc_client.go
Call
func (ns *NatsRPCClient) 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...
go
func (ns *NatsRPCClient) 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...
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "Call", "(", "ctx", "context", ".", "Context", ",", "rpcType", "protos", ".", "RPCType", ",", "route", "*", "route", ".", "Route", ",", "session", "*", "session", ".", "Session", ",", "msg", "*", "message",...
// Call calls a method remotelly
[ "Call", "calls", "a", "method", "remotelly" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L132-L200
28,208
topfreegames/pitaya
cluster/nats_rpc_client.go
Init
func (ns *NatsRPCClient) Init() error { ns.running = true conn, err := setupNatsConn(ns.connString, ns.appDieChan, nats.MaxReconnects(ns.maxReconnectionRetries)) if err != nil { return err } ns.conn = conn return nil }
go
func (ns *NatsRPCClient) Init() error { ns.running = true conn, err := setupNatsConn(ns.connString, ns.appDieChan, nats.MaxReconnects(ns.maxReconnectionRetries)) if err != nil { return err } ns.conn = conn return nil }
[ "func", "(", "ns", "*", "NatsRPCClient", ")", "Init", "(", ")", "error", "{", "ns", ".", "running", "=", "true", "\n", "conn", ",", "err", ":=", "setupNatsConn", "(", "ns", ".", "connString", ",", "ns", ".", "appDieChan", ",", "nats", ".", "MaxReconn...
// Init inits nats rpc client
[ "Init", "inits", "nats", "rpc", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/nats_rpc_client.go#L203-L211
28,209
topfreegames/pitaya
agent/agent_remote.go
NewRemote
func NewRemote( sess *protos.Session, reply string, rpcClient cluster.RPCClient, encoder codec.PacketEncoder, serializer serialize.Serializer, serviceDiscovery cluster.ServiceDiscovery, frontendID string, messageEncoder message.Encoder, ) (*Remote, error) { a := &Remote{ chDie: make(chan struct{})...
go
func NewRemote( sess *protos.Session, reply string, rpcClient cluster.RPCClient, encoder codec.PacketEncoder, serializer serialize.Serializer, serviceDiscovery cluster.ServiceDiscovery, frontendID string, messageEncoder message.Encoder, ) (*Remote, error) { a := &Remote{ chDie: make(chan struct{})...
[ "func", "NewRemote", "(", "sess", "*", "protos", ".", "Session", ",", "reply", "string", ",", "rpcClient", "cluster", ".", "RPCClient", ",", "encoder", "codec", ".", "PacketEncoder", ",", "serializer", "serialize", ".", "Serializer", ",", "serviceDiscovery", "...
// NewRemote create new Remote instance
[ "NewRemote", "create", "new", "Remote", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent_remote.go#L56-L87
28,210
topfreegames/pitaya
agent/agent_remote.go
Push
func (a *Remote) Push(route string, v interface{}) error { if (reflect.TypeOf(a.rpcClient) == reflect.TypeOf(&cluster.NatsRPCClient{}) && a.Session.UID() == "") { return constants.ErrNoUIDBind } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Push, ID=%d, UID=%d, Route=%s, Data=%dbytes", a.Sess...
go
func (a *Remote) Push(route string, v interface{}) error { if (reflect.TypeOf(a.rpcClient) == reflect.TypeOf(&cluster.NatsRPCClient{}) && a.Session.UID() == "") { return constants.ErrNoUIDBind } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Push, ID=%d, UID=%d, Route=%s, Data=%dbytes", a.Sess...
[ "func", "(", "a", "*", "Remote", ")", "Push", "(", "route", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "(", "reflect", ".", "TypeOf", "(", "a", ".", "rpcClient", ")", "==", "reflect", ".", "TypeOf", "(", "&", "cluster", "...
// Push pushes the message to the user
[ "Push", "pushes", "the", "message", "to", "the", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent_remote.go#L105-L127
28,211
topfreegames/pitaya
agent/agent_remote.go
ResponseMID
func (a *Remote) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { err := false if len(isError) > 0 { err = isError[0] } if mid <= 0 { return constants.ErrSessionOnNotify } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Response, ID=%d, MID=%d, Data=%dbytes",...
go
func (a *Remote) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { err := false if len(isError) > 0 { err = isError[0] } if mid <= 0 { return constants.ErrSessionOnNotify } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Response, ID=%d, MID=%d, Data=%dbytes",...
[ "func", "(", "a", "*", "Remote", ")", "ResponseMID", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "v", "interface", "{", "}", ",", "isError", "...", "bool", ")", "error", "{", "err", ":=", "false", "\n", "if", "len", "(", "isErro...
// ResponseMID reponds the message with mid to the user
[ "ResponseMID", "reponds", "the", "message", "with", "mid", "to", "the", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent_remote.go#L130-L150
28,212
topfreegames/pitaya
errors/errors.go
CodeFromError
func CodeFromError(err error) string { if err == nil { return "" } pitayaErr, ok := err.(*Error) if !ok { return ErrUnknownCode } if pitayaErr == nil { return "" } return pitayaErr.Code }
go
func CodeFromError(err error) string { if err == nil { return "" } pitayaErr, ok := err.(*Error) if !ok { return ErrUnknownCode } if pitayaErr == nil { return "" } return pitayaErr.Code }
[ "func", "CodeFromError", "(", "err", "error", ")", "string", "{", "if", "err", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "pitayaErr", ",", "ok", ":=", "err", ".", "(", "*", "Error", ")", "\n", "if", "!", "ok", "{", "return", "Err...
// CodeFromError returns the code of error. // If error is nil, return empty string. // If error is not a pitaya error, returns unkown code
[ "CodeFromError", "returns", "the", "code", "of", "error", ".", "If", "error", "is", "nil", "return", "empty", "string", ".", "If", "error", "is", "not", "a", "pitaya", "error", "returns", "unkown", "code" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/errors/errors.go#L81-L96
28,213
topfreegames/pitaya
timer.go
NewTimer
func NewTimer(interval time.Duration, fn timer.Func) *timer.Timer { return NewCountTimer(interval, timer.LoopForever, fn) }
go
func NewTimer(interval time.Duration, fn timer.Func) *timer.Timer { return NewCountTimer(interval, timer.LoopForever, fn) }
[ "func", "NewTimer", "(", "interval", "time", ".", "Duration", ",", "fn", "timer", ".", "Func", ")", "*", "timer", ".", "Timer", "{", "return", "NewCountTimer", "(", "interval", ",", "timer", ".", "LoopForever", ",", "fn", ")", "\n", "}" ]
// NewTimer returns a new Timer containing a function that will be called // with a period specified by the duration argument. It adjusts the intervals // for slow receivers. // The duration d must be greater than zero; if not, NewTimer will panic. // Stop the timer to release associated resources.
[ "NewTimer", "returns", "a", "new", "Timer", "containing", "a", "function", "that", "will", "be", "called", "with", "a", "period", "specified", "by", "the", "duration", "argument", ".", "It", "adjusts", "the", "intervals", "for", "slow", "receivers", ".", "Th...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer.go#L36-L38
28,214
topfreegames/pitaya
timer.go
NewCountTimer
func NewCountTimer(interval time.Duration, count int, fn timer.Func) *timer.Timer { if fn == nil { panic("pitaya/timer: nil timer function") } if interval <= 0 { panic("non-positive interval for NewTimer") } t := timer.NewTimer(fn, interval, count) // add to manager timer.Manager.ChCreatedTimer <- t return...
go
func NewCountTimer(interval time.Duration, count int, fn timer.Func) *timer.Timer { if fn == nil { panic("pitaya/timer: nil timer function") } if interval <= 0 { panic("non-positive interval for NewTimer") } t := timer.NewTimer(fn, interval, count) // add to manager timer.Manager.ChCreatedTimer <- t return...
[ "func", "NewCountTimer", "(", "interval", "time", ".", "Duration", ",", "count", "int", ",", "fn", "timer", ".", "Func", ")", "*", "timer", ".", "Timer", "{", "if", "fn", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "in...
// NewCountTimer returns a new Timer containing a function that will be called // with a period specified by the duration argument. After count times, timer // will be stopped automatically, It adjusts the intervals for slow receivers. // The duration d must be greater than zero; if not, NewCountTimer will panic. // St...
[ "NewCountTimer", "returns", "a", "new", "Timer", "containing", "a", "function", "that", "will", "be", "called", "with", "a", "period", "specified", "by", "the", "duration", "argument", ".", "After", "count", "times", "timer", "will", "be", "stopped", "automati...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer.go#L45-L57
28,215
topfreegames/pitaya
timer.go
NewAfterTimer
func NewAfterTimer(duration time.Duration, fn timer.Func) *timer.Timer { return NewCountTimer(duration, 1, fn) }
go
func NewAfterTimer(duration time.Duration, fn timer.Func) *timer.Timer { return NewCountTimer(duration, 1, fn) }
[ "func", "NewAfterTimer", "(", "duration", "time", ".", "Duration", ",", "fn", "timer", ".", "Func", ")", "*", "timer", ".", "Timer", "{", "return", "NewCountTimer", "(", "duration", ",", "1", ",", "fn", ")", "\n", "}" ]
// NewAfterTimer returns a new Timer containing a function that will be called // after duration that specified by the duration argument. // The duration d must be greater than zero; if not, NewAfterTimer will panic. // Stop the timer to release associated resources.
[ "NewAfterTimer", "returns", "a", "new", "Timer", "containing", "a", "function", "that", "will", "be", "called", "after", "duration", "that", "specified", "by", "the", "duration", "argument", ".", "The", "duration", "d", "must", "be", "greater", "than", "zero",...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer.go#L63-L65
28,216
topfreegames/pitaya
timer.go
NewCondTimer
func NewCondTimer(condition timer.Condition, fn timer.Func) (*timer.Timer, error) { if condition == nil { return nil, constants.ErrNilCondition } t := NewCountTimer(time.Duration(math.MaxInt64), timer.LoopForever, fn) t.SetCondition(condition) return t, nil }
go
func NewCondTimer(condition timer.Condition, fn timer.Func) (*timer.Timer, error) { if condition == nil { return nil, constants.ErrNilCondition } t := NewCountTimer(time.Duration(math.MaxInt64), timer.LoopForever, fn) t.SetCondition(condition) return t, nil }
[ "func", "NewCondTimer", "(", "condition", "timer", ".", "Condition", ",", "fn", "timer", ".", "Func", ")", "(", "*", "timer", ".", "Timer", ",", "error", ")", "{", "if", "condition", "==", "nil", "{", "return", "nil", ",", "constants", ".", "ErrNilCond...
// NewCondTimer returns a new Timer containing a function that will be called // when condition satisfied that specified by the condition argument. // The duration d must be greater than zero; if not, NewCondTimer will panic. // Stop the timer to release associated resources.
[ "NewCondTimer", "returns", "a", "new", "Timer", "containing", "a", "function", "that", "will", "be", "called", "when", "condition", "satisfied", "that", "specified", "by", "the", "condition", "argument", ".", "The", "duration", "d", "must", "be", "greater", "t...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer.go#L71-L79
28,217
topfreegames/pitaya
timer.go
SetTimerPrecision
func SetTimerPrecision(precision time.Duration) { if precision < time.Millisecond { panic("time precision can not less than a Millisecond") } timer.Precision = precision }
go
func SetTimerPrecision(precision time.Duration) { if precision < time.Millisecond { panic("time precision can not less than a Millisecond") } timer.Precision = precision }
[ "func", "SetTimerPrecision", "(", "precision", "time", ".", "Duration", ")", "{", "if", "precision", "<", "time", ".", "Millisecond", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "timer", ".", "Precision", "=", "precision", "\n", "}" ]
// SetTimerPrecision set the ticker precision, and time precision can not less // than a Millisecond, and can not change after application running. The default // precision is time.Second
[ "SetTimerPrecision", "set", "the", "ticker", "precision", "and", "time", "precision", "can", "not", "less", "than", "a", "Millisecond", "and", "can", "not", "change", "after", "application", "running", ".", "The", "default", "precision", "is", "time", ".", "Se...
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/timer.go#L84-L89
28,218
topfreegames/pitaya
examples/demo/cluster/services/connector.go
NotifySessionData
func (c *Connector) NotifySessionData(ctx context.Context, data *SessionData) { s := pitaya.GetSessionFromCtx(ctx) err := s.SetData(data.Data) if err != nil { fmt.Println("got error on notify", err) } }
go
func (c *Connector) NotifySessionData(ctx context.Context, data *SessionData) { s := pitaya.GetSessionFromCtx(ctx) err := s.SetData(data.Data) if err != nil { fmt.Println("got error on notify", err) } }
[ "func", "(", "c", "*", "Connector", ")", "NotifySessionData", "(", "ctx", "context", ".", "Context", ",", "data", "*", "SessionData", ")", "{", "s", ":=", "pitaya", ".", "GetSessionFromCtx", "(", "ctx", ")", "\n", "err", ":=", "s", ".", "SetData", "(",...
// NotifySessionData sets the session data
[ "NotifySessionData", "sets", "the", "session", "data" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster/services/connector.go#L62-L68
28,219
topfreegames/pitaya
examples/demo/cluster/services/connector.go
Docs
func (c *ConnectorRemote) Docs(ctx context.Context, ddd *protos.Doc) (*protos.Doc, error) { d, err := pitaya.Documentation(true) if err != nil { return nil, err } doc, err := json.Marshal(d) if err != nil { return nil, err } return &protos.Doc{Doc: string(doc)}, nil }
go
func (c *ConnectorRemote) Docs(ctx context.Context, ddd *protos.Doc) (*protos.Doc, error) { d, err := pitaya.Documentation(true) if err != nil { return nil, err } doc, err := json.Marshal(d) if err != nil { return nil, err } return &protos.Doc{Doc: string(doc)}, nil }
[ "func", "(", "c", "*", "ConnectorRemote", ")", "Docs", "(", "ctx", "context", ".", "Context", ",", "ddd", "*", "protos", ".", "Doc", ")", "(", "*", "protos", ".", "Doc", ",", "error", ")", "{", "d", ",", "err", ":=", "pitaya", ".", "Documentation",...
// Docs returns documentation
[ "Docs", "returns", "documentation" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster/services/connector.go#L79-L91
28,220
topfreegames/pitaya
acceptor/tcp_acceptor.go
NewTCPAcceptor
func NewTCPAcceptor(addr string, certs ...string) *TCPAcceptor { keyFile := "" certFile := "" if len(certs) != 2 && len(certs) != 0 { panic(constants.ErrInvalidCertificates) } else if len(certs) == 2 { certFile = certs[0] keyFile = certs[1] } return &TCPAcceptor{ addr: addr, connChan: make(chan net...
go
func NewTCPAcceptor(addr string, certs ...string) *TCPAcceptor { keyFile := "" certFile := "" if len(certs) != 2 && len(certs) != 0 { panic(constants.ErrInvalidCertificates) } else if len(certs) == 2 { certFile = certs[0] keyFile = certs[1] } return &TCPAcceptor{ addr: addr, connChan: make(chan net...
[ "func", "NewTCPAcceptor", "(", "addr", "string", ",", "certs", "...", "string", ")", "*", "TCPAcceptor", "{", "keyFile", ":=", "\"", "\"", "\n", "certFile", ":=", "\"", "\"", "\n", "if", "len", "(", "certs", ")", "!=", "2", "&&", "len", "(", "certs",...
// NewTCPAcceptor creates a new instance of tcp acceptor
[ "NewTCPAcceptor", "creates", "a", "new", "instance", "of", "tcp", "acceptor" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/tcp_acceptor.go#L42-L59
28,221
topfreegames/pitaya
acceptor/tcp_acceptor.go
ListenAndServe
func (a *TCPAcceptor) ListenAndServe() { if a.hasTLSCertificates() { a.ListenAndServeTLS(a.certFile, a.keyFile) return } listener, err := net.Listen("tcp", a.addr) if err != nil { logger.Log.Fatalf("Failed to listen: %s", err.Error()) } a.listener = listener a.running = true a.serve() }
go
func (a *TCPAcceptor) ListenAndServe() { if a.hasTLSCertificates() { a.ListenAndServeTLS(a.certFile, a.keyFile) return } listener, err := net.Listen("tcp", a.addr) if err != nil { logger.Log.Fatalf("Failed to listen: %s", err.Error()) } a.listener = listener a.running = true a.serve() }
[ "func", "(", "a", "*", "TCPAcceptor", ")", "ListenAndServe", "(", ")", "{", "if", "a", ".", "hasTLSCertificates", "(", ")", "{", "a", ".", "ListenAndServeTLS", "(", "a", ".", "certFile", ",", "a", ".", "keyFile", ")", "\n", "return", "\n", "}", "\n\n...
// ListenAndServe using tcp acceptor
[ "ListenAndServe", "using", "tcp", "acceptor" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/tcp_acceptor.go#L85-L98
28,222
topfreegames/pitaya
acceptor/tcp_acceptor.go
ListenAndServeTLS
func (a *TCPAcceptor) ListenAndServeTLS(cert, key string) { crt, err := tls.LoadX509KeyPair(cert, key) if err != nil { logger.Log.Fatalf("Failed to listen: %s", err.Error()) } tlsCfg := &tls.Config{Certificates: []tls.Certificate{crt}} listener, err := tls.Listen("tcp", a.addr, tlsCfg) a.listener = listener ...
go
func (a *TCPAcceptor) ListenAndServeTLS(cert, key string) { crt, err := tls.LoadX509KeyPair(cert, key) if err != nil { logger.Log.Fatalf("Failed to listen: %s", err.Error()) } tlsCfg := &tls.Config{Certificates: []tls.Certificate{crt}} listener, err := tls.Listen("tcp", a.addr, tlsCfg) a.listener = listener ...
[ "func", "(", "a", "*", "TCPAcceptor", ")", "ListenAndServeTLS", "(", "cert", ",", "key", "string", ")", "{", "crt", ",", "err", ":=", "tls", ".", "LoadX509KeyPair", "(", "cert", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "...
// ListenAndServeTLS listens using tls
[ "ListenAndServeTLS", "listens", "using", "tls" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/tcp_acceptor.go#L101-L113
28,223
topfreegames/pitaya
acceptor/ws_acceptor.go
NewWSAcceptor
func NewWSAcceptor(addr string, certs ...string) *WSAcceptor { keyFile := "" certFile := "" if len(certs) != 2 && len(certs) != 0 { panic(constants.ErrInvalidCertificates) } else if len(certs) == 2 { certFile = certs[0] keyFile = certs[1] } w := &WSAcceptor{ addr: addr, connChan: make(chan net.Conn...
go
func NewWSAcceptor(addr string, certs ...string) *WSAcceptor { keyFile := "" certFile := "" if len(certs) != 2 && len(certs) != 0 { panic(constants.ErrInvalidCertificates) } else if len(certs) == 2 { certFile = certs[0] keyFile = certs[1] } w := &WSAcceptor{ addr: addr, connChan: make(chan net.Conn...
[ "func", "NewWSAcceptor", "(", "addr", "string", ",", "certs", "...", "string", ")", "*", "WSAcceptor", "{", "keyFile", ":=", "\"", "\"", "\n", "certFile", ":=", "\"", "\"", "\n", "if", "len", "(", "certs", ")", "!=", "2", "&&", "len", "(", "certs", ...
// NewWSAcceptor returns a new instance of WSAcceptor
[ "NewWSAcceptor", "returns", "a", "new", "instance", "of", "WSAcceptor" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/ws_acceptor.go#L45-L62
28,224
topfreegames/pitaya
acceptor/ws_acceptor.go
ListenAndServe
func (w *WSAcceptor) ListenAndServe() { if w.hasTLSCertificates() { w.ListenAndServeTLS(w.certFile, w.keyFile) return } var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, CheckOrigin: func(r *http.Request) bool { return true }, } listener, err := net.Listen("tcp", w.a...
go
func (w *WSAcceptor) ListenAndServe() { if w.hasTLSCertificates() { w.ListenAndServeTLS(w.certFile, w.keyFile) return } var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, CheckOrigin: func(r *http.Request) bool { return true }, } listener, err := net.Listen("tcp", w.a...
[ "func", "(", "w", "*", "WSAcceptor", ")", "ListenAndServe", "(", ")", "{", "if", "w", ".", "hasTLSCertificates", "(", ")", "{", "w", ".", "ListenAndServeTLS", "(", "w", ".", "certFile", ",", "w", ".", "keyFile", ")", "\n", "return", "\n", "}", "\n\n"...
// ListenAndServe listens and serve in the specified addr
[ "ListenAndServe", "listens", "and", "serve", "in", "the", "specified", "addr" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/ws_acceptor.go#L102-L123
28,225
topfreegames/pitaya
acceptor/ws_acceptor.go
ListenAndServeTLS
func (w *WSAcceptor) ListenAndServeTLS(cert, key string) { var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } crt, err := tls.LoadX509KeyPair(cert, key) if err != nil { logger.Log.Fatalf("Failed to load x509: %s", err.Error()) } tlsCfg := &tls.Config{Certificates: []tls.Cer...
go
func (w *WSAcceptor) ListenAndServeTLS(cert, key string) { var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } crt, err := tls.LoadX509KeyPair(cert, key) if err != nil { logger.Log.Fatalf("Failed to load x509: %s", err.Error()) } tlsCfg := &tls.Config{Certificates: []tls.Cer...
[ "func", "(", "w", "*", "WSAcceptor", ")", "ListenAndServeTLS", "(", "cert", ",", "key", "string", ")", "{", "var", "upgrader", "=", "websocket", ".", "Upgrader", "{", "ReadBufferSize", ":", "1024", ",", "WriteBufferSize", ":", "1024", ",", "}", "\n\n", "...
// ListenAndServeTLS listens and serve in the specified addr using tls
[ "ListenAndServeTLS", "listens", "and", "serve", "in", "the", "specified", "addr", "using", "tls" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/ws_acceptor.go#L126-L144
28,226
topfreegames/pitaya
acceptor/ws_acceptor.go
Stop
func (w *WSAcceptor) Stop() { err := w.listener.Close() if err != nil { logger.Log.Errorf("Failed to stop: %s", err.Error()) } }
go
func (w *WSAcceptor) Stop() { err := w.listener.Close() if err != nil { logger.Log.Errorf("Failed to stop: %s", err.Error()) } }
[ "func", "(", "w", "*", "WSAcceptor", ")", "Stop", "(", ")", "{", "err", ":=", "w", ".", "listener", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Error", "...
// Stop stops the acceptor
[ "Stop", "stops", "the", "acceptor" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/acceptor/ws_acceptor.go#L156-L161
28,227
topfreegames/pitaya
client/client.go
New
func New(logLevel logrus.Level, requestTimeout ...time.Duration) *Client { l := logrus.New() l.Formatter = &logrus.TextFormatter{} l.SetLevel(logLevel) logger.Log = l reqTimeout := 5 * time.Second if len(requestTimeout) > 0 { reqTimeout = requestTimeout[0] } return &Client{ Connected: false, pack...
go
func New(logLevel logrus.Level, requestTimeout ...time.Duration) *Client { l := logrus.New() l.Formatter = &logrus.TextFormatter{} l.SetLevel(logLevel) logger.Log = l reqTimeout := 5 * time.Second if len(requestTimeout) > 0 { reqTimeout = requestTimeout[0] } return &Client{ Connected: false, pack...
[ "func", "New", "(", "logLevel", "logrus", ".", "Level", ",", "requestTimeout", "...", "time", ".", "Duration", ")", "*", "Client", "{", "l", ":=", "logrus", ".", "New", "(", ")", "\n", "l", ".", "Formatter", "=", "&", "logrus", ".", "TextFormatter", ...
// New returns a new client
[ "New", "returns", "a", "new", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/client.go#L104-L128
28,228
topfreegames/pitaya
client/client.go
pendingRequestsReaper
func (c *Client) pendingRequestsReaper() { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for { select { case <-ticker.C: toDelete := make([]*pendingRequest, 0) c.pendingReqMutex.Lock() for _, v := range c.pendingRequests { if time.Now().Sub(v.sentAt) > c.requestTimeout { toDelet...
go
func (c *Client) pendingRequestsReaper() { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for { select { case <-ticker.C: toDelete := make([]*pendingRequest, 0) c.pendingReqMutex.Lock() for _, v := range c.pendingRequests { if time.Now().Sub(v.sentAt) > c.requestTimeout { toDelet...
[ "func", "(", "c", "*", "Client", ")", "pendingRequestsReaper", "(", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "1", "*", "time", ".", "Second", ")", "\n", "defer", "ticker", ".", "Stop", "(", ")", "\n", "for", "{", "select", "{", "cas...
// pendingRequestsReaper delete timedout requests
[ "pendingRequestsReaper", "delete", "timedout", "requests" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/client.go#L189-L222
28,229
topfreegames/pitaya
client/client.go
Disconnect
func (c *Client) Disconnect() { if c.Connected { c.Connected = false close(c.closeChan) c.conn.Close() } }
go
func (c *Client) Disconnect() { if c.Connected { c.Connected = false close(c.closeChan) c.conn.Close() } }
[ "func", "(", "c", "*", "Client", ")", "Disconnect", "(", ")", "{", "if", "c", ".", "Connected", "{", "c", ".", "Connected", "=", "false", "\n", "close", "(", "c", ".", "closeChan", ")", "\n", "c", ".", "conn", ".", "Close", "(", ")", "\n", "}",...
// Disconnect disconnects the client
[ "Disconnect", "disconnects", "the", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/client.go#L317-L323
28,230
topfreegames/pitaya
client/client.go
sendMsg
func (c *Client) sendMsg(msgType message.Type, route string, data []byte) (uint, error) { // TODO mount msg and encode m := message.Message{ Type: msgType, ID: uint(atomic.AddUint32(&c.nextID, 1)), Route: route, Data: data, Err: false, } p, err := c.buildPacket(m) if msgType == message.Request { ...
go
func (c *Client) sendMsg(msgType message.Type, route string, data []byte) (uint, error) { // TODO mount msg and encode m := message.Message{ Type: msgType, ID: uint(atomic.AddUint32(&c.nextID, 1)), Route: route, Data: data, Err: false, } p, err := c.buildPacket(m) if msgType == message.Request { ...
[ "func", "(", "c", "*", "Client", ")", "sendMsg", "(", "msgType", "message", ".", "Type", ",", "route", "string", ",", "data", "[", "]", "byte", ")", "(", "uint", ",", "error", ")", "{", "// TODO mount msg and encode", "m", ":=", "message", ".", "Messag...
// sendMsg sends the request to the server
[ "sendMsg", "sends", "the", "request", "to", "the", "server" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/client.go#L400-L427
28,231
topfreegames/pitaya
cluster/mocks/service_discovery.go
NewMockServiceDiscovery
func NewMockServiceDiscovery(ctrl *gomock.Controller) *MockServiceDiscovery { mock := &MockServiceDiscovery{ctrl: ctrl} mock.recorder = &MockServiceDiscoveryMockRecorder{mock} return mock }
go
func NewMockServiceDiscovery(ctrl *gomock.Controller) *MockServiceDiscovery { mock := &MockServiceDiscovery{ctrl: ctrl} mock.recorder = &MockServiceDiscoveryMockRecorder{mock} return mock }
[ "func", "NewMockServiceDiscovery", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockServiceDiscovery", "{", "mock", ":=", "&", "MockServiceDiscovery", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockServiceDiscoveryMockR...
// NewMockServiceDiscovery creates a new mock instance
[ "NewMockServiceDiscovery", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L25-L29
28,232
topfreegames/pitaya
cluster/mocks/service_discovery.go
GetServersByType
func (m *MockServiceDiscovery) GetServersByType(serverType string) (map[string]*cluster.Server, error) { ret := m.ctrl.Call(m, "GetServersByType", serverType) ret0, _ := ret[0].(map[string]*cluster.Server) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockServiceDiscovery) GetServersByType(serverType string) (map[string]*cluster.Server, error) { ret := m.ctrl.Call(m, "GetServersByType", serverType) ret0, _ := ret[0].(map[string]*cluster.Server) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockServiceDiscovery", ")", "GetServersByType", "(", "serverType", "string", ")", "(", "map", "[", "string", "]", "*", "cluster", ".", "Server", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ","...
// GetServersByType mocks base method
[ "GetServersByType", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L37-L42
28,233
topfreegames/pitaya
cluster/mocks/service_discovery.go
GetServersByType
func (mr *MockServiceDiscoveryMockRecorder) GetServersByType(serverType interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServersByType", reflect.TypeOf((*MockServiceDiscovery)(nil).GetServersByType), serverType) }
go
func (mr *MockServiceDiscoveryMockRecorder) GetServersByType(serverType interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServersByType", reflect.TypeOf((*MockServiceDiscovery)(nil).GetServersByType), serverType) }
[ "func", "(", "mr", "*", "MockServiceDiscoveryMockRecorder", ")", "GetServersByType", "(", "serverType", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "m...
// GetServersByType indicates an expected call of GetServersByType
[ "GetServersByType", "indicates", "an", "expected", "call", "of", "GetServersByType" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L45-L47
28,234
topfreegames/pitaya
cluster/mocks/service_discovery.go
GetServer
func (m *MockServiceDiscovery) GetServer(id string) (*cluster.Server, error) { ret := m.ctrl.Call(m, "GetServer", id) ret0, _ := ret[0].(*cluster.Server) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockServiceDiscovery) GetServer(id string) (*cluster.Server, error) { ret := m.ctrl.Call(m, "GetServer", id) ret0, _ := ret[0].(*cluster.Server) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockServiceDiscovery", ")", "GetServer", "(", "id", "string", ")", "(", "*", "cluster", ".", "Server", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "id", ")", "\n", ...
// GetServer mocks base method
[ "GetServer", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L50-L55
28,235
topfreegames/pitaya
cluster/mocks/service_discovery.go
GetServer
func (mr *MockServiceDiscoveryMockRecorder) GetServer(id interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServer", reflect.TypeOf((*MockServiceDiscovery)(nil).GetServer), id) }
go
func (mr *MockServiceDiscoveryMockRecorder) GetServer(id interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServer", reflect.TypeOf((*MockServiceDiscovery)(nil).GetServer), id) }
[ "func", "(", "mr", "*", "MockServiceDiscoveryMockRecorder", ")", "GetServer", "(", "id", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", ...
// GetServer indicates an expected call of GetServer
[ "GetServer", "indicates", "an", "expected", "call", "of", "GetServer" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L58-L60
28,236
topfreegames/pitaya
cluster/mocks/service_discovery.go
GetServers
func (m *MockServiceDiscovery) GetServers() []*cluster.Server { ret := m.ctrl.Call(m, "GetServers") ret0, _ := ret[0].([]*cluster.Server) return ret0 }
go
func (m *MockServiceDiscovery) GetServers() []*cluster.Server { ret := m.ctrl.Call(m, "GetServers") ret0, _ := ret[0].([]*cluster.Server) return ret0 }
[ "func", "(", "m", "*", "MockServiceDiscovery", ")", "GetServers", "(", ")", "[", "]", "*", "cluster", ".", "Server", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0",...
// GetServers mocks base method
[ "GetServers", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L63-L67
28,237
topfreegames/pitaya
cluster/mocks/service_discovery.go
AddListener
func (m *MockServiceDiscovery) AddListener(listener cluster.SDListener) { m.ctrl.Call(m, "AddListener", listener) }
go
func (m *MockServiceDiscovery) AddListener(listener cluster.SDListener) { m.ctrl.Call(m, "AddListener", listener) }
[ "func", "(", "m", "*", "MockServiceDiscovery", ")", "AddListener", "(", "listener", "cluster", ".", "SDListener", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "listener", ")", "\n", "}" ]
// AddListener mocks base method
[ "AddListener", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L87-L89
28,238
topfreegames/pitaya
cluster/mocks/service_discovery.go
AddListener
func (mr *MockServiceDiscoveryMockRecorder) AddListener(listener interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddListener", reflect.TypeOf((*MockServiceDiscovery)(nil).AddListener), listener) }
go
func (mr *MockServiceDiscoveryMockRecorder) AddListener(listener interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddListener", reflect.TypeOf((*MockServiceDiscovery)(nil).AddListener), listener) }
[ "func", "(", "mr", "*", "MockServiceDiscoveryMockRecorder", ")", "AddListener", "(", "listener", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ...
// AddListener indicates an expected call of AddListener
[ "AddListener", "indicates", "an", "expected", "call", "of", "AddListener" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/service_discovery.go#L92-L94
28,239
topfreegames/pitaya
conn/message/mocks/message_encoder.go
NewMockEncoder
func NewMockEncoder(ctrl *gomock.Controller) *MockEncoder { mock := &MockEncoder{ctrl: ctrl} mock.recorder = &MockEncoderMockRecorder{mock} return mock }
go
func NewMockEncoder(ctrl *gomock.Controller) *MockEncoder { mock := &MockEncoder{ctrl: ctrl} mock.recorder = &MockEncoderMockRecorder{mock} return mock }
[ "func", "NewMockEncoder", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockEncoder", "{", "mock", ":=", "&", "MockEncoder", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockEncoderMockRecorder", "{", "mock", "}", ...
// NewMockEncoder creates a new mock instance
[ "NewMockEncoder", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/mocks/message_encoder.go#L25-L29
28,240
topfreegames/pitaya
conn/message/mocks/message_encoder.go
IsCompressionEnabled
func (m *MockEncoder) IsCompressionEnabled() bool { ret := m.ctrl.Call(m, "IsCompressionEnabled") ret0, _ := ret[0].(bool) return ret0 }
go
func (m *MockEncoder) IsCompressionEnabled() bool { ret := m.ctrl.Call(m, "IsCompressionEnabled") ret0, _ := ret[0].(bool) return ret0 }
[ "func", "(", "m", "*", "MockEncoder", ")", "IsCompressionEnabled", "(", ")", "bool", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "bool", ")", "...
// IsCompressionEnabled mocks base method
[ "IsCompressionEnabled", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/mocks/message_encoder.go#L37-L41
28,241
topfreegames/pitaya
conn/message/mocks/message_encoder.go
IsCompressionEnabled
func (mr *MockEncoderMockRecorder) IsCompressionEnabled() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsCompressionEnabled", reflect.TypeOf((*MockEncoder)(nil).IsCompressionEnabled)) }
go
func (mr *MockEncoderMockRecorder) IsCompressionEnabled() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsCompressionEnabled", reflect.TypeOf((*MockEncoder)(nil).IsCompressionEnabled)) }
[ "func", "(", "mr", "*", "MockEncoderMockRecorder", ")", "IsCompressionEnabled", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ...
// IsCompressionEnabled indicates an expected call of IsCompressionEnabled
[ "IsCompressionEnabled", "indicates", "an", "expected", "call", "of", "IsCompressionEnabled" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/mocks/message_encoder.go#L44-L46
28,242
topfreegames/pitaya
examples/demo/cluster_grpc/services/connector.go
SendPushToUser
func (c *Connector) SendPushToUser(ctx context.Context, msg *UserMessage) (*Response, error) { _, err := pitaya.SendPushToUsers("onMessage", msg, []string{"2"}, "connector") if err != nil { return nil, err } return &Response{ Code: 200, Msg: "boa", }, nil }
go
func (c *Connector) SendPushToUser(ctx context.Context, msg *UserMessage) (*Response, error) { _, err := pitaya.SendPushToUsers("onMessage", msg, []string{"2"}, "connector") if err != nil { return nil, err } return &Response{ Code: 200, Msg: "boa", }, nil }
[ "func", "(", "c", "*", "Connector", ")", "SendPushToUser", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "UserMessage", ")", "(", "*", "Response", ",", "error", ")", "{", "_", ",", "err", ":=", "pitaya", ".", "SendPushToUsers", "(", "\"", "...
// SendPushToUser sends a push to a user
[ "SendPushToUser", "sends", "a", "push", "to", "a", "user" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_grpc/services/connector.go#L70-L79
28,243
topfreegames/pitaya
examples/demo/cluster_grpc/services/connector.go
RemoteFunc
func (c *ConnectorRemote) RemoteFunc(ctx context.Context, msg *protos.RPCMsg) (*protos.RPCRes, error) { fmt.Printf("received a remote call with this message: %s\n", msg) return &protos.RPCRes{ Msg: fmt.Sprintf("received msg: %s", msg.GetMsg()), }, nil }
go
func (c *ConnectorRemote) RemoteFunc(ctx context.Context, msg *protos.RPCMsg) (*protos.RPCRes, error) { fmt.Printf("received a remote call with this message: %s\n", msg) return &protos.RPCRes{ Msg: fmt.Sprintf("received msg: %s", msg.GetMsg()), }, nil }
[ "func", "(", "c", "*", "ConnectorRemote", ")", "RemoteFunc", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "protos", ".", "RPCMsg", ")", "(", "*", "protos", ".", "RPCRes", ",", "error", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\...
// RemoteFunc is a function that will be called remotely
[ "RemoteFunc", "is", "a", "function", "that", "will", "be", "called", "remotely" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_grpc/services/connector.go#L82-L87
28,244
topfreegames/pitaya
helpers/helpers.go
GetFreePort
func GetFreePort(t testing.TB) int { t.Helper() addr, err := net.ResolveTCPAddr("tcp", "localhost:0") if err != nil { t.Fatal(err) } l, err := net.ListenTCP("tcp", addr) if err != nil { t.Fatal(err) } defer l.Close() return l.Addr().(*net.TCPAddr).Port }
go
func GetFreePort(t testing.TB) int { t.Helper() addr, err := net.ResolveTCPAddr("tcp", "localhost:0") if err != nil { t.Fatal(err) } l, err := net.ListenTCP("tcp", addr) if err != nil { t.Fatal(err) } defer l.Close() return l.Addr().(*net.TCPAddr).Port }
[ "func", "GetFreePort", "(", "t", "testing", ".", "TB", ")", "int", "{", "t", ".", "Helper", "(", ")", "\n", "addr", ",", "err", ":=", "net", ".", "ResolveTCPAddr", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "t",...
// GetFreePort returns a free port
[ "GetFreePort", "returns", "a", "free", "port" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L24-L37
28,245
topfreegames/pitaya
helpers/helpers.go
GetMapKeys
func GetMapKeys(t *testing.T, m interface{}) []string { if reflect.ValueOf(m).Kind() != reflect.Map { t.Fatal(errors.New("GetMapKeys should receive a map")) } if reflect.TypeOf(m).Key() != reflect.TypeOf("bla") { t.Fatal(errors.New("GetMapKeys should receive a map with string keys")) } t.Helper() res := make(...
go
func GetMapKeys(t *testing.T, m interface{}) []string { if reflect.ValueOf(m).Kind() != reflect.Map { t.Fatal(errors.New("GetMapKeys should receive a map")) } if reflect.TypeOf(m).Key() != reflect.TypeOf("bla") { t.Fatal(errors.New("GetMapKeys should receive a map with string keys")) } t.Helper() res := make(...
[ "func", "GetMapKeys", "(", "t", "*", "testing", ".", "T", ",", "m", "interface", "{", "}", ")", "[", "]", "string", "{", "if", "reflect", ".", "ValueOf", "(", "m", ")", ".", "Kind", "(", ")", "!=", "reflect", ".", "Map", "{", "t", ".", "Fatal",...
// GetMapKeys returns a string slice with the map keys
[ "GetMapKeys", "returns", "a", "string", "slice", "with", "the", "map", "keys" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L40-L53
28,246
topfreegames/pitaya
helpers/helpers.go
WriteFile
func WriteFile(t *testing.T, filepath string, bytes []byte) { t.Helper() if err := ioutil.WriteFile(filepath, bytes, 0644); err != nil { t.Fatalf("failed writing file: %s", err) } }
go
func WriteFile(t *testing.T, filepath string, bytes []byte) { t.Helper() if err := ioutil.WriteFile(filepath, bytes, 0644); err != nil { t.Fatalf("failed writing file: %s", err) } }
[ "func", "WriteFile", "(", "t", "*", "testing", ".", "T", ",", "filepath", "string", ",", "bytes", "[", "]", "byte", ")", "{", "t", ".", "Helper", "(", ")", "\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "filepath", ",", "bytes", ",", "...
// WriteFile test helper
[ "WriteFile", "test", "helper" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L73-L78
28,247
topfreegames/pitaya
helpers/helpers.go
ReadFile
func ReadFile(t *testing.T, filepath string) []byte { t.Helper() b, err := ioutil.ReadFile(filepath) if err != nil { t.Fatalf("failed reading file: %s", err) } return b }
go
func ReadFile(t *testing.T, filepath string) []byte { t.Helper() b, err := ioutil.ReadFile(filepath) if err != nil { t.Fatalf("failed reading file: %s", err) } return b }
[ "func", "ReadFile", "(", "t", "*", "testing", ".", "T", ",", "filepath", "string", ")", "[", "]", "byte", "{", "t", ".", "Helper", "(", ")", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ")", "\n", "if", "err", "!=", ...
// ReadFile test helper
[ "ReadFile", "test", "helper" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L81-L88
28,248
topfreegames/pitaya
helpers/helpers.go
StartProcess
func StartProcess(t testing.TB, program string, args ...string) *exec.Cmd { t.Helper() return exec.Command(program, args...) }
go
func StartProcess(t testing.TB, program string, args ...string) *exec.Cmd { t.Helper() return exec.Command(program, args...) }
[ "func", "StartProcess", "(", "t", "testing", ".", "TB", ",", "program", "string", ",", "args", "...", "string", ")", "*", "exec", ".", "Cmd", "{", "t", ".", "Helper", "(", ")", "\n", "return", "exec", ".", "Command", "(", "program", ",", "args", "....
// StartProcess starts a process
[ "StartProcess", "starts", "a", "process" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L91-L94
28,249
topfreegames/pitaya
helpers/helpers.go
StartServer
func StartServer(t testing.TB, frontend bool, debug bool, svType string, port int, sdPrefix string, grpc bool) func() { grpcPort := GetFreePort(t) promPort := GetFreePort(t) var useGRPC string if grpc { useGRPC = "true" } else { useGRPC = "false" } t.Helper() args := []string{ "-type", svType, "-port"...
go
func StartServer(t testing.TB, frontend bool, debug bool, svType string, port int, sdPrefix string, grpc bool) func() { grpcPort := GetFreePort(t) promPort := GetFreePort(t) var useGRPC string if grpc { useGRPC = "true" } else { useGRPC = "false" } t.Helper() args := []string{ "-type", svType, "-port"...
[ "func", "StartServer", "(", "t", "testing", ".", "TB", ",", "frontend", "bool", ",", "debug", "bool", ",", "svType", "string", ",", "port", "int", ",", "sdPrefix", "string", ",", "grpc", "bool", ")", "func", "(", ")", "{", "grpcPort", ":=", "GetFreePor...
// StartServer starts a server
[ "StartServer", "starts", "a", "server" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L108-L157
28,250
topfreegames/pitaya
helpers/helpers.go
FixtureGoldenFileName
func FixtureGoldenFileName(t *testing.T, name string) string { t.Helper() return filepath.Join("fixtures", name+".golden") }
go
func FixtureGoldenFileName(t *testing.T, name string) string { t.Helper() return filepath.Join("fixtures", name+".golden") }
[ "func", "FixtureGoldenFileName", "(", "t", "*", "testing", ".", "T", ",", "name", "string", ")", "string", "{", "t", ".", "Helper", "(", ")", "\n", "return", "filepath", ".", "Join", "(", "\"", "\"", ",", "name", "+", "\"", "\"", ")", "\n", "}" ]
// FixtureGoldenFileName returns the golden file name on fixtures path
[ "FixtureGoldenFileName", "returns", "the", "golden", "file", "name", "on", "fixtures", "path" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L160-L163
28,251
topfreegames/pitaya
helpers/helpers.go
ShouldEventuallyReceive
func ShouldEventuallyReceive(t testing.TB, c interface{}, timeouts ...time.Duration) interface{} { t.Helper() if !isChan(c) { t.Fatal("ShouldEventuallyReceive c argument should be a channel") } v := reflect.ValueOf(c) timeout := time.After(500 * time.Millisecond) if len(timeouts) > 0 { timeout = time.After(...
go
func ShouldEventuallyReceive(t testing.TB, c interface{}, timeouts ...time.Duration) interface{} { t.Helper() if !isChan(c) { t.Fatal("ShouldEventuallyReceive c argument should be a channel") } v := reflect.ValueOf(c) timeout := time.After(500 * time.Millisecond) if len(timeouts) > 0 { timeout = time.After(...
[ "func", "ShouldEventuallyReceive", "(", "t", "testing", ".", "TB", ",", "c", "interface", "{", "}", ",", "timeouts", "...", "time", ".", "Duration", ")", "interface", "{", "}", "{", "t", ".", "Helper", "(", ")", "\n", "if", "!", "isChan", "(", "c", ...
// ShouldEventuallyReceive should asserts that eventually channel c receives a value
[ "ShouldEventuallyReceive", "should", "asserts", "that", "eventually", "channel", "c", "receives", "a", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/helpers/helpers.go#L196-L226
28,252
topfreegames/pitaya
examples/demo/worker/services/room.go
CallLog
func (*Room) CallLog(ctx context.Context, arg *protos.Arg) (*protos.Response, error) { route := "metagame.metagame.logremote" reply := &protos.Response{} jid, err := pitaya.ReliableRPC(route, nil, reply, arg) if err != nil { logger.Log.Infof("failed to enqueue rpc: %q", err) return nil, err } logger.Log.Info...
go
func (*Room) CallLog(ctx context.Context, arg *protos.Arg) (*protos.Response, error) { route := "metagame.metagame.logremote" reply := &protos.Response{} jid, err := pitaya.ReliableRPC(route, nil, reply, arg) if err != nil { logger.Log.Infof("failed to enqueue rpc: %q", err) return nil, err } logger.Log.Info...
[ "func", "(", "*", "Room", ")", "CallLog", "(", "ctx", "context", ".", "Context", ",", "arg", "*", "protos", ".", "Arg", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "route", ":=", "\"", "\"", "\n", "reply", ":=", "&", "protos...
// CallLog makes ReliableRPC to metagame LogRemote
[ "CallLog", "makes", "ReliableRPC", "to", "metagame", "LogRemote" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/worker/services/room.go#L18-L29
28,253
topfreegames/pitaya
serialize/mocks/serializer.go
NewMockSerializer
func NewMockSerializer(ctrl *gomock.Controller) *MockSerializer { mock := &MockSerializer{ctrl: ctrl} mock.recorder = &MockSerializerMockRecorder{mock} return mock }
go
func NewMockSerializer(ctrl *gomock.Controller) *MockSerializer { mock := &MockSerializer{ctrl: ctrl} mock.recorder = &MockSerializerMockRecorder{mock} return mock }
[ "func", "NewMockSerializer", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockSerializer", "{", "mock", ":=", "&", "MockSerializer", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockSerializerMockRecorder", "{", "mock...
// NewMockSerializer creates a new mock instance
[ "NewMockSerializer", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/mocks/serializer.go#L24-L28
28,254
topfreegames/pitaya
serialize/mocks/serializer.go
GetName
func (mr *MockSerializerMockRecorder) GetName() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetName", reflect.TypeOf((*MockSerializer)(nil).GetName)) }
go
func (mr *MockSerializerMockRecorder) GetName() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetName", reflect.TypeOf((*MockSerializer)(nil).GetName)) }
[ "func", "(", "mr", "*", "MockSerializerMockRecorder", ")", "GetName", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "T...
// GetName indicates an expected call of GetName
[ "GetName", "indicates", "an", "expected", "call", "of", "GetName" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/mocks/serializer.go#L43-L45
28,255
topfreegames/pitaya
serialize/mocks/serializer.go
Marshal
func (m *MockSerializer) Marshal(arg0 interface{}) ([]byte, error) { ret := m.ctrl.Call(m, "Marshal", arg0) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockSerializer) Marshal(arg0 interface{}) ([]byte, error) { ret := m.ctrl.Call(m, "Marshal", arg0) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockSerializer", ")", "Marshal", "(", "arg0", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ")", "\n", "r...
// Marshal mocks base method
[ "Marshal", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/mocks/serializer.go#L48-L53
28,256
topfreegames/pitaya
serialize/mocks/serializer.go
Unmarshal
func (m *MockSerializer) Unmarshal(arg0 []byte, arg1 interface{}) error { ret := m.ctrl.Call(m, "Unmarshal", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockSerializer) Unmarshal(arg0 []byte, arg1 interface{}) error { ret := m.ctrl.Call(m, "Unmarshal", arg0, arg1) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockSerializer", ")", "Unmarshal", "(", "arg0", "[", "]", "byte", ",", "arg1", "interface", "{", "}", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ")...
// Unmarshal mocks base method
[ "Unmarshal", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/mocks/serializer.go#L61-L65
28,257
topfreegames/pitaya
serialize/mocks/serializer.go
Unmarshal
func (mr *MockSerializerMockRecorder) Unmarshal(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unmarshal", reflect.TypeOf((*MockSerializer)(nil).Unmarshal), arg0, arg1) }
go
func (mr *MockSerializerMockRecorder) Unmarshal(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unmarshal", reflect.TypeOf((*MockSerializer)(nil).Unmarshal), arg0, arg1) }
[ "func", "(", "mr", "*", "MockSerializerMockRecorder", ")", "Unmarshal", "(", "arg0", ",", "arg1", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "moc...
// Unmarshal indicates an expected call of Unmarshal
[ "Unmarshal", "indicates", "an", "expected", "call", "of", "Unmarshal" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/serialize/mocks/serializer.go#L68-L70
28,258
topfreegames/pitaya
docgenerator/generator.go
HandlersDocs
func HandlersDocs(serverType string, services map[string]*component.Service, getPtrNames bool) (map[string]interface{}, error) { docs := &docs{ Handlers: map[string]*doc{}, } for serviceName, service := range services { for name, handler := range service.Handlers { routeName := route.NewRoute(serverType, ser...
go
func HandlersDocs(serverType string, services map[string]*component.Service, getPtrNames bool) (map[string]interface{}, error) { docs := &docs{ Handlers: map[string]*doc{}, } for serviceName, service := range services { for name, handler := range service.Handlers { routeName := route.NewRoute(serverType, ser...
[ "func", "HandlersDocs", "(", "serverType", "string", ",", "services", "map", "[", "string", "]", "*", "component", ".", "Service", ",", "getPtrNames", "bool", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "docs", "...
// HandlersDocs returns a map from route to input and output
[ "HandlersDocs", "returns", "a", "map", "from", "route", "to", "input", "and", "output" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/docgenerator/generator.go#L46-L59
28,259
topfreegames/pitaya
docgenerator/generator.go
RemotesDocs
func RemotesDocs(serverType string, services map[string]*component.Service, getPtrNames bool) (map[string]interface{}, error) { docs := &docs{ Remotes: map[string]*doc{}, } for serviceName, service := range services { for name, remote := range service.Remotes { routeName := route.NewRoute(serverType, service...
go
func RemotesDocs(serverType string, services map[string]*component.Service, getPtrNames bool) (map[string]interface{}, error) { docs := &docs{ Remotes: map[string]*doc{}, } for serviceName, service := range services { for name, remote := range service.Remotes { routeName := route.NewRoute(serverType, service...
[ "func", "RemotesDocs", "(", "serverType", "string", ",", "services", "map", "[", "string", "]", "*", "component", ".", "Service", ",", "getPtrNames", "bool", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "docs", ":...
// RemotesDocs returns a map from route to input and output
[ "RemotesDocs", "returns", "a", "map", "from", "route", "to", "input", "and", "output" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/docgenerator/generator.go#L62-L75
28,260
topfreegames/pitaya
conn/message/message.go
New
func New(err ...bool) *Message { m := &Message{} if len(err) > 0 { m.Err = err[0] } return m }
go
func New(err ...bool) *Message { m := &Message{} if len(err) > 0 { m.Err = err[0] } return m }
[ "func", "New", "(", "err", "...", "bool", ")", "*", "Message", "{", "m", ":=", "&", "Message", "{", "}", "\n", "if", "len", "(", "err", ")", ">", "0", "{", "m", ".", "Err", "=", "err", "[", "0", "]", "\n", "}", "\n", "return", "m", "\n", ...
// New returns a new message instance
[ "New", "returns", "a", "new", "message", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/message.go#L79-L85
28,261
topfreegames/pitaya
conn/message/message.go
String
func (m *Message) String() string { return fmt.Sprintf("Type: %s, ID: %d, Route: %s, Compressed: %t, Error: %t, Data: %v, BodyLength: %d", types[m.Type], m.ID, m.Route, m.compressed, m.Err, m.Data, len(m.Data)) }
go
func (m *Message) String() string { return fmt.Sprintf("Type: %s, ID: %d, Route: %s, Compressed: %t, Error: %t, Data: %v, BodyLength: %d", types[m.Type], m.ID, m.Route, m.compressed, m.Err, m.Data, len(m.Data)) }
[ "func", "(", "m", "*", "Message", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "types", "[", "m", ".", "Type", "]", ",", "m", ".", "ID", ",", "m", ".", "Route", ",", "m", ".", "compressed", ",...
// String, implementation of fmt.Stringer interface
[ "String", "implementation", "of", "fmt", ".", "Stringer", "interface" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/message.go#L88-L97
28,262
topfreegames/pitaya
conn/message/message.go
SetDictionary
func SetDictionary(dict map[string]uint16) error { if dict == nil { return nil } for route, code := range dict { r := strings.TrimSpace(route) // duplication check if _, ok := routes[r]; ok { return fmt.Errorf("duplicated route(route: %s, code: %d)", r, code) } if _, ok := codes[code]; ok { retu...
go
func SetDictionary(dict map[string]uint16) error { if dict == nil { return nil } for route, code := range dict { r := strings.TrimSpace(route) // duplication check if _, ok := routes[r]; ok { return fmt.Errorf("duplicated route(route: %s, code: %d)", r, code) } if _, ok := codes[code]; ok { retu...
[ "func", "SetDictionary", "(", "dict", "map", "[", "string", "]", "uint16", ")", "error", "{", "if", "dict", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "for", "route", ",", "code", ":=", "range", "dict", "{", "r", ":=", "strings", ".", "T...
// SetDictionary set routes map which be used to compress route.
[ "SetDictionary", "set", "routes", "map", "which", "be", "used", "to", "compress", "route", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/message/message.go#L109-L132
28,263
topfreegames/pitaya
conn/packet/packet.go
String
func (p *Packet) String() string { return fmt.Sprintf("Type: %d, Length: %d, Data: %s", p.Type, p.Length, string(p.Data)) }
go
func (p *Packet) String() string { return fmt.Sprintf("Type: %d, Length: %d, Data: %s", p.Type, p.Length, string(p.Data)) }
[ "func", "(", "p", "*", "Packet", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Type", ",", "p", ".", "Length", ",", "string", "(", "p", ".", "Data", ")", ")", "\n", "}" ]
//String represents the Packet's in text mode.
[ "String", "represents", "the", "Packet", "s", "in", "text", "mode", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/packet/packet.go#L40-L42
28,264
topfreegames/pitaya
metrics/mocks/reporter.go
NewMockReporter
func NewMockReporter(ctrl *gomock.Controller) *MockReporter { mock := &MockReporter{ctrl: ctrl} mock.recorder = &MockReporterMockRecorder{mock} return mock }
go
func NewMockReporter(ctrl *gomock.Controller) *MockReporter { mock := &MockReporter{ctrl: ctrl} mock.recorder = &MockReporterMockRecorder{mock} return mock }
[ "func", "NewMockReporter", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockReporter", "{", "mock", ":=", "&", "MockReporter", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockReporterMockRecorder", "{", "mock", "}"...
// NewMockReporter creates a new mock instance
[ "NewMockReporter", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/mocks/reporter.go#L25-L29
28,265
topfreegames/pitaya
metrics/mocks/reporter.go
ReportCount
func (m *MockReporter) ReportCount(metric string, tags map[string]string, count float64) error { ret := m.ctrl.Call(m, "ReportCount", metric, tags, count) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockReporter) ReportCount(metric string, tags map[string]string, count float64) error { ret := m.ctrl.Call(m, "ReportCount", metric, tags, count) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockReporter", ")", "ReportCount", "(", "metric", "string", ",", "tags", "map", "[", "string", "]", "string", ",", "count", "float64", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"",...
// ReportCount mocks base method
[ "ReportCount", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/mocks/reporter.go#L37-L41
28,266
topfreegames/pitaya
metrics/mocks/reporter.go
ReportCount
func (mr *MockReporterMockRecorder) ReportCount(metric, tags, count interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportCount", reflect.TypeOf((*MockReporter)(nil).ReportCount), metric, tags, count) }
go
func (mr *MockReporterMockRecorder) ReportCount(metric, tags, count interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportCount", reflect.TypeOf((*MockReporter)(nil).ReportCount), metric, tags, count) }
[ "func", "(", "mr", "*", "MockReporterMockRecorder", ")", "ReportCount", "(", "metric", ",", "tags", ",", "count", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", ...
// ReportCount indicates an expected call of ReportCount
[ "ReportCount", "indicates", "an", "expected", "call", "of", "ReportCount" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/mocks/reporter.go#L44-L46
28,267
topfreegames/pitaya
metrics/mocks/reporter.go
ReportSummary
func (m *MockReporter) ReportSummary(metric string, tags map[string]string, value float64) error { ret := m.ctrl.Call(m, "ReportSummary", metric, tags, value) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockReporter) ReportSummary(metric string, tags map[string]string, value float64) error { ret := m.ctrl.Call(m, "ReportSummary", metric, tags, value) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockReporter", ")", "ReportSummary", "(", "metric", "string", ",", "tags", "map", "[", "string", "]", "string", ",", "value", "float64", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"...
// ReportSummary mocks base method
[ "ReportSummary", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/mocks/reporter.go#L49-L53
28,268
topfreegames/pitaya
metrics/mocks/reporter.go
ReportSummary
func (mr *MockReporterMockRecorder) ReportSummary(metric, tags, value interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportSummary", reflect.TypeOf((*MockReporter)(nil).ReportSummary), metric, tags, value) }
go
func (mr *MockReporterMockRecorder) ReportSummary(metric, tags, value interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReportSummary", reflect.TypeOf((*MockReporter)(nil).ReportSummary), metric, tags, value) }
[ "func", "(", "mr", "*", "MockReporterMockRecorder", ")", "ReportSummary", "(", "metric", ",", "tags", ",", "value", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(",...
// ReportSummary indicates an expected call of ReportSummary
[ "ReportSummary", "indicates", "an", "expected", "call", "of", "ReportSummary" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/mocks/reporter.go#L56-L58
28,269
topfreegames/pitaya
tracing/span.go
InjectSpan
func InjectSpan(ctx context.Context) (context.Context, error) { span := opentracing.SpanFromContext(ctx) if span == nil { return ctx, nil } spanData := opentracing.TextMapCarrier{} tracer := opentracing.GlobalTracer() err := tracer.Inject(span.Context(), opentracing.TextMap, spanData) if err != nil { return ...
go
func InjectSpan(ctx context.Context) (context.Context, error) { span := opentracing.SpanFromContext(ctx) if span == nil { return ctx, nil } spanData := opentracing.TextMapCarrier{} tracer := opentracing.GlobalTracer() err := tracer.Inject(span.Context(), opentracing.TextMap, spanData) if err != nil { return ...
[ "func", "InjectSpan", "(", "ctx", "context", ".", "Context", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "span", ":=", "opentracing", ".", "SpanFromContext", "(", "ctx", ")", "\n", "if", "span", "==", "nil", "{", "return", "ctx", ",", ...
// InjectSpan retrieves an opentrancing span from the current context and creates a new context // with it encoded in binary format inside the propagatable context content
[ "InjectSpan", "retrieves", "an", "opentrancing", "span", "from", "the", "current", "context", "and", "creates", "a", "new", "context", "with", "it", "encoded", "in", "binary", "format", "inside", "the", "propagatable", "context", "content" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/tracing/span.go#L79-L91
28,270
topfreegames/pitaya
tracing/span.go
StartSpan
func StartSpan( parentCtx context.Context, opName string, tags opentracing.Tags, reference ...opentracing.SpanContext, ) context.Context { var ref opentracing.SpanContext if len(reference) > 0 { ref = reference[0] } span := opentracing.StartSpan(opName, opentracing.ChildOf(ref), tags) return opentracing.Cont...
go
func StartSpan( parentCtx context.Context, opName string, tags opentracing.Tags, reference ...opentracing.SpanContext, ) context.Context { var ref opentracing.SpanContext if len(reference) > 0 { ref = reference[0] } span := opentracing.StartSpan(opName, opentracing.ChildOf(ref), tags) return opentracing.Cont...
[ "func", "StartSpan", "(", "parentCtx", "context", ".", "Context", ",", "opName", "string", ",", "tags", "opentracing", ".", "Tags", ",", "reference", "...", "opentracing", ".", "SpanContext", ",", ")", "context", ".", "Context", "{", "var", "ref", "opentraci...
// StartSpan starts a new span with a given parent context, operation name, tags and // optional parent span. It returns a context with the created span.
[ "StartSpan", "starts", "a", "new", "span", "with", "a", "given", "parent", "context", "operation", "name", "tags", "and", "optional", "parent", "span", ".", "It", "returns", "a", "context", "with", "the", "created", "span", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/tracing/span.go#L95-L107
28,271
topfreegames/pitaya
tracing/span.go
FinishSpan
func FinishSpan(ctx context.Context, err error) { if ctx == nil { return } span := opentracing.SpanFromContext(ctx) if span == nil { return } defer span.Finish() if err != nil { LogError(span, err.Error()) } }
go
func FinishSpan(ctx context.Context, err error) { if ctx == nil { return } span := opentracing.SpanFromContext(ctx) if span == nil { return } defer span.Finish() if err != nil { LogError(span, err.Error()) } }
[ "func", "FinishSpan", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "{", "if", "ctx", "==", "nil", "{", "return", "\n", "}", "\n", "span", ":=", "opentracing", ".", "SpanFromContext", "(", "ctx", ")", "\n", "if", "span", "==", "nil...
// FinishSpan finishes a span retrieved from the given context and logs the error if it exists
[ "FinishSpan", "finishes", "a", "span", "retrieved", "from", "the", "given", "context", "and", "logs", "the", "error", "if", "it", "exists" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/tracing/span.go#L110-L122
28,272
topfreegames/pitaya
router/router.go
Route
func (r *Router) Route( ctx context.Context, rpcType protos.RPCType, svType string, route *route.Route, msg *message.Message, ) (*cluster.Server, error) { if r.serviceDiscovery == nil { return nil, constants.ErrServiceDiscoveryNotInitialized } serversOfType, err := r.serviceDiscovery.GetServersByType(svType) ...
go
func (r *Router) Route( ctx context.Context, rpcType protos.RPCType, svType string, route *route.Route, msg *message.Message, ) (*cluster.Server, error) { if r.serviceDiscovery == nil { return nil, constants.ErrServiceDiscoveryNotInitialized } serversOfType, err := r.serviceDiscovery.GetServersByType(svType) ...
[ "func", "(", "r", "*", "Router", ")", "Route", "(", "ctx", "context", ".", "Context", ",", "rpcType", "protos", ".", "RPCType", ",", "svType", "string", ",", "route", "*", "route", ".", "Route", ",", "msg", "*", "message", ".", "Message", ",", ")", ...
// Route gets the right server to use in the call
[ "Route", "gets", "the", "right", "server", "to", "use", "in", "the", "call" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/router/router.go#L76-L101
28,273
topfreegames/pitaya
agent/agent.go
NewAgent
func NewAgent( conn net.Conn, packetDecoder codec.PacketDecoder, packetEncoder codec.PacketEncoder, serializer serialize.Serializer, heartbeatTime time.Duration, messagesBufferSize int, dieChan chan bool, messageEncoder message.Encoder, metricsReporters []metrics.Reporter, ) *Agent { // initialize heartbeat a...
go
func NewAgent( conn net.Conn, packetDecoder codec.PacketDecoder, packetEncoder codec.PacketEncoder, serializer serialize.Serializer, heartbeatTime time.Duration, messagesBufferSize int, dieChan chan bool, messageEncoder message.Encoder, metricsReporters []metrics.Reporter, ) *Agent { // initialize heartbeat a...
[ "func", "NewAgent", "(", "conn", "net", ".", "Conn", ",", "packetDecoder", "codec", ".", "PacketDecoder", ",", "packetEncoder", "codec", ".", "PacketEncoder", ",", "serializer", "serialize", ".", "Serializer", ",", "heartbeatTime", "time", ".", "Duration", ",", ...
// NewAgent create new agent instance
[ "NewAgent", "create", "new", "agent", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L93-L132
28,274
topfreegames/pitaya
agent/agent.go
Push
func (a *Agent) Push(route string, v interface{}) error { if a.GetStatus() == constants.StatusClosed { return constants.ErrBrokenPipe } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Push, ID=%d, UID=%d, Route=%s, Data=%dbytes", a.Session.ID(), a.Session.UID(), route, len(d)) default: logger...
go
func (a *Agent) Push(route string, v interface{}) error { if a.GetStatus() == constants.StatusClosed { return constants.ErrBrokenPipe } switch d := v.(type) { case []byte: logger.Log.Debugf("Type=Push, ID=%d, UID=%d, Route=%s, Data=%dbytes", a.Session.ID(), a.Session.UID(), route, len(d)) default: logger...
[ "func", "(", "a", "*", "Agent", ")", "Push", "(", "route", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "a", ".", "GetStatus", "(", ")", "==", "constants", ".", "StatusClosed", "{", "return", "constants", ".", "ErrBrokenPipe", ...
// Push implementation for session.NetworkEntity interface
[ "Push", "implementation", "for", "session", ".", "NetworkEntity", "interface" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L146-L160
28,275
topfreegames/pitaya
agent/agent.go
ResponseMID
func (a *Agent) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { err := false if len(isError) > 0 { err = isError[0] } if a.GetStatus() == constants.StatusClosed { err := constants.ErrBrokenPipe tracing.FinishSpan(ctx, err) metrics.ReportTimingFromCtx(ctx, a.metricsReporter...
go
func (a *Agent) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { err := false if len(isError) > 0 { err = isError[0] } if a.GetStatus() == constants.StatusClosed { err := constants.ErrBrokenPipe tracing.FinishSpan(ctx, err) metrics.ReportTimingFromCtx(ctx, a.metricsReporter...
[ "func", "(", "a", "*", "Agent", ")", "ResponseMID", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "v", "interface", "{", "}", ",", "isError", "...", "bool", ")", "error", "{", "err", ":=", "false", "\n", "if", "len", "(", "isError...
// ResponseMID implementation for session.NetworkEntity interface // Respond message to session
[ "ResponseMID", "implementation", "for", "session", ".", "NetworkEntity", "interface", "Respond", "message", "to", "session" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L164-L193
28,276
topfreegames/pitaya
agent/agent.go
Close
func (a *Agent) Close() error { a.closeMutex.Lock() defer a.closeMutex.Unlock() if a.GetStatus() == constants.StatusClosed { return constants.ErrCloseClosedSession } a.SetStatus(constants.StatusClosed) logger.Log.Debugf("Session closed, ID=%d, UID=%d, IP=%s", a.Session.ID(), a.Session.UID(), a.conn.RemoteAdd...
go
func (a *Agent) Close() error { a.closeMutex.Lock() defer a.closeMutex.Unlock() if a.GetStatus() == constants.StatusClosed { return constants.ErrCloseClosedSession } a.SetStatus(constants.StatusClosed) logger.Log.Debugf("Session closed, ID=%d, UID=%d, IP=%s", a.Session.ID(), a.Session.UID(), a.conn.RemoteAdd...
[ "func", "(", "a", "*", "Agent", ")", "Close", "(", ")", "error", "{", "a", ".", "closeMutex", ".", "Lock", "(", ")", "\n", "defer", "a", ".", "closeMutex", ".", "Unlock", "(", ")", "\n", "if", "a", ".", "GetStatus", "(", ")", "==", "constants", ...
// Close closes the agent, cleans inner state and closes low-level connection. // Any blocked Read or Write operations will be unblocked and return errors.
[ "Close", "closes", "the", "agent", "cleans", "inner", "state", "and", "closes", "low", "-", "level", "connection", ".", "Any", "blocked", "Read", "or", "Write", "operations", "will", "be", "unblocked", "and", "return", "errors", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L197-L222
28,277
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
28,278
topfreegames/pitaya
agent/agent.go
Kick
func (a *Agent) Kick(ctx context.Context) error { // packet encode p, err := a.encoder.Encode(packet.Kick, nil) if err != nil { return err } _, err = a.conn.Write(p) return err }
go
func (a *Agent) Kick(ctx context.Context) error { // packet encode p, err := a.encoder.Encode(packet.Kick, nil) if err != nil { return err } _, err = a.conn.Write(p) return err }
[ "func", "(", "a", "*", "Agent", ")", "Kick", "(", "ctx", "context", ".", "Context", ")", "error", "{", "// packet encode", "p", ",", "err", ":=", "a", ".", "encoder", ".", "Encode", "(", "packet", ".", "Kick", ",", "nil", ")", "\n", "if", "err", ...
// Kick sends a kick packet to a client
[ "Kick", "sends", "a", "kick", "packet", "to", "a", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L241-L249
28,279
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
28,280
topfreegames/pitaya
agent/agent.go
Handle
func (a *Agent) Handle() { defer func() { a.Close() logger.Log.Debugf("Session handle goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() go a.write() go a.heartbeat() select { case <-a.chDie: // agent closed signal return } }
go
func (a *Agent) Handle() { defer func() { a.Close() logger.Log.Debugf("Session handle goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() go a.write() go a.heartbeat() select { case <-a.chDie: // agent closed signal return } }
[ "func", "(", "a", "*", "Agent", ")", "Handle", "(", ")", "{", "defer", "func", "(", ")", "{", "a", ".", "Close", "(", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "a", ".", "Session", ".", "ID", "(", ")", ",", "a", ...
// Handle handles the messages from and to a client
[ "Handle", "handles", "the", "messages", "from", "and", "to", "a", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L262-L274
28,281
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
28,282
topfreegames/pitaya
agent/agent.go
AnswerWithError
func (a *Agent) AnswerWithError(ctx context.Context, mid uint, err error) { if ctx != nil && err != nil { s := opentracing.SpanFromContext(ctx) if s != nil { tracing.LogError(s, err.Error()) } } p, e := util.GetErrorPayload(a.serializer, err) if e != nil { logger.Log.Errorf("error answering the user with...
go
func (a *Agent) AnswerWithError(ctx context.Context, mid uint, err error) { if ctx != nil && err != nil { s := opentracing.SpanFromContext(ctx) if s != nil { tracing.LogError(s, err.Error()) } } p, e := util.GetErrorPayload(a.serializer, err) if e != nil { logger.Log.Errorf("error answering the user with...
[ "func", "(", "a", "*", "Agent", ")", "AnswerWithError", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "err", "error", ")", "{", "if", "ctx", "!=", "nil", "&&", "err", "!=", "nil", "{", "s", ":=", "opentracing", ".", "SpanFromContext...
// AnswerWithError answers with an error
[ "AnswerWithError", "answers", "with", "an", "error" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/agent/agent.go#L428-L444
28,283
topfreegames/pitaya
session/session.go
New
func New(entity NetworkEntity, frontend bool, UID ...string) *Session { s := &Session{ id: sessionIDSvc.sessionID(), entity: entity, data: make(map[string]interface{}), handshakeData: nil, lastTime: time.Now().Unix(), OnCloseCallbacks: []func(){}, IsFrontend...
go
func New(entity NetworkEntity, frontend bool, UID ...string) *Session { s := &Session{ id: sessionIDSvc.sessionID(), entity: entity, data: make(map[string]interface{}), handshakeData: nil, lastTime: time.Now().Unix(), OnCloseCallbacks: []func(){}, IsFrontend...
[ "func", "New", "(", "entity", "NetworkEntity", ",", "frontend", "bool", ",", "UID", "...", "string", ")", "*", "Session", "{", "s", ":=", "&", "Session", "{", "id", ":", "sessionIDSvc", ".", "sessionID", "(", ")", ",", "entity", ":", "entity", ",", "...
// New returns a new session instance // a NetworkEntity is a low-level network instance
[ "New", "returns", "a", "new", "session", "instance", "a", "NetworkEntity", "is", "a", "low", "-", "level", "network", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L114-L132
28,284
topfreegames/pitaya
session/session.go
GetSessionByUID
func GetSessionByUID(uid string) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByUID.Load(uid); ok { return val.(*Session) } return nil }
go
func GetSessionByUID(uid string) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByUID.Load(uid); ok { return val.(*Session) } return nil }
[ "func", "GetSessionByUID", "(", "uid", "string", ")", "*", "Session", "{", "// TODO: Block this operation in backend servers", "if", "val", ",", "ok", ":=", "sessionsByUID", ".", "Load", "(", "uid", ")", ";", "ok", "{", "return", "val", ".", "(", "*", "Sessi...
// GetSessionByUID return a session bound to an user id
[ "GetSessionByUID", "return", "a", "session", "bound", "to", "an", "user", "id" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L135-L141
28,285
topfreegames/pitaya
session/session.go
GetSessionByID
func GetSessionByID(id int64) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByID.Load(id); ok { return val.(*Session) } return nil }
go
func GetSessionByID(id int64) *Session { // TODO: Block this operation in backend servers if val, ok := sessionsByID.Load(id); ok { return val.(*Session) } return nil }
[ "func", "GetSessionByID", "(", "id", "int64", ")", "*", "Session", "{", "// TODO: Block this operation in backend servers", "if", "val", ",", "ok", ":=", "sessionsByID", ".", "Load", "(", "id", ")", ";", "ok", "{", "return", "val", ".", "(", "*", "Session", ...
// GetSessionByID return a session bound to a frontend server id
[ "GetSessionByID", "return", "a", "session", "bound", "to", "a", "frontend", "server", "id" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L144-L150
28,286
topfreegames/pitaya
session/session.go
OnSessionBind
func OnSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range sessionBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } sessionBindCallbacks = append...
go
func OnSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range sessionBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } sessionBindCallbacks = append...
[ "func", "OnSessionBind", "(", "f", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "Session", ")", "error", ")", "{", "// Prevents the same function to be added twice in onSessionBind", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\n", ...
// OnSessionBind adds a method to be called when a session is bound // same function cannot be added twice!
[ "OnSessionBind", "adds", "a", "method", "to", "be", "called", "when", "a", "session", "is", "bound", "same", "function", "cannot", "be", "added", "twice!" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L154-L164
28,287
topfreegames/pitaya
session/session.go
OnAfterSessionBind
func OnAfterSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range afterBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } afterBindCallbacks = appen...
go
func OnAfterSessionBind(f func(ctx context.Context, s *Session) error) { // Prevents the same function to be added twice in onSessionBind sf1 := reflect.ValueOf(f) for _, fun := range afterBindCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } afterBindCallbacks = appen...
[ "func", "OnAfterSessionBind", "(", "f", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "Session", ")", "error", ")", "{", "// Prevents the same function to be added twice in onSessionBind", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\...
// OnAfterSessionBind adds a method to be called when session is bound and after all sessionBind callbacks
[ "OnAfterSessionBind", "adds", "a", "method", "to", "be", "called", "when", "session", "is", "bound", "and", "after", "all", "sessionBind", "callbacks" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L167-L177
28,288
topfreegames/pitaya
session/session.go
OnSessionClose
func OnSessionClose(f func(s *Session)) { sf1 := reflect.ValueOf(f) for _, fun := range SessionCloseCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } SessionCloseCallbacks = append(SessionCloseCallbacks, f) }
go
func OnSessionClose(f func(s *Session)) { sf1 := reflect.ValueOf(f) for _, fun := range SessionCloseCallbacks { sf2 := reflect.ValueOf(fun) if sf1.Pointer() == sf2.Pointer() { return } } SessionCloseCallbacks = append(SessionCloseCallbacks, f) }
[ "func", "OnSessionClose", "(", "f", "func", "(", "s", "*", "Session", ")", ")", "{", "sf1", ":=", "reflect", ".", "ValueOf", "(", "f", ")", "\n", "for", "_", ",", "fun", ":=", "range", "SessionCloseCallbacks", "{", "sf2", ":=", "reflect", ".", "Value...
// OnSessionClose adds a method that will be called when every session closes
[ "OnSessionClose", "adds", "a", "method", "that", "will", "be", "called", "when", "every", "session", "closes" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L180-L189
28,289
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
28,290
topfreegames/pitaya
session/session.go
ResponseMID
func (s *Session) ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error { return s.entity.ResponseMID(ctx, mid, v, err...) }
go
func (s *Session) ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error { return s.entity.ResponseMID(ctx, mid, v, err...) }
[ "func", "(", "s", "*", "Session", ")", "ResponseMID", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "v", "interface", "{", "}", ",", "err", "...", "bool", ")", "error", "{", "return", "s", ".", "entity", ".", "ResponseMID", "(", "...
// ResponseMID responses message to client, mid is // request message ID
[ "ResponseMID", "responses", "message", "to", "client", "mid", "is", "request", "message", "ID" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L208-L210
28,291
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
28,292
topfreegames/pitaya
session/session.go
SetData
func (s *Session) SetData(data map[string]interface{}) error { s.Lock() defer s.Unlock() s.data = data return s.updateEncodedData() }
go
func (s *Session) SetData(data map[string]interface{}) error { s.Lock() defer s.Unlock() s.data = data return s.updateEncodedData() }
[ "func", "(", "s", "*", "Session", ")", "SetData", "(", "data", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "s", ".", "data", "=", "data", ...
// SetData sets the whole session data
[ "SetData", "sets", "the", "whole", "session", "data" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L231-L237
28,293
topfreegames/pitaya
session/session.go
SetDataEncoded
func (s *Session) SetDataEncoded(encodedData []byte) error { if len(encodedData) == 0 { return nil } var data map[string]interface{} err := json.Unmarshal(encodedData, &data) if err != nil { return err } return s.SetData(data) }
go
func (s *Session) SetDataEncoded(encodedData []byte) error { if len(encodedData) == 0 { return nil } var data map[string]interface{} err := json.Unmarshal(encodedData, &data) if err != nil { return err } return s.SetData(data) }
[ "func", "(", "s", "*", "Session", ")", "SetDataEncoded", "(", "encodedData", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "encodedData", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "var", "data", "map", "[", "string", "]", "int...
// SetDataEncoded sets the whole session data from an encoded value
[ "SetDataEncoded", "sets", "the", "whole", "session", "data", "from", "an", "encoded", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L245-L255
28,294
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
28,295
topfreegames/pitaya
session/session.go
Bind
func (s *Session) Bind(ctx context.Context, uid string) error { if uid == "" { return constants.ErrIllegalUID } if s.UID() != "" { return constants.ErrSessionAlreadyBound } s.uid = uid for _, cb := range sessionBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } for _,...
go
func (s *Session) Bind(ctx context.Context, uid string) error { if uid == "" { return constants.ErrIllegalUID } if s.UID() != "" { return constants.ErrSessionAlreadyBound } s.uid = uid for _, cb := range sessionBindCallbacks { err := cb(ctx, s) if err != nil { s.uid = "" return err } } for _,...
[ "func", "(", "s", "*", "Session", ")", "Bind", "(", "ctx", "context", ".", "Context", ",", "uid", "string", ")", "error", "{", "if", "uid", "==", "\"", "\"", "{", "return", "constants", ".", "ErrIllegalUID", "\n", "}", "\n\n", "if", "s", ".", "UID"...
// Bind bind UID to current session
[ "Bind", "bind", "UID", "to", "current", "session" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L264-L304
28,296
topfreegames/pitaya
session/session.go
OnClose
func (s *Session) OnClose(c func()) error { if !s.IsFrontend { return constants.ErrOnCloseBackend } s.OnCloseCallbacks = append(s.OnCloseCallbacks, c) return nil }
go
func (s *Session) OnClose(c func()) error { if !s.IsFrontend { return constants.ErrOnCloseBackend } s.OnCloseCallbacks = append(s.OnCloseCallbacks, c) return nil }
[ "func", "(", "s", "*", "Session", ")", "OnClose", "(", "c", "func", "(", ")", ")", "error", "{", "if", "!", "s", ".", "IsFrontend", "{", "return", "constants", ".", "ErrOnCloseBackend", "\n", "}", "\n", "s", ".", "OnCloseCallbacks", "=", "append", "(...
// OnClose adds the function it receives to the callbacks that will be called // when the session is closed
[ "OnClose", "adds", "the", "function", "it", "receives", "to", "the", "callbacks", "that", "will", "be", "called", "when", "the", "session", "is", "closed" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L317-L323
28,297
topfreegames/pitaya
session/session.go
Close
func (s *Session) Close() { atomic.AddInt64(&SessionCount, -1) sessionsByID.Delete(s.ID()) sessionsByUID.Delete(s.UID()) // TODO: this logic should be moved to nats rpc server if s.IsFrontend && s.Subscriptions != nil && len(s.Subscriptions) > 0 { // if the user is bound to an userid and nats rpc server is being...
go
func (s *Session) Close() { atomic.AddInt64(&SessionCount, -1) sessionsByID.Delete(s.ID()) sessionsByUID.Delete(s.UID()) // TODO: this logic should be moved to nats rpc server if s.IsFrontend && s.Subscriptions != nil && len(s.Subscriptions) > 0 { // if the user is bound to an userid and nats rpc server is being...
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "{", "atomic", ".", "AddInt64", "(", "&", "SessionCount", ",", "-", "1", ")", "\n", "sessionsByID", ".", "Delete", "(", "s", ".", "ID", "(", ")", ")", "\n", "sessionsByUID", ".", "Delete", ...
// Close terminates current session, session related data will not be released, // all related data should be cleared explicitly in Session closed callback
[ "Close", "terminates", "current", "session", "session", "related", "data", "will", "not", "be", "released", "all", "related", "data", "should", "be", "cleared", "explicitly", "in", "Session", "closed", "callback" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L327-L344
28,298
topfreegames/pitaya
session/session.go
Remove
func (s *Session) Remove(key string) error { s.Lock() defer s.Unlock() delete(s.data, key) return s.updateEncodedData() }
go
func (s *Session) Remove(key string) error { s.Lock() defer s.Unlock() delete(s.data, key) return s.updateEncodedData() }
[ "func", "(", "s", "*", "Session", ")", "Remove", "(", "key", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "s", ...
// Remove delete data associated with the key from session storage
[ "Remove", "delete", "data", "associated", "with", "the", "key", "from", "session", "storage" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L352-L358
28,299
topfreegames/pitaya
session/session.go
HasKey
func (s *Session) HasKey(key string) bool { s.RLock() defer s.RUnlock() _, has := s.data[key] return has }
go
func (s *Session) HasKey(key string) bool { s.RLock() defer s.RUnlock() _, has := s.data[key] return has }
[ "func", "(", "s", "*", "Session", ")", "HasKey", "(", "key", "string", ")", "bool", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n\n", "_", ",", "has", ":=", "s", ".", "data", "[", "key", "]", "\n", "retur...
// HasKey decides whether a key has associated value
[ "HasKey", "decides", "whether", "a", "key", "has", "associated", "value" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/session.go#L370-L376