repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
micro/go-plugins
wrapper/trace/opentracing/opentracing.go
NewClientWrapper
func NewClientWrapper(ot opentracing.Tracer) client.Wrapper { return func(c client.Client) client.Client { if ot == nil { ot = opentracing.GlobalTracer() } return &otWrapper{ot, c} } }
go
func NewClientWrapper(ot opentracing.Tracer) client.Wrapper { return func(c client.Client) client.Client { if ot == nil { ot = opentracing.GlobalTracer() } return &otWrapper{ot, c} } }
[ "func", "NewClientWrapper", "(", "ot", "opentracing", ".", "Tracer", ")", "client", ".", "Wrapper", "{", "return", "func", "(", "c", "client", ".", "Client", ")", "client", ".", "Client", "{", "if", "ot", "==", "nil", "{", "ot", "=", "opentracing", ".", "GlobalTracer", "(", ")", "\n", "}", "\n", "return", "&", "otWrapper", "{", "ot", ",", "c", "}", "\n", "}", "\n", "}" ]
// NewClientWrapper accepts an open tracing Trace and returns a Client Wrapper
[ "NewClientWrapper", "accepts", "an", "open", "tracing", "Trace", "and", "returns", "a", "Client", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/opentracing/opentracing.go#L74-L81
train
micro/go-plugins
wrapper/trace/opentracing/opentracing.go
NewCallWrapper
func NewCallWrapper(ot opentracing.Tracer) client.CallWrapper { return func(cf client.CallFunc) client.CallFunc { return func(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error { if ot == nil { ot = opentracing.GlobalTracer() } name := fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()) ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return cf(ctx, node, req, rsp, opts) } } }
go
func NewCallWrapper(ot opentracing.Tracer) client.CallWrapper { return func(cf client.CallFunc) client.CallFunc { return func(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error { if ot == nil { ot = opentracing.GlobalTracer() } name := fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()) ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return cf(ctx, node, req, rsp, opts) } } }
[ "func", "NewCallWrapper", "(", "ot", "opentracing", ".", "Tracer", ")", "client", ".", "CallWrapper", "{", "return", "func", "(", "cf", "client", ".", "CallFunc", ")", "client", ".", "CallFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "node", "*", "registry", ".", "Node", ",", "req", "client", ".", "Request", ",", "rsp", "interface", "{", "}", ",", "opts", "client", ".", "CallOptions", ")", "error", "{", "if", "ot", "==", "nil", "{", "ot", "=", "opentracing", ".", "GlobalTracer", "(", ")", "\n", "}", "\n", "name", ":=", "fmt", ".", "Sprintf", "(", "\"%s.%s\"", ",", "req", ".", "Service", "(", ")", ",", "req", ".", "Endpoint", "(", ")", ")", "\n", "ctx", ",", "span", ",", "err", ":=", "StartSpanFromContext", "(", "ctx", ",", "ot", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "return", "cf", "(", "ctx", ",", "node", ",", "req", ",", "rsp", ",", "opts", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewCallWrapper accepts an opentracing Tracer and returns a Call Wrapper
[ "NewCallWrapper", "accepts", "an", "opentracing", "Tracer", "and", "returns", "a", "Call", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/opentracing/opentracing.go#L84-L99
train
micro/go-plugins
wrapper/trace/opentracing/opentracing.go
NewHandlerWrapper
func NewHandlerWrapper(ot opentracing.Tracer) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { if ot == nil { ot = opentracing.GlobalTracer() } name := fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()) ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return h(ctx, req, rsp) } } }
go
func NewHandlerWrapper(ot opentracing.Tracer) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { if ot == nil { ot = opentracing.GlobalTracer() } name := fmt.Sprintf("%s.%s", req.Service(), req.Endpoint()) ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return h(ctx, req, rsp) } } }
[ "func", "NewHandlerWrapper", "(", "ot", "opentracing", ".", "Tracer", ")", "server", ".", "HandlerWrapper", "{", "return", "func", "(", "h", "server", ".", "HandlerFunc", ")", "server", ".", "HandlerFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "req", "server", ".", "Request", ",", "rsp", "interface", "{", "}", ")", "error", "{", "if", "ot", "==", "nil", "{", "ot", "=", "opentracing", ".", "GlobalTracer", "(", ")", "\n", "}", "\n", "name", ":=", "fmt", ".", "Sprintf", "(", "\"%s.%s\"", ",", "req", ".", "Service", "(", ")", ",", "req", ".", "Endpoint", "(", ")", ")", "\n", "ctx", ",", "span", ",", "err", ":=", "StartSpanFromContext", "(", "ctx", ",", "ot", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "return", "h", "(", "ctx", ",", "req", ",", "rsp", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewHandlerWrapper accepts an opentracing Tracer and returns a Handler Wrapper
[ "NewHandlerWrapper", "accepts", "an", "opentracing", "Tracer", "and", "returns", "a", "Handler", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/opentracing/opentracing.go#L102-L117
train
micro/go-plugins
wrapper/trace/opentracing/opentracing.go
NewSubscriberWrapper
func NewSubscriberWrapper(ot opentracing.Tracer) server.SubscriberWrapper { return func(next server.SubscriberFunc) server.SubscriberFunc { return func(ctx context.Context, msg server.Message) error { name := "Pub to " + msg.Topic() if ot == nil { ot = opentracing.GlobalTracer() } ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return next(ctx, msg) } } }
go
func NewSubscriberWrapper(ot opentracing.Tracer) server.SubscriberWrapper { return func(next server.SubscriberFunc) server.SubscriberFunc { return func(ctx context.Context, msg server.Message) error { name := "Pub to " + msg.Topic() if ot == nil { ot = opentracing.GlobalTracer() } ctx, span, err := StartSpanFromContext(ctx, ot, name) if err != nil { return err } defer span.Finish() return next(ctx, msg) } } }
[ "func", "NewSubscriberWrapper", "(", "ot", "opentracing", ".", "Tracer", ")", "server", ".", "SubscriberWrapper", "{", "return", "func", "(", "next", "server", ".", "SubscriberFunc", ")", "server", ".", "SubscriberFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "msg", "server", ".", "Message", ")", "error", "{", "name", ":=", "\"Pub to \"", "+", "msg", ".", "Topic", "(", ")", "\n", "if", "ot", "==", "nil", "{", "ot", "=", "opentracing", ".", "GlobalTracer", "(", ")", "\n", "}", "\n", "ctx", ",", "span", ",", "err", ":=", "StartSpanFromContext", "(", "ctx", ",", "ot", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "return", "next", "(", "ctx", ",", "msg", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewSubscriberWrapper accepts an opentracing Tracer and returns a Subscriber Wrapper
[ "NewSubscriberWrapper", "accepts", "an", "opentracing", "Tracer", "and", "returns", "a", "Subscriber", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/opentracing/opentracing.go#L120-L135
train
micro/go-plugins
wrapper/ratelimiter/ratelimit/ratelimit.go
NewClientWrapper
func NewClientWrapper(b *ratelimit.Bucket, wait bool) client.Wrapper { fn := limit(b, wait, "go.micro.client") return func(c client.Client) client.Client { return &clientWrapper{fn, c} } }
go
func NewClientWrapper(b *ratelimit.Bucket, wait bool) client.Wrapper { fn := limit(b, wait, "go.micro.client") return func(c client.Client) client.Client { return &clientWrapper{fn, c} } }
[ "func", "NewClientWrapper", "(", "b", "*", "ratelimit", ".", "Bucket", ",", "wait", "bool", ")", "client", ".", "Wrapper", "{", "fn", ":=", "limit", "(", "b", ",", "wait", ",", "\"go.micro.client\"", ")", "\n", "return", "func", "(", "c", "client", ".", "Client", ")", "client", ".", "Client", "{", "return", "&", "clientWrapper", "{", "fn", ",", "c", "}", "\n", "}", "\n", "}" ]
// NewClientWrapper takes a rate limiter and wait flag and returns a client Wrapper.
[ "NewClientWrapper", "takes", "a", "rate", "limiter", "and", "wait", "flag", "and", "returns", "a", "client", "Wrapper", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/ratelimiter/ratelimit/ratelimit.go#L38-L44
train
micro/go-plugins
wrapper/ratelimiter/ratelimit/ratelimit.go
NewHandlerWrapper
func NewHandlerWrapper(b *ratelimit.Bucket, wait bool) server.HandlerWrapper { fn := limit(b, wait, "go.micro.server") return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { if err := fn(); err != nil { return err } return h(ctx, req, rsp) } } }
go
func NewHandlerWrapper(b *ratelimit.Bucket, wait bool) server.HandlerWrapper { fn := limit(b, wait, "go.micro.server") return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { if err := fn(); err != nil { return err } return h(ctx, req, rsp) } } }
[ "func", "NewHandlerWrapper", "(", "b", "*", "ratelimit", ".", "Bucket", ",", "wait", "bool", ")", "server", ".", "HandlerWrapper", "{", "fn", ":=", "limit", "(", "b", ",", "wait", ",", "\"go.micro.server\"", ")", "\n", "return", "func", "(", "h", "server", ".", "HandlerFunc", ")", "server", ".", "HandlerFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "req", "server", ".", "Request", ",", "rsp", "interface", "{", "}", ")", "error", "{", "if", "err", ":=", "fn", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "h", "(", "ctx", ",", "req", ",", "rsp", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewHandlerWrapper takes a rate limiter and wait flag and returns a client Wrapper.
[ "NewHandlerWrapper", "takes", "a", "rate", "limiter", "and", "wait", "flag", "and", "returns", "a", "client", "Wrapper", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/ratelimiter/ratelimit/ratelimit.go#L47-L58
train
micro/go-plugins
micro/trace/awsxray/options.go
WithClient
func WithClient(x *xray.XRay) Option { return func(o *Options) { o.Client = x } }
go
func WithClient(x *xray.XRay) Option { return func(o *Options) { o.Client = x } }
[ "func", "WithClient", "(", "x", "*", "xray", ".", "XRay", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "{", "o", ".", "Client", "=", "x", "\n", "}", "\n", "}" ]
// WithClient sets the XRay Client to use to send segments
[ "WithClient", "sets", "the", "XRay", "Client", "to", "use", "to", "send", "segments" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/micro/trace/awsxray/options.go#L26-L30
train
micro/go-plugins
wrapper/trace/opencensus/tracker.go
end
func (t *tracker) end(ctx context.Context, err error) { status := getResponseStatus(err) ctx, _ = tag.New(ctx, tag.Upsert(StatusCode, strconv.Itoa(int(status.Code)))) stats.Record(ctx, t.profile.LatencyMeasure.M(float64(time.Since(t.startedAt))/float64(time.Millisecond))) if t.span != nil { t.span.SetStatus(status) t.span.End() } }
go
func (t *tracker) end(ctx context.Context, err error) { status := getResponseStatus(err) ctx, _ = tag.New(ctx, tag.Upsert(StatusCode, strconv.Itoa(int(status.Code)))) stats.Record(ctx, t.profile.LatencyMeasure.M(float64(time.Since(t.startedAt))/float64(time.Millisecond))) if t.span != nil { t.span.SetStatus(status) t.span.End() } }
[ "func", "(", "t", "*", "tracker", ")", "end", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "{", "status", ":=", "getResponseStatus", "(", "err", ")", "\n", "ctx", ",", "_", "=", "tag", ".", "New", "(", "ctx", ",", "tag", ".", "Upsert", "(", "StatusCode", ",", "strconv", ".", "Itoa", "(", "int", "(", "status", ".", "Code", ")", ")", ")", ")", "\n", "stats", ".", "Record", "(", "ctx", ",", "t", ".", "profile", ".", "LatencyMeasure", ".", "M", "(", "float64", "(", "time", ".", "Since", "(", "t", ".", "startedAt", ")", ")", "/", "float64", "(", "time", ".", "Millisecond", ")", ")", ")", "\n", "if", "t", ".", "span", "!=", "nil", "{", "t", ".", "span", ".", "SetStatus", "(", "status", ")", "\n", "t", ".", "span", ".", "End", "(", ")", "\n", "}", "\n", "}" ]
// end a request's monitoring session. If there is a span ongoing, it will // be ended and metrics will be recorded.
[ "end", "a", "request", "s", "monitoring", "session", ".", "If", "there", "is", "a", "span", "ongoing", "it", "will", "be", "ended", "and", "metrics", "will", "be", "recorded", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/opencensus/tracker.go#L71-L81
train
micro/go-plugins
registry/eureka/marshalling.go
serviceToInstance
func serviceToInstance(service *registry.Service) (*fargo.Instance, error) { if len(service.Nodes) == 0 { return nil, errors.New("Require nodes") } node := service.Nodes[0] instance := &fargo.Instance{ App: service.Name, HostName: node.Address, IPAddr: node.Address, VipAddress: node.Address, SecureVipAddress: node.Address, Port: node.Port, Status: fargo.UP, UniqueID: func(i fargo.Instance) string { return fmt.Sprintf("%s:%s", node.Address, node.Id) }, DataCenterInfo: fargo.DataCenterInfo{Name: fargo.MyOwn}, } // set version instance.SetMetadataString("version", service.Version) // set instance ID instance.SetMetadataString("instanceId", node.Id) // set endpoints if b, err := json.Marshal(service.Endpoints); err == nil { instance.SetMetadataString("endpoints", string(b)) } // set metadata if b, err := json.Marshal(node.Metadata); err == nil { instance.SetMetadataString("metadata", string(b)) } return instance, nil }
go
func serviceToInstance(service *registry.Service) (*fargo.Instance, error) { if len(service.Nodes) == 0 { return nil, errors.New("Require nodes") } node := service.Nodes[0] instance := &fargo.Instance{ App: service.Name, HostName: node.Address, IPAddr: node.Address, VipAddress: node.Address, SecureVipAddress: node.Address, Port: node.Port, Status: fargo.UP, UniqueID: func(i fargo.Instance) string { return fmt.Sprintf("%s:%s", node.Address, node.Id) }, DataCenterInfo: fargo.DataCenterInfo{Name: fargo.MyOwn}, } // set version instance.SetMetadataString("version", service.Version) // set instance ID instance.SetMetadataString("instanceId", node.Id) // set endpoints if b, err := json.Marshal(service.Endpoints); err == nil { instance.SetMetadataString("endpoints", string(b)) } // set metadata if b, err := json.Marshal(node.Metadata); err == nil { instance.SetMetadataString("metadata", string(b)) } return instance, nil }
[ "func", "serviceToInstance", "(", "service", "*", "registry", ".", "Service", ")", "(", "*", "fargo", ".", "Instance", ",", "error", ")", "{", "if", "len", "(", "service", ".", "Nodes", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"Require nodes\"", ")", "\n", "}", "\n", "node", ":=", "service", ".", "Nodes", "[", "0", "]", "\n", "instance", ":=", "&", "fargo", ".", "Instance", "{", "App", ":", "service", ".", "Name", ",", "HostName", ":", "node", ".", "Address", ",", "IPAddr", ":", "node", ".", "Address", ",", "VipAddress", ":", "node", ".", "Address", ",", "SecureVipAddress", ":", "node", ".", "Address", ",", "Port", ":", "node", ".", "Port", ",", "Status", ":", "fargo", ".", "UP", ",", "UniqueID", ":", "func", "(", "i", "fargo", ".", "Instance", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s:%s\"", ",", "node", ".", "Address", ",", "node", ".", "Id", ")", "\n", "}", ",", "DataCenterInfo", ":", "fargo", ".", "DataCenterInfo", "{", "Name", ":", "fargo", ".", "MyOwn", "}", ",", "}", "\n", "instance", ".", "SetMetadataString", "(", "\"version\"", ",", "service", ".", "Version", ")", "\n", "instance", ".", "SetMetadataString", "(", "\"instanceId\"", ",", "node", ".", "Id", ")", "\n", "if", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "service", ".", "Endpoints", ")", ";", "err", "==", "nil", "{", "instance", ".", "SetMetadataString", "(", "\"endpoints\"", ",", "string", "(", "b", ")", ")", "\n", "}", "\n", "if", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "node", ".", "Metadata", ")", ";", "err", "==", "nil", "{", "instance", ".", "SetMetadataString", "(", "\"metadata\"", ",", "string", "(", "b", ")", ")", "\n", "}", "\n", "return", "instance", ",", "nil", "\n", "}" ]
// only parses first node
[ "only", "parses", "first", "node" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/eureka/marshalling.go#L74-L112
train
micro/go-plugins
registry/kubernetes/watcher.go
updateCache
func (k *k8sWatcher) updateCache() ([]*registry.Result, error) { podList, err := k.registry.client.ListPods(podSelector) if err != nil { return nil, err } k.RLock() k.RUnlock() var results []*registry.Result for _, pod := range podList.Items { rslts := k.buildPodResults(&pod, nil) for _, r := range rslts { results = append(results, r) } k.Lock() k.pods[pod.Metadata.Name] = &pod k.Unlock() } return results, nil }
go
func (k *k8sWatcher) updateCache() ([]*registry.Result, error) { podList, err := k.registry.client.ListPods(podSelector) if err != nil { return nil, err } k.RLock() k.RUnlock() var results []*registry.Result for _, pod := range podList.Items { rslts := k.buildPodResults(&pod, nil) for _, r := range rslts { results = append(results, r) } k.Lock() k.pods[pod.Metadata.Name] = &pod k.Unlock() } return results, nil }
[ "func", "(", "k", "*", "k8sWatcher", ")", "updateCache", "(", ")", "(", "[", "]", "*", "registry", ".", "Result", ",", "error", ")", "{", "podList", ",", "err", ":=", "k", ".", "registry", ".", "client", ".", "ListPods", "(", "podSelector", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "k", ".", "RLock", "(", ")", "\n", "k", ".", "RUnlock", "(", ")", "\n", "var", "results", "[", "]", "*", "registry", ".", "Result", "\n", "for", "_", ",", "pod", ":=", "range", "podList", ".", "Items", "{", "rslts", ":=", "k", ".", "buildPodResults", "(", "&", "pod", ",", "nil", ")", "\n", "for", "_", ",", "r", ":=", "range", "rslts", "{", "results", "=", "append", "(", "results", ",", "r", ")", "\n", "}", "\n", "k", ".", "Lock", "(", ")", "\n", "k", ".", "pods", "[", "pod", ".", "Metadata", ".", "Name", "]", "=", "&", "pod", "\n", "k", ".", "Unlock", "(", ")", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// build a cache of pods when the watcher starts.
[ "build", "a", "cache", "of", "pods", "when", "the", "watcher", "starts", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/watcher.go#L25-L49
train
micro/go-plugins
registry/kubernetes/watcher.go
buildPodResults
func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*registry.Result { var results []*registry.Result ignore := make(map[string]bool) if pod.Metadata != nil { for ak, av := range pod.Metadata.Annotations { // check this annotation kv is a service notation if !strings.HasPrefix(ak, annotationServiceKeyPrefix) { continue } if av == nil { continue } // ignore when we check the cached annotations // as we take care of it here ignore[ak] = true // compare aginst cache. var cacheExists bool var cav *string if cache != nil && cache.Metadata != nil { cav, cacheExists = cache.Metadata.Annotations[ak] if cacheExists && cav != nil && cav == av { // service notation exists and is identical - // no change result required. continue } } rslt := &registry.Result{} if cacheExists { rslt.Action = "update" } else { rslt.Action = "create" } // unmarshal service notation from annotation value err := json.Unmarshal([]byte(*av), &rslt.Service) if err != nil { continue } results = append(results, rslt) } } // loop through cache annotations to find services // not accounted for above, and "delete" them. if cache != nil && cache.Metadata != nil { for ak, av := range cache.Metadata.Annotations { if ignore[ak] { continue } // check this annotation kv is a service notation if !strings.HasPrefix(ak, annotationServiceKeyPrefix) { continue } rslt := &registry.Result{Action: "delete"} // unmarshal service notation from annotation value err := json.Unmarshal([]byte(*av), &rslt.Service) if err != nil { continue } results = append(results, rslt) } } return results }
go
func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*registry.Result { var results []*registry.Result ignore := make(map[string]bool) if pod.Metadata != nil { for ak, av := range pod.Metadata.Annotations { // check this annotation kv is a service notation if !strings.HasPrefix(ak, annotationServiceKeyPrefix) { continue } if av == nil { continue } // ignore when we check the cached annotations // as we take care of it here ignore[ak] = true // compare aginst cache. var cacheExists bool var cav *string if cache != nil && cache.Metadata != nil { cav, cacheExists = cache.Metadata.Annotations[ak] if cacheExists && cav != nil && cav == av { // service notation exists and is identical - // no change result required. continue } } rslt := &registry.Result{} if cacheExists { rslt.Action = "update" } else { rslt.Action = "create" } // unmarshal service notation from annotation value err := json.Unmarshal([]byte(*av), &rslt.Service) if err != nil { continue } results = append(results, rslt) } } // loop through cache annotations to find services // not accounted for above, and "delete" them. if cache != nil && cache.Metadata != nil { for ak, av := range cache.Metadata.Annotations { if ignore[ak] { continue } // check this annotation kv is a service notation if !strings.HasPrefix(ak, annotationServiceKeyPrefix) { continue } rslt := &registry.Result{Action: "delete"} // unmarshal service notation from annotation value err := json.Unmarshal([]byte(*av), &rslt.Service) if err != nil { continue } results = append(results, rslt) } } return results }
[ "func", "(", "k", "*", "k8sWatcher", ")", "buildPodResults", "(", "pod", "*", "client", ".", "Pod", ",", "cache", "*", "client", ".", "Pod", ")", "[", "]", "*", "registry", ".", "Result", "{", "var", "results", "[", "]", "*", "registry", ".", "Result", "\n", "ignore", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "if", "pod", ".", "Metadata", "!=", "nil", "{", "for", "ak", ",", "av", ":=", "range", "pod", ".", "Metadata", ".", "Annotations", "{", "if", "!", "strings", ".", "HasPrefix", "(", "ak", ",", "annotationServiceKeyPrefix", ")", "{", "continue", "\n", "}", "\n", "if", "av", "==", "nil", "{", "continue", "\n", "}", "\n", "ignore", "[", "ak", "]", "=", "true", "\n", "var", "cacheExists", "bool", "\n", "var", "cav", "*", "string", "\n", "if", "cache", "!=", "nil", "&&", "cache", ".", "Metadata", "!=", "nil", "{", "cav", ",", "cacheExists", "=", "cache", ".", "Metadata", ".", "Annotations", "[", "ak", "]", "\n", "if", "cacheExists", "&&", "cav", "!=", "nil", "&&", "cav", "==", "av", "{", "continue", "\n", "}", "\n", "}", "\n", "rslt", ":=", "&", "registry", ".", "Result", "{", "}", "\n", "if", "cacheExists", "{", "rslt", ".", "Action", "=", "\"update\"", "\n", "}", "else", "{", "rslt", ".", "Action", "=", "\"create\"", "\n", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "*", "av", ")", ",", "&", "rslt", ".", "Service", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "results", "=", "append", "(", "results", ",", "rslt", ")", "\n", "}", "\n", "}", "\n", "if", "cache", "!=", "nil", "&&", "cache", ".", "Metadata", "!=", "nil", "{", "for", "ak", ",", "av", ":=", "range", "cache", ".", "Metadata", ".", "Annotations", "{", "if", "ignore", "[", "ak", "]", "{", "continue", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "ak", ",", "annotationServiceKeyPrefix", ")", "{", "continue", "\n", "}", "\n", "rslt", ":=", "&", "registry", ".", "Result", "{", "Action", ":", "\"delete\"", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "*", "av", ")", ",", "&", "rslt", ".", "Service", ")", "\n", "if", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "results", "=", "append", "(", "results", ",", "rslt", ")", "\n", "}", "\n", "}", "\n", "return", "results", "\n", "}" ]
// look through pod annotations, compare against cache if present // and return a list of results to send down the wire.
[ "look", "through", "pod", "annotations", "compare", "against", "cache", "if", "present", "and", "return", "a", "list", "of", "results", "to", "send", "down", "the", "wire", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/watcher.go#L53-L127
train
micro/go-plugins
registry/kubernetes/watcher.go
handleEvent
func (k *k8sWatcher) handleEvent(event watch.Event) { var pod client.Pod if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { log.Log("K8s Watcher: Couldnt unmarshal event object from pod") return } switch event.Type { case watch.Modified: // Pod was modified k.RLock() cache := k.pods[pod.Metadata.Name] k.RUnlock() // service could have been added, edited or removed. var results []*registry.Result if pod.Status.Phase == podRunning { results = k.buildPodResults(&pod, cache) } else { // passing in cache might not return all results results = k.buildPodResults(&pod, nil) } for _, result := range results { // pod isnt running if pod.Status.Phase != podRunning { result.Action = "delete" } k.next <- result } k.Lock() k.pods[pod.Metadata.Name] = &pod k.Unlock() return case watch.Deleted: // Pod was deleted // passing in cache might not return all results results := k.buildPodResults(&pod, nil) for _, result := range results { result.Action = "delete" k.next <- result } k.Lock() delete(k.pods, pod.Metadata.Name) k.Unlock() return } }
go
func (k *k8sWatcher) handleEvent(event watch.Event) { var pod client.Pod if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { log.Log("K8s Watcher: Couldnt unmarshal event object from pod") return } switch event.Type { case watch.Modified: // Pod was modified k.RLock() cache := k.pods[pod.Metadata.Name] k.RUnlock() // service could have been added, edited or removed. var results []*registry.Result if pod.Status.Phase == podRunning { results = k.buildPodResults(&pod, cache) } else { // passing in cache might not return all results results = k.buildPodResults(&pod, nil) } for _, result := range results { // pod isnt running if pod.Status.Phase != podRunning { result.Action = "delete" } k.next <- result } k.Lock() k.pods[pod.Metadata.Name] = &pod k.Unlock() return case watch.Deleted: // Pod was deleted // passing in cache might not return all results results := k.buildPodResults(&pod, nil) for _, result := range results { result.Action = "delete" k.next <- result } k.Lock() delete(k.pods, pod.Metadata.Name) k.Unlock() return } }
[ "func", "(", "k", "*", "k8sWatcher", ")", "handleEvent", "(", "event", "watch", ".", "Event", ")", "{", "var", "pod", "client", ".", "Pod", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "event", ".", "Object", ")", ",", "&", "pod", ")", ";", "err", "!=", "nil", "{", "log", ".", "Log", "(", "\"K8s Watcher: Couldnt unmarshal event object from pod\"", ")", "\n", "return", "\n", "}", "\n", "switch", "event", ".", "Type", "{", "case", "watch", ".", "Modified", ":", "k", ".", "RLock", "(", ")", "\n", "cache", ":=", "k", ".", "pods", "[", "pod", ".", "Metadata", ".", "Name", "]", "\n", "k", ".", "RUnlock", "(", ")", "\n", "var", "results", "[", "]", "*", "registry", ".", "Result", "\n", "if", "pod", ".", "Status", ".", "Phase", "==", "podRunning", "{", "results", "=", "k", ".", "buildPodResults", "(", "&", "pod", ",", "cache", ")", "\n", "}", "else", "{", "results", "=", "k", ".", "buildPodResults", "(", "&", "pod", ",", "nil", ")", "\n", "}", "\n", "for", "_", ",", "result", ":=", "range", "results", "{", "if", "pod", ".", "Status", ".", "Phase", "!=", "podRunning", "{", "result", ".", "Action", "=", "\"delete\"", "\n", "}", "\n", "k", ".", "next", "<-", "result", "\n", "}", "\n", "k", ".", "Lock", "(", ")", "\n", "k", ".", "pods", "[", "pod", ".", "Metadata", ".", "Name", "]", "=", "&", "pod", "\n", "k", ".", "Unlock", "(", ")", "\n", "return", "\n", "case", "watch", ".", "Deleted", ":", "results", ":=", "k", ".", "buildPodResults", "(", "&", "pod", ",", "nil", ")", "\n", "for", "_", ",", "result", ":=", "range", "results", "{", "result", ".", "Action", "=", "\"delete\"", "\n", "k", ".", "next", "<-", "result", "\n", "}", "\n", "k", ".", "Lock", "(", ")", "\n", "delete", "(", "k", ".", "pods", ",", "pod", ".", "Metadata", ".", "Name", ")", "\n", "k", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n", "}" ]
// handleEvent will taken an event from the k8s pods API and do the correct // things with the result, based on the local cache.
[ "handleEvent", "will", "taken", "an", "event", "from", "the", "k8s", "pods", "API", "and", "do", "the", "correct", "things", "with", "the", "result", "based", "on", "the", "local", "cache", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/watcher.go#L131-L185
train
micro/go-plugins
registry/kubernetes/watcher.go
Next
func (k *k8sWatcher) Next() (*registry.Result, error) { r, ok := <-k.next if !ok { return nil, errors.New("result chan closed") } return r, nil }
go
func (k *k8sWatcher) Next() (*registry.Result, error) { r, ok := <-k.next if !ok { return nil, errors.New("result chan closed") } return r, nil }
[ "func", "(", "k", "*", "k8sWatcher", ")", "Next", "(", ")", "(", "*", "registry", ".", "Result", ",", "error", ")", "{", "r", ",", "ok", ":=", "<-", "k", ".", "next", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"result chan closed\"", ")", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// Next will block until a new result comes in
[ "Next", "will", "block", "until", "a", "new", "result", "comes", "in" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/watcher.go#L188-L194
train
micro/go-plugins
registry/kubernetes/watcher.go
Stop
func (k *k8sWatcher) Stop() { k.watcher.Stop() select { case <-k.next: return default: close(k.next) } }
go
func (k *k8sWatcher) Stop() { k.watcher.Stop() select { case <-k.next: return default: close(k.next) } }
[ "func", "(", "k", "*", "k8sWatcher", ")", "Stop", "(", ")", "{", "k", ".", "watcher", ".", "Stop", "(", ")", "\n", "select", "{", "case", "<-", "k", ".", "next", ":", "return", "\n", "default", ":", "close", "(", "k", ".", "next", ")", "\n", "}", "\n", "}" ]
// Stop will cancel any requests, and close channels
[ "Stop", "will", "cancel", "any", "requests", "and", "close", "channels" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/watcher.go#L197-L206
train
micro/go-plugins
wrapper/trace/datadog/datadog.go
NewClientWrapper
func NewClientWrapper() client.Wrapper { return func(c client.Client) client.Client { return &ddWrapper{c} } }
go
func NewClientWrapper() client.Wrapper { return func(c client.Client) client.Client { return &ddWrapper{c} } }
[ "func", "NewClientWrapper", "(", ")", "client", ".", "Wrapper", "{", "return", "func", "(", "c", "client", ".", "Client", ")", "client", ".", "Client", "{", "return", "&", "ddWrapper", "{", "c", "}", "\n", "}", "\n", "}" ]
// NewClientWrapper returns a Client wrapped in tracer
[ "NewClientWrapper", "returns", "a", "Client", "wrapped", "in", "tracer" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/datadog/datadog.go#L49-L53
train
micro/go-plugins
wrapper/trace/datadog/datadog.go
NewCallWrapper
func NewCallWrapper() client.CallWrapper { return func(cf client.CallFunc) client.CallFunc { return func(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error { t := newRequestTracker(req, ClientProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(nil, noDebugStack) }() return cf(ctx, node, req, rsp, opts) } } }
go
func NewCallWrapper() client.CallWrapper { return func(cf client.CallFunc) client.CallFunc { return func(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error { t := newRequestTracker(req, ClientProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(nil, noDebugStack) }() return cf(ctx, node, req, rsp, opts) } } }
[ "func", "NewCallWrapper", "(", ")", "client", ".", "CallWrapper", "{", "return", "func", "(", "cf", "client", ".", "CallFunc", ")", "client", ".", "CallFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "node", "*", "registry", ".", "Node", ",", "req", "client", ".", "Request", ",", "rsp", "interface", "{", "}", ",", "opts", "client", ".", "CallOptions", ")", "error", "{", "t", ":=", "newRequestTracker", "(", "req", ",", "ClientProfile", ")", "\n", "ctx", "=", "t", ".", "StartSpanFromContext", "(", "ctx", ")", "\n", "defer", "func", "(", ")", "{", "t", ".", "finishWithError", "(", "nil", ",", "noDebugStack", ")", "\n", "}", "(", ")", "\n", "return", "cf", "(", "ctx", ",", "node", ",", "req", ",", "rsp", ",", "opts", ")", "\n", "}", "\n", "}", "\n", "}" ]
// NewCallWrapper returns a Call Wrapper
[ "NewCallWrapper", "returns", "a", "Call", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/datadog/datadog.go#L56-L69
train
micro/go-plugins
wrapper/trace/datadog/datadog.go
NewHandlerWrapper
func NewHandlerWrapper() server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) (err error) { if req.Endpoint() != "Debug.Health" { t := newRequestTracker(req, ServerProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(err, noDebugStack) }() } err = h(ctx, req, rsp) return } } }
go
func NewHandlerWrapper() server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) (err error) { if req.Endpoint() != "Debug.Health" { t := newRequestTracker(req, ServerProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(err, noDebugStack) }() } err = h(ctx, req, rsp) return } } }
[ "func", "NewHandlerWrapper", "(", ")", "server", ".", "HandlerWrapper", "{", "return", "func", "(", "h", "server", ".", "HandlerFunc", ")", "server", ".", "HandlerFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "req", "server", ".", "Request", ",", "rsp", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "if", "req", ".", "Endpoint", "(", ")", "!=", "\"Debug.Health\"", "{", "t", ":=", "newRequestTracker", "(", "req", ",", "ServerProfile", ")", "\n", "ctx", "=", "t", ".", "StartSpanFromContext", "(", "ctx", ")", "\n", "defer", "func", "(", ")", "{", "t", ".", "finishWithError", "(", "err", ",", "noDebugStack", ")", "\n", "}", "(", ")", "\n", "}", "\n", "err", "=", "h", "(", "ctx", ",", "req", ",", "rsp", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// NewHandlerWrapper returns a Handler Wrapper
[ "NewHandlerWrapper", "returns", "a", "Handler", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/datadog/datadog.go#L72-L88
train
micro/go-plugins
wrapper/trace/datadog/datadog.go
NewSubscriberWrapper
func NewSubscriberWrapper() server.SubscriberWrapper { return func(next server.SubscriberFunc) server.SubscriberFunc { return func(ctx context.Context, msg server.Message) (err error) { t := newPublicationTracker(msg, ServerProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(err, noDebugStack) }() err = next(ctx, msg) return } } }
go
func NewSubscriberWrapper() server.SubscriberWrapper { return func(next server.SubscriberFunc) server.SubscriberFunc { return func(ctx context.Context, msg server.Message) (err error) { t := newPublicationTracker(msg, ServerProfile) ctx = t.StartSpanFromContext(ctx) defer func() { t.finishWithError(err, noDebugStack) }() err = next(ctx, msg) return } } }
[ "func", "NewSubscriberWrapper", "(", ")", "server", ".", "SubscriberWrapper", "{", "return", "func", "(", "next", "server", ".", "SubscriberFunc", ")", "server", ".", "SubscriberFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "msg", "server", ".", "Message", ")", "(", "err", "error", ")", "{", "t", ":=", "newPublicationTracker", "(", "msg", ",", "ServerProfile", ")", "\n", "ctx", "=", "t", ".", "StartSpanFromContext", "(", "ctx", ")", "\n", "defer", "func", "(", ")", "{", "t", ".", "finishWithError", "(", "err", ",", "noDebugStack", ")", "\n", "}", "(", ")", "\n", "err", "=", "next", "(", "ctx", ",", "msg", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// NewSubscriberWrapper returns a Subscriber Wrapper
[ "NewSubscriberWrapper", "returns", "a", "Subscriber", "Wrapper" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/wrapper/trace/datadog/datadog.go#L91-L104
train
micro/go-plugins
registry/kubernetes/client/api/response.go
Into
func (r *Response) Into(data interface{}) error { if r.err != nil { return r.err } defer r.res.Body.Close() decoder := json.NewDecoder(r.res.Body) err := decoder.Decode(&data) if err != nil { return ErrDecode } return r.err }
go
func (r *Response) Into(data interface{}) error { if r.err != nil { return r.err } defer r.res.Body.Close() decoder := json.NewDecoder(r.res.Body) err := decoder.Decode(&data) if err != nil { return ErrDecode } return r.err }
[ "func", "(", "r", "*", "Response", ")", "Into", "(", "data", "interface", "{", "}", ")", "error", "{", "if", "r", ".", "err", "!=", "nil", "{", "return", "r", ".", "err", "\n", "}", "\n", "defer", "r", ".", "res", ".", "Body", ".", "Close", "(", ")", "\n", "decoder", ":=", "json", ".", "NewDecoder", "(", "r", ".", "res", ".", "Body", ")", "\n", "err", ":=", "decoder", ".", "Decode", "(", "&", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ErrDecode", "\n", "}", "\n", "return", "r", ".", "err", "\n", "}" ]
// Into decode body into `data`
[ "Into", "decode", "body", "into", "data" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/client/api/response.go#L48-L61
train
micro/go-plugins
registry/nats/options.go
Options
func Options(nopts nats.Options) registry.Option { return func(o *registry.Options) { if o.Context == nil { o.Context = context.Background() } o.Context = context.WithValue(o.Context, optionsKey{}, nopts) } }
go
func Options(nopts nats.Options) registry.Option { return func(o *registry.Options) { if o.Context == nil { o.Context = context.Background() } o.Context = context.WithValue(o.Context, optionsKey{}, nopts) } }
[ "func", "Options", "(", "nopts", "nats", ".", "Options", ")", "registry", ".", "Option", "{", "return", "func", "(", "o", "*", "registry", ".", "Options", ")", "{", "if", "o", ".", "Context", "==", "nil", "{", "o", ".", "Context", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "optionsKey", "{", "}", ",", "nopts", ")", "\n", "}", "\n", "}" ]
// Options allow to inject a nats.Options struct for configuring // the nats connection
[ "Options", "allow", "to", "inject", "a", "nats", ".", "Options", "struct", "for", "configuring", "the", "nats", "connection" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/nats/options.go#L40-L47
train
micro/go-plugins
registry/kubernetes/client/client.go
NewClientByHost
func NewClientByHost(host string) Kubernetes { tr := &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, DisableCompression: true, } c := &http.Client{ Transport: tr, } return &client{ opts: &api.Options{ Client: c, Host: host, Namespace: "default", }, } }
go
func NewClientByHost(host string) Kubernetes { tr := &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, DisableCompression: true, } c := &http.Client{ Transport: tr, } return &client{ opts: &api.Options{ Client: c, Host: host, Namespace: "default", }, } }
[ "func", "NewClientByHost", "(", "host", "string", ")", "Kubernetes", "{", "tr", ":=", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "&", "tls", ".", "Config", "{", "InsecureSkipVerify", ":", "true", ",", "}", ",", "DisableCompression", ":", "true", ",", "}", "\n", "c", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "tr", ",", "}", "\n", "return", "&", "client", "{", "opts", ":", "&", "api", ".", "Options", "{", "Client", ":", "c", ",", "Host", ":", "host", ",", "Namespace", ":", "\"default\"", ",", "}", ",", "}", "\n", "}" ]
// NewClientByHost sets up a client by host
[ "NewClientByHost", "sets", "up", "a", "client", "by", "host" ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/client/client.go#L65-L84
train
micro/go-plugins
registry/kubernetes/client/client.go
NewClientInCluster
func NewClientInCluster() Kubernetes { host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") s, err := os.Stat(serviceAccountPath) if err != nil { log.Fatal(err) } if s == nil || !s.IsDir() { log.Fatal(errors.New("no k8s service account found")) } token, err := ioutil.ReadFile(path.Join(serviceAccountPath, "token")) if err != nil { log.Fatal(err) } t := string(token) ns, err := detectNamespace() if err != nil { log.Fatal(err) } crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) if err != nil { log.Fatal(err) } c := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ RootCAs: crt, }, DisableCompression: true, }, } return &client{ opts: &api.Options{ Client: c, Host: host, Namespace: ns, BearerToken: &t, }, } }
go
func NewClientInCluster() Kubernetes { host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") s, err := os.Stat(serviceAccountPath) if err != nil { log.Fatal(err) } if s == nil || !s.IsDir() { log.Fatal(errors.New("no k8s service account found")) } token, err := ioutil.ReadFile(path.Join(serviceAccountPath, "token")) if err != nil { log.Fatal(err) } t := string(token) ns, err := detectNamespace() if err != nil { log.Fatal(err) } crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) if err != nil { log.Fatal(err) } c := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ RootCAs: crt, }, DisableCompression: true, }, } return &client{ opts: &api.Options{ Client: c, Host: host, Namespace: ns, BearerToken: &t, }, } }
[ "func", "NewClientInCluster", "(", ")", "Kubernetes", "{", "host", ":=", "\"https://\"", "+", "os", ".", "Getenv", "(", "\"KUBERNETES_SERVICE_HOST\"", ")", "+", "\":\"", "+", "os", ".", "Getenv", "(", "\"KUBERNETES_SERVICE_PORT\"", ")", "\n", "s", ",", "err", ":=", "os", ".", "Stat", "(", "serviceAccountPath", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "if", "s", "==", "nil", "||", "!", "s", ".", "IsDir", "(", ")", "{", "log", ".", "Fatal", "(", "errors", ".", "New", "(", "\"no k8s service account found\"", ")", ")", "\n", "}", "\n", "token", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ".", "Join", "(", "serviceAccountPath", ",", "\"token\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "t", ":=", "string", "(", "token", ")", "\n", "ns", ",", "err", ":=", "detectNamespace", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "crt", ",", "err", ":=", "CertPoolFromFile", "(", "path", ".", "Join", "(", "serviceAccountPath", ",", "\"ca.crt\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "c", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "&", "tls", ".", "Config", "{", "RootCAs", ":", "crt", ",", "}", ",", "DisableCompression", ":", "true", ",", "}", ",", "}", "\n", "return", "&", "client", "{", "opts", ":", "&", "api", ".", "Options", "{", "Client", ":", "c", ",", "Host", ":", "host", ",", "Namespace", ":", "ns", ",", "BearerToken", ":", "&", "t", ",", "}", ",", "}", "\n", "}" ]
// NewClientInCluster should work similarily to the official api // NewInClient by setting up a client configuration for use within // a k8s pod.
[ "NewClientInCluster", "should", "work", "similarily", "to", "the", "official", "api", "NewInClient", "by", "setting", "up", "a", "client", "configuration", "for", "use", "within", "a", "k8s", "pod", "." ]
d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0
https://github.com/micro/go-plugins/blob/d1cb339c5c5a3ab1e4be090c75a3cc03e38348e0/registry/kubernetes/client/client.go#L89-L133
train
topfreegames/pitaya
examples/demo/cluster_grpc/services/room.go
Outbound
func (Stats *Stats) Outbound(ctx context.Context, in []byte) ([]byte, error) { Stats.outboundBytes += len(in) return in, nil }
go
func (Stats *Stats) Outbound(ctx context.Context, in []byte) ([]byte, error) { Stats.outboundBytes += len(in) return in, nil }
[ "func", "(", "Stats", "*", "Stats", ")", "Outbound", "(", "ctx", "context", ".", "Context", ",", "in", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "Stats", ".", "outboundBytes", "+=", "len", "(", "in", ")", "\n", "return", "in", ",", "nil", "\n", "}" ]
// Outbound gets the outbound status
[ "Outbound", "gets", "the", "outbound", "status" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_grpc/services/room.go#L64-L67
train
topfreegames/pitaya
examples/demo/cluster_grpc/services/room.go
Inbound
func (Stats *Stats) Inbound(ctx context.Context, in []byte) ([]byte, error) { Stats.inboundBytes += len(in) return in, nil }
go
func (Stats *Stats) Inbound(ctx context.Context, in []byte) ([]byte, error) { Stats.inboundBytes += len(in) return in, nil }
[ "func", "(", "Stats", "*", "Stats", ")", "Inbound", "(", "ctx", "context", ".", "Context", ",", "in", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "Stats", ".", "inboundBytes", "+=", "len", "(", "in", ")", "\n", "return", "in", ",", "nil", "\n", "}" ]
// Inbound gets the inbound status
[ "Inbound", "gets", "the", "inbound", "status" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_grpc/services/room.go#L70-L73
train
topfreegames/pitaya
examples/demo/cluster_grpc/services/room.go
MessageRemote
func (r *Room) MessageRemote(ctx context.Context, msg *UserMessage, b bool, s string) (*UserMessage, error) { return msg, nil }
go
func (r *Room) MessageRemote(ctx context.Context, msg *UserMessage, b bool, s string) (*UserMessage, error) { return msg, nil }
[ "func", "(", "r", "*", "Room", ")", "MessageRemote", "(", "ctx", "context", ".", "Context", ",", "msg", "*", "UserMessage", ",", "b", "bool", ",", "s", "string", ")", "(", "*", "UserMessage", ",", "error", ")", "{", "return", "msg", ",", "nil", "\n", "}" ]
// MessageRemote just echoes the given message
[ "MessageRemote", "just", "echoes", "the", "given", "message" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/cluster_grpc/services/room.go#L175-L177
train
topfreegames/pitaya
session/mocks/session.go
NewMockNetworkEntity
func NewMockNetworkEntity(ctrl *gomock.Controller) *MockNetworkEntity { mock := &MockNetworkEntity{ctrl: ctrl} mock.recorder = &MockNetworkEntityMockRecorder{mock} return mock }
go
func NewMockNetworkEntity(ctrl *gomock.Controller) *MockNetworkEntity { mock := &MockNetworkEntity{ctrl: ctrl} mock.recorder = &MockNetworkEntityMockRecorder{mock} return mock }
[ "func", "NewMockNetworkEntity", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockNetworkEntity", "{", "mock", ":=", "&", "MockNetworkEntity", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockNetworkEntityMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockNetworkEntity creates a new mock instance
[ "NewMockNetworkEntity", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L27-L31
train
topfreegames/pitaya
session/mocks/session.go
Push
func (m *MockNetworkEntity) Push(route string, v interface{}) error { ret := m.ctrl.Call(m, "Push", route, v) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockNetworkEntity) Push(route string, v interface{}) error { ret := m.ctrl.Call(m, "Push", route, v) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockNetworkEntity", ")", "Push", "(", "route", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"Push\"", ",", "route", ",", "v", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// Push mocks base method
[ "Push", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L39-L43
train
topfreegames/pitaya
session/mocks/session.go
Push
func (mr *MockNetworkEntityMockRecorder) Push(route, v interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Push", reflect.TypeOf((*MockNetworkEntity)(nil).Push), route, v) }
go
func (mr *MockNetworkEntityMockRecorder) Push(route, v interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Push", reflect.TypeOf((*MockNetworkEntity)(nil).Push), route, v) }
[ "func", "(", "mr", "*", "MockNetworkEntityMockRecorder", ")", "Push", "(", "route", ",", "v", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"Push\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockNetworkEntity", ")", "(", "nil", ")", ".", "Push", ")", ",", "route", ",", "v", ")", "\n", "}" ]
// Push indicates an expected call of Push
[ "Push", "indicates", "an", "expected", "call", "of", "Push" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L46-L48
train
topfreegames/pitaya
session/mocks/session.go
ResponseMID
func (m *MockNetworkEntity) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { varargs := []interface{}{ctx, mid, v} for _, a := range isError { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "ResponseMID", varargs...) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockNetworkEntity) ResponseMID(ctx context.Context, mid uint, v interface{}, isError ...bool) error { varargs := []interface{}{ctx, mid, v} for _, a := range isError { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "ResponseMID", varargs...) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockNetworkEntity", ")", "ResponseMID", "(", "ctx", "context", ".", "Context", ",", "mid", "uint", ",", "v", "interface", "{", "}", ",", "isError", "...", "bool", ")", "error", "{", "varargs", ":=", "[", "]", "interface", "{", "}", "{", "ctx", ",", "mid", ",", "v", "}", "\n", "for", "_", ",", "a", ":=", "range", "isError", "{", "varargs", "=", "append", "(", "varargs", ",", "a", ")", "\n", "}", "\n", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"ResponseMID\"", ",", "varargs", "...", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// ResponseMID mocks base method
[ "ResponseMID", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L51-L59
train
topfreegames/pitaya
session/mocks/session.go
ResponseMID
func (mr *MockNetworkEntityMockRecorder) ResponseMID(ctx, mid, v interface{}, isError ...interface{}) *gomock.Call { varargs := append([]interface{}{ctx, mid, v}, isError...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResponseMID", reflect.TypeOf((*MockNetworkEntity)(nil).ResponseMID), varargs...) }
go
func (mr *MockNetworkEntityMockRecorder) ResponseMID(ctx, mid, v interface{}, isError ...interface{}) *gomock.Call { varargs := append([]interface{}{ctx, mid, v}, isError...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResponseMID", reflect.TypeOf((*MockNetworkEntity)(nil).ResponseMID), varargs...) }
[ "func", "(", "mr", "*", "MockNetworkEntityMockRecorder", ")", "ResponseMID", "(", "ctx", ",", "mid", ",", "v", "interface", "{", "}", ",", "isError", "...", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "varargs", ":=", "append", "(", "[", "]", "interface", "{", "}", "{", "ctx", ",", "mid", ",", "v", "}", ",", "isError", "...", ")", "\n", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"ResponseMID\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockNetworkEntity", ")", "(", "nil", ")", ".", "ResponseMID", ")", ",", "varargs", "...", ")", "\n", "}" ]
// ResponseMID indicates an expected call of ResponseMID
[ "ResponseMID", "indicates", "an", "expected", "call", "of", "ResponseMID" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L62-L65
train
topfreegames/pitaya
session/mocks/session.go
Kick
func (m *MockNetworkEntity) Kick(ctx context.Context) error { ret := m.ctrl.Call(m, "Kick", ctx) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockNetworkEntity) Kick(ctx context.Context) error { ret := m.ctrl.Call(m, "Kick", ctx) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockNetworkEntity", ")", "Kick", "(", "ctx", "context", ".", "Context", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"Kick\"", ",", "ctx", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// Kick mocks base method
[ "Kick", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L80-L84
train
topfreegames/pitaya
session/mocks/session.go
Kick
func (mr *MockNetworkEntityMockRecorder) Kick(ctx interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Kick", reflect.TypeOf((*MockNetworkEntity)(nil).Kick), ctx) }
go
func (mr *MockNetworkEntityMockRecorder) Kick(ctx interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Kick", reflect.TypeOf((*MockNetworkEntity)(nil).Kick), ctx) }
[ "func", "(", "mr", "*", "MockNetworkEntityMockRecorder", ")", "Kick", "(", "ctx", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"Kick\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockNetworkEntity", ")", "(", "nil", ")", ".", "Kick", ")", ",", "ctx", ")", "\n", "}" ]
// Kick indicates an expected call of Kick
[ "Kick", "indicates", "an", "expected", "call", "of", "Kick" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L87-L89
train
topfreegames/pitaya
session/mocks/session.go
RemoteAddr
func (mr *MockNetworkEntityMockRecorder) RemoteAddr() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoteAddr", reflect.TypeOf((*MockNetworkEntity)(nil).RemoteAddr)) }
go
func (mr *MockNetworkEntityMockRecorder) RemoteAddr() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoteAddr", reflect.TypeOf((*MockNetworkEntity)(nil).RemoteAddr)) }
[ "func", "(", "mr", "*", "MockNetworkEntityMockRecorder", ")", "RemoteAddr", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"RemoteAddr\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockNetworkEntity", ")", "(", "nil", ")", ".", "RemoteAddr", ")", ")", "\n", "}" ]
// RemoteAddr indicates an expected call of RemoteAddr
[ "RemoteAddr", "indicates", "an", "expected", "call", "of", "RemoteAddr" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L99-L101
train
topfreegames/pitaya
session/mocks/session.go
SendRequest
func (m *MockNetworkEntity) SendRequest(ctx context.Context, serverID, route string, v interface{}) (*protos.Response, error) { ret := m.ctrl.Call(m, "SendRequest", ctx, serverID, route, v) ret0, _ := ret[0].(*protos.Response) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockNetworkEntity) SendRequest(ctx context.Context, serverID, route string, v interface{}) (*protos.Response, error) { ret := m.ctrl.Call(m, "SendRequest", ctx, serverID, route, v) ret0, _ := ret[0].(*protos.Response) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockNetworkEntity", ")", "SendRequest", "(", "ctx", "context", ".", "Context", ",", "serverID", ",", "route", "string", ",", "v", "interface", "{", "}", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"SendRequest\"", ",", "ctx", ",", "serverID", ",", "route", ",", "v", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "*", "protos", ".", "Response", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// SendRequest mocks base method
[ "SendRequest", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L104-L109
train
topfreegames/pitaya
session/mocks/session.go
SendRequest
func (mr *MockNetworkEntityMockRecorder) SendRequest(ctx, serverID, route, v interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRequest", reflect.TypeOf((*MockNetworkEntity)(nil).SendRequest), ctx, serverID, route, v) }
go
func (mr *MockNetworkEntityMockRecorder) SendRequest(ctx, serverID, route, v interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRequest", reflect.TypeOf((*MockNetworkEntity)(nil).SendRequest), ctx, serverID, route, v) }
[ "func", "(", "mr", "*", "MockNetworkEntityMockRecorder", ")", "SendRequest", "(", "ctx", ",", "serverID", ",", "route", ",", "v", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"SendRequest\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockNetworkEntity", ")", "(", "nil", ")", ".", "SendRequest", ")", ",", "ctx", ",", "serverID", ",", "route", ",", "v", ")", "\n", "}" ]
// SendRequest indicates an expected call of SendRequest
[ "SendRequest", "indicates", "an", "expected", "call", "of", "SendRequest" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/session/mocks/session.go#L112-L114
train
topfreegames/pitaya
service/handler.go
NewHandlerService
func NewHandlerService( dieChan chan bool, packetDecoder codec.PacketDecoder, packetEncoder codec.PacketEncoder, serializer serialize.Serializer, heartbeatTime time.Duration, messagesBufferSize, localProcessBufferSize, remoteProcessBufferSize int, server *cluster.Server, remoteService *RemoteService, messageEncoder message.Encoder, metricsReporters []metrics.Reporter, ) *HandlerService { h := &HandlerService{ services: make(map[string]*component.Service), chLocalProcess: make(chan unhandledMessage, localProcessBufferSize), chRemoteProcess: make(chan unhandledMessage, remoteProcessBufferSize), decoder: packetDecoder, encoder: packetEncoder, messagesBufferSize: messagesBufferSize, serializer: serializer, heartbeatTimeout: heartbeatTime, appDieChan: dieChan, server: server, remoteService: remoteService, messageEncoder: messageEncoder, metricsReporters: metricsReporters, } return h }
go
func NewHandlerService( dieChan chan bool, packetDecoder codec.PacketDecoder, packetEncoder codec.PacketEncoder, serializer serialize.Serializer, heartbeatTime time.Duration, messagesBufferSize, localProcessBufferSize, remoteProcessBufferSize int, server *cluster.Server, remoteService *RemoteService, messageEncoder message.Encoder, metricsReporters []metrics.Reporter, ) *HandlerService { h := &HandlerService{ services: make(map[string]*component.Service), chLocalProcess: make(chan unhandledMessage, localProcessBufferSize), chRemoteProcess: make(chan unhandledMessage, remoteProcessBufferSize), decoder: packetDecoder, encoder: packetEncoder, messagesBufferSize: messagesBufferSize, serializer: serializer, heartbeatTimeout: heartbeatTime, appDieChan: dieChan, server: server, remoteService: remoteService, messageEncoder: messageEncoder, metricsReporters: metricsReporters, } return h }
[ "func", "NewHandlerService", "(", "dieChan", "chan", "bool", ",", "packetDecoder", "codec", ".", "PacketDecoder", ",", "packetEncoder", "codec", ".", "PacketEncoder", ",", "serializer", "serialize", ".", "Serializer", ",", "heartbeatTime", "time", ".", "Duration", ",", "messagesBufferSize", ",", "localProcessBufferSize", ",", "remoteProcessBufferSize", "int", ",", "server", "*", "cluster", ".", "Server", ",", "remoteService", "*", "RemoteService", ",", "messageEncoder", "message", ".", "Encoder", ",", "metricsReporters", "[", "]", "metrics", ".", "Reporter", ",", ")", "*", "HandlerService", "{", "h", ":=", "&", "HandlerService", "{", "services", ":", "make", "(", "map", "[", "string", "]", "*", "component", ".", "Service", ")", ",", "chLocalProcess", ":", "make", "(", "chan", "unhandledMessage", ",", "localProcessBufferSize", ")", ",", "chRemoteProcess", ":", "make", "(", "chan", "unhandledMessage", ",", "remoteProcessBufferSize", ")", ",", "decoder", ":", "packetDecoder", ",", "encoder", ":", "packetEncoder", ",", "messagesBufferSize", ":", "messagesBufferSize", ",", "serializer", ":", "serializer", ",", "heartbeatTimeout", ":", "heartbeatTime", ",", "appDieChan", ":", "dieChan", ",", "server", ":", "server", ",", "remoteService", ":", "remoteService", ",", "messageEncoder", ":", "messageEncoder", ",", "metricsReporters", ":", "metricsReporters", ",", "}", "\n", "return", "h", "\n", "}" ]
// NewHandlerService creates and returns a new handler service
[ "NewHandlerService", "creates", "and", "returns", "a", "new", "handler", "service" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/handler.go#L84-L115
train
topfreegames/pitaya
service/handler.go
Dispatch
func (h *HandlerService) Dispatch(thread int) { // TODO: This timer is being stopped multiple times, it probably doesn't need to be stopped here defer timer.GlobalTicker.Stop() for { // Calls to remote servers block calls to local server select { case lm := <-h.chLocalProcess: metrics.ReportMessageProcessDelayFromCtx(lm.ctx, h.metricsReporters, "local") h.localProcess(lm.ctx, lm.agent, lm.route, lm.msg) case rm := <-h.chRemoteProcess: metrics.ReportMessageProcessDelayFromCtx(rm.ctx, h.metricsReporters, "remote") h.remoteService.remoteProcess(rm.ctx, nil, rm.agent, rm.route, rm.msg) case <-timer.GlobalTicker.C: // execute cron task timer.Cron() case t := <-timer.Manager.ChCreatedTimer: // new Timers timer.AddTimer(t) case id := <-timer.Manager.ChClosingTimer: // closing Timers timer.RemoveTimer(id) } } }
go
func (h *HandlerService) Dispatch(thread int) { // TODO: This timer is being stopped multiple times, it probably doesn't need to be stopped here defer timer.GlobalTicker.Stop() for { // Calls to remote servers block calls to local server select { case lm := <-h.chLocalProcess: metrics.ReportMessageProcessDelayFromCtx(lm.ctx, h.metricsReporters, "local") h.localProcess(lm.ctx, lm.agent, lm.route, lm.msg) case rm := <-h.chRemoteProcess: metrics.ReportMessageProcessDelayFromCtx(rm.ctx, h.metricsReporters, "remote") h.remoteService.remoteProcess(rm.ctx, nil, rm.agent, rm.route, rm.msg) case <-timer.GlobalTicker.C: // execute cron task timer.Cron() case t := <-timer.Manager.ChCreatedTimer: // new Timers timer.AddTimer(t) case id := <-timer.Manager.ChClosingTimer: // closing Timers timer.RemoveTimer(id) } } }
[ "func", "(", "h", "*", "HandlerService", ")", "Dispatch", "(", "thread", "int", ")", "{", "defer", "timer", ".", "GlobalTicker", ".", "Stop", "(", ")", "\n", "for", "{", "select", "{", "case", "lm", ":=", "<-", "h", ".", "chLocalProcess", ":", "metrics", ".", "ReportMessageProcessDelayFromCtx", "(", "lm", ".", "ctx", ",", "h", ".", "metricsReporters", ",", "\"local\"", ")", "\n", "h", ".", "localProcess", "(", "lm", ".", "ctx", ",", "lm", ".", "agent", ",", "lm", ".", "route", ",", "lm", ".", "msg", ")", "\n", "case", "rm", ":=", "<-", "h", ".", "chRemoteProcess", ":", "metrics", ".", "ReportMessageProcessDelayFromCtx", "(", "rm", ".", "ctx", ",", "h", ".", "metricsReporters", ",", "\"remote\"", ")", "\n", "h", ".", "remoteService", ".", "remoteProcess", "(", "rm", ".", "ctx", ",", "nil", ",", "rm", ".", "agent", ",", "rm", ".", "route", ",", "rm", ".", "msg", ")", "\n", "case", "<-", "timer", ".", "GlobalTicker", ".", "C", ":", "timer", ".", "Cron", "(", ")", "\n", "case", "t", ":=", "<-", "timer", ".", "Manager", ".", "ChCreatedTimer", ":", "timer", ".", "AddTimer", "(", "t", ")", "\n", "case", "id", ":=", "<-", "timer", ".", "Manager", ".", "ChClosingTimer", ":", "timer", ".", "RemoveTimer", "(", "id", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Dispatch message to corresponding logic handler
[ "Dispatch", "message", "to", "corresponding", "logic", "handler" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/handler.go#L118-L143
train
topfreegames/pitaya
service/handler.go
Handle
func (h *HandlerService) Handle(conn net.Conn) { // create a client agent and startup write goroutine a := agent.NewAgent(conn, h.decoder, h.encoder, h.serializer, h.heartbeatTimeout, h.messagesBufferSize, h.appDieChan, h.messageEncoder, h.metricsReporters) // startup agent goroutine go a.Handle() logger.Log.Debugf("New session established: %s", a.String()) // guarantee agent related resource is destroyed defer func() { a.Session.Close() logger.Log.Debugf("Session read goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() // read loop buf := make([]byte, 2048) for { n, err := conn.Read(buf) if err != nil { logger.Log.Debugf("Read message error: %s, session will be closed immediately", err.Error()) return } logger.Log.Debug("Received data on connection") // (warning): decoder uses slice for performance, packet data should be copied before next Decode packets, err := h.decoder.Decode(buf[:n]) if err != nil { logger.Log.Errorf("Failed to decode message: %s", err.Error()) return } if len(packets) < 1 { logger.Log.Warnf("Read no packets, data: %v", buf[:n]) continue } // process all packet for i := range packets { if err := h.processPacket(a, packets[i]); err != nil { logger.Log.Errorf("Failed to process packet: %s", err.Error()) return } } } }
go
func (h *HandlerService) Handle(conn net.Conn) { // create a client agent and startup write goroutine a := agent.NewAgent(conn, h.decoder, h.encoder, h.serializer, h.heartbeatTimeout, h.messagesBufferSize, h.appDieChan, h.messageEncoder, h.metricsReporters) // startup agent goroutine go a.Handle() logger.Log.Debugf("New session established: %s", a.String()) // guarantee agent related resource is destroyed defer func() { a.Session.Close() logger.Log.Debugf("Session read goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) }() // read loop buf := make([]byte, 2048) for { n, err := conn.Read(buf) if err != nil { logger.Log.Debugf("Read message error: %s, session will be closed immediately", err.Error()) return } logger.Log.Debug("Received data on connection") // (warning): decoder uses slice for performance, packet data should be copied before next Decode packets, err := h.decoder.Decode(buf[:n]) if err != nil { logger.Log.Errorf("Failed to decode message: %s", err.Error()) return } if len(packets) < 1 { logger.Log.Warnf("Read no packets, data: %v", buf[:n]) continue } // process all packet for i := range packets { if err := h.processPacket(a, packets[i]); err != nil { logger.Log.Errorf("Failed to process packet: %s", err.Error()) return } } } }
[ "func", "(", "h", "*", "HandlerService", ")", "Handle", "(", "conn", "net", ".", "Conn", ")", "{", "a", ":=", "agent", ".", "NewAgent", "(", "conn", ",", "h", ".", "decoder", ",", "h", ".", "encoder", ",", "h", ".", "serializer", ",", "h", ".", "heartbeatTimeout", ",", "h", ".", "messagesBufferSize", ",", "h", ".", "appDieChan", ",", "h", ".", "messageEncoder", ",", "h", ".", "metricsReporters", ")", "\n", "go", "a", ".", "Handle", "(", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"New session established: %s\"", ",", "a", ".", "String", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "a", ".", "Session", ".", "Close", "(", ")", "\n", "logger", ".", "Log", ".", "Debugf", "(", "\"Session read goroutine exit, SessionID=%d, UID=%d\"", ",", "a", ".", "Session", ".", "ID", "(", ")", ",", "a", ".", "Session", ".", "UID", "(", ")", ")", "\n", "}", "(", ")", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "2048", ")", "\n", "for", "{", "n", ",", "err", ":=", "conn", ".", "Read", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Debugf", "(", "\"Read message error: %s, session will be closed immediately\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "logger", ".", "Log", ".", "Debug", "(", "\"Received data on connection\"", ")", "\n", "packets", ",", "err", ":=", "h", ".", "decoder", ".", "Decode", "(", "buf", "[", ":", "n", "]", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Failed to decode message: %s\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "if", "len", "(", "packets", ")", "<", "1", "{", "logger", ".", "Log", ".", "Warnf", "(", "\"Read no packets, data: %v\"", ",", "buf", "[", ":", "n", "]", ")", "\n", "continue", "\n", "}", "\n", "for", "i", ":=", "range", "packets", "{", "if", "err", ":=", "h", ".", "processPacket", "(", "a", ",", "packets", "[", "i", "]", ")", ";", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Failed to process packet: %s\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Handle handles messages from a conn
[ "Handle", "handles", "messages", "from", "a", "conn" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/handler.go#L166-L212
train
topfreegames/pitaya
service/handler.go
DumpServices
func (h *HandlerService) DumpServices() { for name := range handlers { logger.Log.Infof("registered handler %s, isRawArg: %s", name, handlers[name].IsRawArg) } }
go
func (h *HandlerService) DumpServices() { for name := range handlers { logger.Log.Infof("registered handler %s, isRawArg: %s", name, handlers[name].IsRawArg) } }
[ "func", "(", "h", "*", "HandlerService", ")", "DumpServices", "(", ")", "{", "for", "name", ":=", "range", "handlers", "{", "logger", ".", "Log", ".", "Infof", "(", "\"registered handler %s, isRawArg: %s\"", ",", "name", ",", "handlers", "[", "name", "]", ".", "IsRawArg", ")", "\n", "}", "\n", "}" ]
// DumpServices outputs all registered services
[ "DumpServices", "outputs", "all", "registered", "services" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/handler.go#L332-L336
train
topfreegames/pitaya
service/handler.go
Docs
func (h *HandlerService) Docs(getPtrNames bool) (map[string]interface{}, error) { if h == nil { return map[string]interface{}{}, nil } return docgenerator.HandlersDocs(h.server.Type, h.services, getPtrNames) }
go
func (h *HandlerService) Docs(getPtrNames bool) (map[string]interface{}, error) { if h == nil { return map[string]interface{}{}, nil } return docgenerator.HandlersDocs(h.server.Type, h.services, getPtrNames) }
[ "func", "(", "h", "*", "HandlerService", ")", "Docs", "(", "getPtrNames", "bool", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "if", "h", "==", "nil", "{", "return", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ",", "nil", "\n", "}", "\n", "return", "docgenerator", ".", "HandlersDocs", "(", "h", ".", "server", ".", "Type", ",", "h", ".", "services", ",", "getPtrNames", ")", "\n", "}" ]
// Docs returns documentation for handlers
[ "Docs", "returns", "documentation", "for", "handlers" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/service/handler.go#L339-L344
train
topfreegames/pitaya
worker/worker.go
EnqueueRPC
func (w *Worker) EnqueueRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error) { opts := w.enqueueOptions(w.opts) return workers.EnqueueWithOptions(rpcQueue, class, &rpcInfo{ Route: routeStr, Metadata: metadata, Arg: arg, Reply: reply, }, opts) }
go
func (w *Worker) EnqueueRPC( routeStr string, metadata map[string]interface{}, reply, arg proto.Message, ) (jid string, err error) { opts := w.enqueueOptions(w.opts) return workers.EnqueueWithOptions(rpcQueue, class, &rpcInfo{ Route: routeStr, Metadata: metadata, Arg: arg, Reply: reply, }, opts) }
[ "func", "(", "w", "*", "Worker", ")", "EnqueueRPC", "(", "routeStr", "string", ",", "metadata", "map", "[", "string", "]", "interface", "{", "}", ",", "reply", ",", "arg", "proto", ".", "Message", ",", ")", "(", "jid", "string", ",", "err", "error", ")", "{", "opts", ":=", "w", ".", "enqueueOptions", "(", "w", ".", "opts", ")", "\n", "return", "workers", ".", "EnqueueWithOptions", "(", "rpcQueue", ",", "class", ",", "&", "rpcInfo", "{", "Route", ":", "routeStr", ",", "Metadata", ":", "metadata", ",", "Arg", ":", "arg", ",", "Reply", ":", "reply", ",", "}", ",", "opts", ")", "\n", "}" ]
// EnqueueRPC enqueues rpc job to worker
[ "EnqueueRPC", "enqueues", "rpc", "job", "to", "worker" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/worker/worker.go#L83-L95
train
topfreegames/pitaya
worker/worker.go
RegisterRPCJob
func (w *Worker) RegisterRPCJob(rpcJob RPCJob) error { if w.registered { return constants.ErrRPCJobAlreadyRegistered } job := w.parsedRPCJob(rpcJob) workers.Process(rpcQueue, job, w.concurrency) w.registered = true return nil }
go
func (w *Worker) RegisterRPCJob(rpcJob RPCJob) error { if w.registered { return constants.ErrRPCJobAlreadyRegistered } job := w.parsedRPCJob(rpcJob) workers.Process(rpcQueue, job, w.concurrency) w.registered = true return nil }
[ "func", "(", "w", "*", "Worker", ")", "RegisterRPCJob", "(", "rpcJob", "RPCJob", ")", "error", "{", "if", "w", ".", "registered", "{", "return", "constants", ".", "ErrRPCJobAlreadyRegistered", "\n", "}", "\n", "job", ":=", "w", ".", "parsedRPCJob", "(", "rpcJob", ")", "\n", "workers", ".", "Process", "(", "rpcQueue", ",", "job", ",", "w", ".", "concurrency", ")", "\n", "w", ".", "registered", "=", "true", "\n", "return", "nil", "\n", "}" ]
// RegisterRPCJob registers a RPC job
[ "RegisterRPCJob", "registers", "a", "RPC", "job" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/worker/worker.go#L113-L122
train
topfreegames/pitaya
kick.go
SendKickToUsers
func SendKickToUsers(uids []string, frontendType string) ([]string, error) { if !app.server.Frontend && frontendType == "" { return uids, constants.ErrFrontendTypeNotSpecified } var notKickedUids []string for _, uid := range uids { if s := session.GetSessionByUID(uid); s != nil { if err := s.Kick(context.Background()); err != nil { notKickedUids = append(notKickedUids, uid) logger.Log.Errorf("Session kick error, ID=%d, UID=%d, ERROR=%s", s.ID(), s.UID(), err.Error()) } } else if app.rpcClient != nil { kick := &protos.KickMsg{UserId: uid} if err := app.rpcClient.SendKick(uid, frontendType, kick); err != nil { notKickedUids = append(notKickedUids, uid) logger.Log.Errorf("RPCClient send kick error, UID=%d, SvType=%s, Error=%s", uid, frontendType, err.Error()) } } else { notKickedUids = append(notKickedUids, uid) } } if len(notKickedUids) != 0 { return notKickedUids, constants.ErrKickingUsers } return nil, nil }
go
func SendKickToUsers(uids []string, frontendType string) ([]string, error) { if !app.server.Frontend && frontendType == "" { return uids, constants.ErrFrontendTypeNotSpecified } var notKickedUids []string for _, uid := range uids { if s := session.GetSessionByUID(uid); s != nil { if err := s.Kick(context.Background()); err != nil { notKickedUids = append(notKickedUids, uid) logger.Log.Errorf("Session kick error, ID=%d, UID=%d, ERROR=%s", s.ID(), s.UID(), err.Error()) } } else if app.rpcClient != nil { kick := &protos.KickMsg{UserId: uid} if err := app.rpcClient.SendKick(uid, frontendType, kick); err != nil { notKickedUids = append(notKickedUids, uid) logger.Log.Errorf("RPCClient send kick error, UID=%d, SvType=%s, Error=%s", uid, frontendType, err.Error()) } } else { notKickedUids = append(notKickedUids, uid) } } if len(notKickedUids) != 0 { return notKickedUids, constants.ErrKickingUsers } return nil, nil }
[ "func", "SendKickToUsers", "(", "uids", "[", "]", "string", ",", "frontendType", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "!", "app", ".", "server", ".", "Frontend", "&&", "frontendType", "==", "\"\"", "{", "return", "uids", ",", "constants", ".", "ErrFrontendTypeNotSpecified", "\n", "}", "\n", "var", "notKickedUids", "[", "]", "string", "\n", "for", "_", ",", "uid", ":=", "range", "uids", "{", "if", "s", ":=", "session", ".", "GetSessionByUID", "(", "uid", ")", ";", "s", "!=", "nil", "{", "if", "err", ":=", "s", ".", "Kick", "(", "context", ".", "Background", "(", ")", ")", ";", "err", "!=", "nil", "{", "notKickedUids", "=", "append", "(", "notKickedUids", ",", "uid", ")", "\n", "logger", ".", "Log", ".", "Errorf", "(", "\"Session kick error, ID=%d, UID=%d, ERROR=%s\"", ",", "s", ".", "ID", "(", ")", ",", "s", ".", "UID", "(", ")", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "else", "if", "app", ".", "rpcClient", "!=", "nil", "{", "kick", ":=", "&", "protos", ".", "KickMsg", "{", "UserId", ":", "uid", "}", "\n", "if", "err", ":=", "app", ".", "rpcClient", ".", "SendKick", "(", "uid", ",", "frontendType", ",", "kick", ")", ";", "err", "!=", "nil", "{", "notKickedUids", "=", "append", "(", "notKickedUids", ",", "uid", ")", "\n", "logger", ".", "Log", ".", "Errorf", "(", "\"RPCClient send kick error, UID=%d, SvType=%s, Error=%s\"", ",", "uid", ",", "frontendType", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "else", "{", "notKickedUids", "=", "append", "(", "notKickedUids", ",", "uid", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "notKickedUids", ")", "!=", "0", "{", "return", "notKickedUids", ",", "constants", ".", "ErrKickingUsers", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// SendKickToUsers sends kick to an user array
[ "SendKickToUsers", "sends", "kick", "to", "an", "user", "array" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/kick.go#L33-L63
train
topfreegames/pitaya
client/protoclient.go
unpackDescriptor
func unpackDescriptor(compressedDescriptor []byte) (*protobuf.FileDescriptorProto, error) { r, err := gzip.NewReader(bytes.NewReader(compressedDescriptor)) if err != nil { return nil, err } defer r.Close() b, err := ioutil.ReadAll(r) if err != nil { return nil, err } var fileDescriptorProto protobuf.FileDescriptorProto if err = proto.Unmarshal(b, &fileDescriptorProto); err != nil { return nil, err } return &fileDescriptorProto, nil }
go
func unpackDescriptor(compressedDescriptor []byte) (*protobuf.FileDescriptorProto, error) { r, err := gzip.NewReader(bytes.NewReader(compressedDescriptor)) if err != nil { return nil, err } defer r.Close() b, err := ioutil.ReadAll(r) if err != nil { return nil, err } var fileDescriptorProto protobuf.FileDescriptorProto if err = proto.Unmarshal(b, &fileDescriptorProto); err != nil { return nil, err } return &fileDescriptorProto, nil }
[ "func", "unpackDescriptor", "(", "compressedDescriptor", "[", "]", "byte", ")", "(", "*", "protobuf", ".", "FileDescriptorProto", ",", "error", ")", "{", "r", ",", "err", ":=", "gzip", ".", "NewReader", "(", "bytes", ".", "NewReader", "(", "compressedDescriptor", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "r", ".", "Close", "(", ")", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "fileDescriptorProto", "protobuf", ".", "FileDescriptorProto", "\n", "if", "err", "=", "proto", ".", "Unmarshal", "(", "b", ",", "&", "fileDescriptorProto", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "fileDescriptorProto", ",", "nil", "\n", "}" ]
// Receive a compressed byte slice and unpack it to a FileDescriptorProto
[ "Receive", "a", "compressed", "byte", "slice", "and", "unpack", "it", "to", "a", "FileDescriptorProto" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L75-L94
train
topfreegames/pitaya
client/protoclient.go
buildProtosFromDescriptor
func (pc *ProtoClient) buildProtosFromDescriptor(descriptorArray []*protobuf.FileDescriptorProto) error { descriptorsMap := make(map[string]*desc.MessageDescriptor) descriptors, err := desc.CreateFileDescriptors(descriptorArray) if err != nil { return err } for name := range pc.descriptorsNames { for _, v := range descriptors { message := v.FindMessage(name) if message != nil { descriptorsMap[name] = message } } } for name, cmd := range pc.info.Commands { if msg, ok := descriptorsMap[cmd.input]; ok { pc.info.Commands[name].inputMsgDescriptor = msg } if msg, ok := descriptorsMap[cmd.output]; ok { pc.info.Commands[name].outputMsgDescriptor = msg } } return nil }
go
func (pc *ProtoClient) buildProtosFromDescriptor(descriptorArray []*protobuf.FileDescriptorProto) error { descriptorsMap := make(map[string]*desc.MessageDescriptor) descriptors, err := desc.CreateFileDescriptors(descriptorArray) if err != nil { return err } for name := range pc.descriptorsNames { for _, v := range descriptors { message := v.FindMessage(name) if message != nil { descriptorsMap[name] = message } } } for name, cmd := range pc.info.Commands { if msg, ok := descriptorsMap[cmd.input]; ok { pc.info.Commands[name].inputMsgDescriptor = msg } if msg, ok := descriptorsMap[cmd.output]; ok { pc.info.Commands[name].outputMsgDescriptor = msg } } return nil }
[ "func", "(", "pc", "*", "ProtoClient", ")", "buildProtosFromDescriptor", "(", "descriptorArray", "[", "]", "*", "protobuf", ".", "FileDescriptorProto", ")", "error", "{", "descriptorsMap", ":=", "make", "(", "map", "[", "string", "]", "*", "desc", ".", "MessageDescriptor", ")", "\n", "descriptors", ",", "err", ":=", "desc", ".", "CreateFileDescriptors", "(", "descriptorArray", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "name", ":=", "range", "pc", ".", "descriptorsNames", "{", "for", "_", ",", "v", ":=", "range", "descriptors", "{", "message", ":=", "v", ".", "FindMessage", "(", "name", ")", "\n", "if", "message", "!=", "nil", "{", "descriptorsMap", "[", "name", "]", "=", "message", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "name", ",", "cmd", ":=", "range", "pc", ".", "info", ".", "Commands", "{", "if", "msg", ",", "ok", ":=", "descriptorsMap", "[", "cmd", ".", "input", "]", ";", "ok", "{", "pc", ".", "info", ".", "Commands", "[", "name", "]", ".", "inputMsgDescriptor", "=", "msg", "\n", "}", "\n", "if", "msg", ",", "ok", ":=", "descriptorsMap", "[", "cmd", ".", "output", "]", ";", "ok", "{", "pc", ".", "info", ".", "Commands", "[", "name", "]", ".", "outputMsgDescriptor", "=", "msg", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Receive an array of descriptors in binary format. The function creates the // protobuffer from this data and associates it to the message.
[ "Receive", "an", "array", "of", "descriptors", "in", "binary", "format", ".", "The", "function", "creates", "the", "protobuffer", "from", "this", "data", "and", "associates", "it", "to", "the", "message", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L98-L126
train
topfreegames/pitaya
client/protoclient.go
getOutputInputNames
func getOutputInputNames(command map[string]interface{}) (string, string, error) { outputName := "" inputName := "" in := command["input"] inputDocs, ok := in.(map[string]interface{}) if ok { for k := range inputDocs { if strings.Contains(k, "proto") { inputName = strings.Replace(k, "*", "", 1) } } } out := command["output"] outputDocsArr := out.([]interface{}) outputDocs, ok := outputDocsArr[0].(map[string]interface{}) if ok { for k := range outputDocs { if strings.Contains(k, "proto") { outputName = strings.Replace(k, "*", "", 1) } } } return inputName, outputName, nil }
go
func getOutputInputNames(command map[string]interface{}) (string, string, error) { outputName := "" inputName := "" in := command["input"] inputDocs, ok := in.(map[string]interface{}) if ok { for k := range inputDocs { if strings.Contains(k, "proto") { inputName = strings.Replace(k, "*", "", 1) } } } out := command["output"] outputDocsArr := out.([]interface{}) outputDocs, ok := outputDocsArr[0].(map[string]interface{}) if ok { for k := range outputDocs { if strings.Contains(k, "proto") { outputName = strings.Replace(k, "*", "", 1) } } } return inputName, outputName, nil }
[ "func", "getOutputInputNames", "(", "command", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "string", ",", "string", ",", "error", ")", "{", "outputName", ":=", "\"\"", "\n", "inputName", ":=", "\"\"", "\n", "in", ":=", "command", "[", "\"input\"", "]", "\n", "inputDocs", ",", "ok", ":=", "in", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "ok", "{", "for", "k", ":=", "range", "inputDocs", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"proto\"", ")", "{", "inputName", "=", "strings", ".", "Replace", "(", "k", ",", "\"*\"", ",", "\"\"", ",", "1", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "out", ":=", "command", "[", "\"output\"", "]", "\n", "outputDocsArr", ":=", "out", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "outputDocs", ",", "ok", ":=", "outputDocsArr", "[", "0", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "ok", "{", "for", "k", ":=", "range", "outputDocs", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"proto\"", ")", "{", "outputName", "=", "strings", ".", "Replace", "(", "k", ",", "\"*\"", ",", "\"\"", ",", "1", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "inputName", ",", "outputName", ",", "nil", "\n", "}" ]
// Receives each entry from the Unmarshal json from the Docs and read the inputs and // outputs associated with it. Return the output type, the input and the error.
[ "Receives", "each", "entry", "from", "the", "Unmarshal", "json", "from", "the", "Docs", "and", "read", "the", "inputs", "and", "outputs", "associated", "with", "it", ".", "Return", "the", "output", "type", "the", "input", "and", "the", "error", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L130-L156
train
topfreegames/pitaya
client/protoclient.go
getKeys
func getKeys(info map[string]interface{}, keysSet map[string]bool) { for k, v := range info { if strings.Contains(k, "*") { kew := strings.Replace(k, "*", "", 1) keysSet[kew] = true } listofouts, ok := v.([]interface{}) if ok { for i := range listofouts { aux, ok := listofouts[i].(map[string]interface{}) if !ok { continue } getKeys(aux, keysSet) } } if aux, ok := v.(map[string]interface{}); ok { getKeys(aux, keysSet) } } }
go
func getKeys(info map[string]interface{}, keysSet map[string]bool) { for k, v := range info { if strings.Contains(k, "*") { kew := strings.Replace(k, "*", "", 1) keysSet[kew] = true } listofouts, ok := v.([]interface{}) if ok { for i := range listofouts { aux, ok := listofouts[i].(map[string]interface{}) if !ok { continue } getKeys(aux, keysSet) } } if aux, ok := v.(map[string]interface{}); ok { getKeys(aux, keysSet) } } }
[ "func", "getKeys", "(", "info", "map", "[", "string", "]", "interface", "{", "}", ",", "keysSet", "map", "[", "string", "]", "bool", ")", "{", "for", "k", ",", "v", ":=", "range", "info", "{", "if", "strings", ".", "Contains", "(", "k", ",", "\"*\"", ")", "{", "kew", ":=", "strings", ".", "Replace", "(", "k", ",", "\"*\"", ",", "\"\"", ",", "1", ")", "\n", "keysSet", "[", "kew", "]", "=", "true", "\n", "}", "\n", "listofouts", ",", "ok", ":=", "v", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "if", "ok", "{", "for", "i", ":=", "range", "listofouts", "{", "aux", ",", "ok", ":=", "listofouts", "[", "i", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "getKeys", "(", "aux", ",", "keysSet", ")", "\n", "}", "\n", "}", "\n", "if", "aux", ",", "ok", ":=", "v", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ";", "ok", "{", "getKeys", "(", "aux", ",", "keysSet", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Get recursively all protos needed in a Unmarshal json.
[ "Get", "recursively", "all", "protos", "needed", "in", "a", "Unmarshal", "json", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L159-L181
train
topfreegames/pitaya
client/protoclient.go
newProto
func newProto(docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { return &ProtoClient{ Client: *New(docslogLevel, requestTimeout...), descriptorsNames: make(map[string]bool), info: ProtoBufferInfo{ Commands: make(map[string]*Command), }, docsRoute: "", descriptorsRoute: "", IncomingMsgChan: make(chan *message.Message, 10), closeChan: make(chan bool), } }
go
func newProto(docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { return &ProtoClient{ Client: *New(docslogLevel, requestTimeout...), descriptorsNames: make(map[string]bool), info: ProtoBufferInfo{ Commands: make(map[string]*Command), }, docsRoute: "", descriptorsRoute: "", IncomingMsgChan: make(chan *message.Message, 10), closeChan: make(chan bool), } }
[ "func", "newProto", "(", "docslogLevel", "logrus", ".", "Level", ",", "requestTimeout", "...", "time", ".", "Duration", ")", "*", "ProtoClient", "{", "return", "&", "ProtoClient", "{", "Client", ":", "*", "New", "(", "docslogLevel", ",", "requestTimeout", "...", ")", ",", "descriptorsNames", ":", "make", "(", "map", "[", "string", "]", "bool", ")", ",", "info", ":", "ProtoBufferInfo", "{", "Commands", ":", "make", "(", "map", "[", "string", "]", "*", "Command", ")", ",", "}", ",", "docsRoute", ":", "\"\"", ",", "descriptorsRoute", ":", "\"\"", ",", "IncomingMsgChan", ":", "make", "(", "chan", "*", "message", ".", "Message", ",", "10", ")", ",", "closeChan", ":", "make", "(", "chan", "bool", ")", ",", "}", "\n", "}" ]
// Return the basic structure for the ProtoClient struct.
[ "Return", "the", "basic", "structure", "for", "the", "ProtoClient", "struct", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L285-L297
train
topfreegames/pitaya
client/protoclient.go
NewProto
func NewProto(docsRoute string, docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { newclient := newProto(docslogLevel, requestTimeout...) newclient.docsRoute = docsRoute return newclient }
go
func NewProto(docsRoute string, docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { newclient := newProto(docslogLevel, requestTimeout...) newclient.docsRoute = docsRoute return newclient }
[ "func", "NewProto", "(", "docsRoute", "string", ",", "docslogLevel", "logrus", ".", "Level", ",", "requestTimeout", "...", "time", ".", "Duration", ")", "*", "ProtoClient", "{", "newclient", ":=", "newProto", "(", "docslogLevel", ",", "requestTimeout", "...", ")", "\n", "newclient", ".", "docsRoute", "=", "docsRoute", "\n", "return", "newclient", "\n", "}" ]
// NewProto returns a new protoclient with the auto documentation route.
[ "NewProto", "returns", "a", "new", "protoclient", "with", "the", "auto", "documentation", "route", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L300-L304
train
topfreegames/pitaya
client/protoclient.go
NewWithDescriptor
func NewWithDescriptor(descriptorsRoute string, docsRoute string, docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { newclient := newProto(docslogLevel, requestTimeout...) newclient.docsRoute = docsRoute newclient.descriptorsRoute = descriptorsRoute return newclient }
go
func NewWithDescriptor(descriptorsRoute string, docsRoute string, docslogLevel logrus.Level, requestTimeout ...time.Duration) *ProtoClient { newclient := newProto(docslogLevel, requestTimeout...) newclient.docsRoute = docsRoute newclient.descriptorsRoute = descriptorsRoute return newclient }
[ "func", "NewWithDescriptor", "(", "descriptorsRoute", "string", ",", "docsRoute", "string", ",", "docslogLevel", "logrus", ".", "Level", ",", "requestTimeout", "...", "time", ".", "Duration", ")", "*", "ProtoClient", "{", "newclient", ":=", "newProto", "(", "docslogLevel", ",", "requestTimeout", "...", ")", "\n", "newclient", ".", "docsRoute", "=", "docsRoute", "\n", "newclient", ".", "descriptorsRoute", "=", "descriptorsRoute", "\n", "return", "newclient", "\n", "}" ]
// NewWithDescriptor returns a new protoclient with the descriptors route and // auto documentation route.
[ "NewWithDescriptor", "returns", "a", "new", "protoclient", "with", "the", "descriptors", "route", "and", "auto", "documentation", "route", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L308-L313
train
topfreegames/pitaya
client/protoclient.go
LoadServerInfo
func (pc *ProtoClient) LoadServerInfo(addr string) error { pc.ready = false if err := pc.Client.ConnectToTLS(addr, true); err != nil { if err.Error() == "EOF" { if err := pc.Client.ConnectTo(addr); err != nil { return err } } else { return err } } // request doc info _, err := pc.SendRequest(pc.docsRoute, make([]byte, 0)) if err != nil { return err } response := <-pc.Client.IncomingMsgChan docs := &protos.Doc{} if err := proto.Unmarshal(response.Data, docs); err != nil { return err } if err := pc.getDescriptors(docs.Doc); err != nil { return err } pc.Disconnect() pc.ready = true return nil }
go
func (pc *ProtoClient) LoadServerInfo(addr string) error { pc.ready = false if err := pc.Client.ConnectToTLS(addr, true); err != nil { if err.Error() == "EOF" { if err := pc.Client.ConnectTo(addr); err != nil { return err } } else { return err } } // request doc info _, err := pc.SendRequest(pc.docsRoute, make([]byte, 0)) if err != nil { return err } response := <-pc.Client.IncomingMsgChan docs := &protos.Doc{} if err := proto.Unmarshal(response.Data, docs); err != nil { return err } if err := pc.getDescriptors(docs.Doc); err != nil { return err } pc.Disconnect() pc.ready = true return nil }
[ "func", "(", "pc", "*", "ProtoClient", ")", "LoadServerInfo", "(", "addr", "string", ")", "error", "{", "pc", ".", "ready", "=", "false", "\n", "if", "err", ":=", "pc", ".", "Client", ".", "ConnectToTLS", "(", "addr", ",", "true", ")", ";", "err", "!=", "nil", "{", "if", "err", ".", "Error", "(", ")", "==", "\"EOF\"", "{", "if", "err", ":=", "pc", ".", "Client", ".", "ConnectTo", "(", "addr", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "return", "err", "\n", "}", "\n", "}", "\n", "_", ",", "err", ":=", "pc", ".", "SendRequest", "(", "pc", ".", "docsRoute", ",", "make", "(", "[", "]", "byte", ",", "0", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "response", ":=", "<-", "pc", ".", "Client", ".", "IncomingMsgChan", "\n", "docs", ":=", "&", "protos", ".", "Doc", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "response", ".", "Data", ",", "docs", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "pc", ".", "getDescriptors", "(", "docs", ".", "Doc", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "pc", ".", "Disconnect", "(", ")", "\n", "pc", ".", "ready", "=", "true", "\n", "return", "nil", "\n", "}" ]
// LoadServerInfo load commands information from the server. Addr is the // server address.
[ "LoadServerInfo", "load", "commands", "information", "from", "the", "server", ".", "Addr", "is", "the", "server", "address", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L317-L350
train
topfreegames/pitaya
client/protoclient.go
Disconnect
func (pc *ProtoClient) Disconnect() { pc.Client.Disconnect() if pc.ready { pc.closeChan <- true } }
go
func (pc *ProtoClient) Disconnect() { pc.Client.Disconnect() if pc.ready { pc.closeChan <- true } }
[ "func", "(", "pc", "*", "ProtoClient", ")", "Disconnect", "(", ")", "{", "pc", ".", "Client", ".", "Disconnect", "(", ")", "\n", "if", "pc", ".", "ready", "{", "pc", ".", "closeChan", "<-", "true", "\n", "}", "\n", "}" ]
// Disconnect the client
[ "Disconnect", "the", "client" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L353-L358
train
topfreegames/pitaya
client/protoclient.go
waitForData
func (pc *ProtoClient) waitForData() { for { select { case response := <-pc.Client.IncomingMsgChan: inputMsg := dynamic.NewMessage(pc.expectedInputDescriptor) msg, ok := pc.info.Commands[response.Route] if ok { inputMsg = dynamic.NewMessage(msg.outputMsgDescriptor) } else { pc.expectedInputDescriptor = nil } if response.Err { errMsg := &protos.Error{} err := proto.Unmarshal(response.Data, errMsg) if err != nil { logger.Log.Errorf("Erro decode error data: %s", string(response.Data)) continue } response.Data, err = json.Marshal(errMsg) if err != nil { logger.Log.Errorf("Erro encode error to json: %s", string(response.Data)) continue } pc.IncomingMsgChan <- response continue } if inputMsg == nil { logger.Log.Errorf("Not expected data: %s", string(response.Data)) continue } err := inputMsg.Unmarshal(response.Data) if err != nil { logger.Log.Errorf("Erro decode data: %s", string(response.Data)) continue } data, err2 := inputMsg.MarshalJSON() if err2 != nil { logger.Log.Errorf("Erro encode data to json: %s", string(response.Data)) continue } response.Data = data pc.IncomingMsgChan <- response case <-pc.closeChan: return } } }
go
func (pc *ProtoClient) waitForData() { for { select { case response := <-pc.Client.IncomingMsgChan: inputMsg := dynamic.NewMessage(pc.expectedInputDescriptor) msg, ok := pc.info.Commands[response.Route] if ok { inputMsg = dynamic.NewMessage(msg.outputMsgDescriptor) } else { pc.expectedInputDescriptor = nil } if response.Err { errMsg := &protos.Error{} err := proto.Unmarshal(response.Data, errMsg) if err != nil { logger.Log.Errorf("Erro decode error data: %s", string(response.Data)) continue } response.Data, err = json.Marshal(errMsg) if err != nil { logger.Log.Errorf("Erro encode error to json: %s", string(response.Data)) continue } pc.IncomingMsgChan <- response continue } if inputMsg == nil { logger.Log.Errorf("Not expected data: %s", string(response.Data)) continue } err := inputMsg.Unmarshal(response.Data) if err != nil { logger.Log.Errorf("Erro decode data: %s", string(response.Data)) continue } data, err2 := inputMsg.MarshalJSON() if err2 != nil { logger.Log.Errorf("Erro encode data to json: %s", string(response.Data)) continue } response.Data = data pc.IncomingMsgChan <- response case <-pc.closeChan: return } } }
[ "func", "(", "pc", "*", "ProtoClient", ")", "waitForData", "(", ")", "{", "for", "{", "select", "{", "case", "response", ":=", "<-", "pc", ".", "Client", ".", "IncomingMsgChan", ":", "inputMsg", ":=", "dynamic", ".", "NewMessage", "(", "pc", ".", "expectedInputDescriptor", ")", "\n", "msg", ",", "ok", ":=", "pc", ".", "info", ".", "Commands", "[", "response", ".", "Route", "]", "\n", "if", "ok", "{", "inputMsg", "=", "dynamic", ".", "NewMessage", "(", "msg", ".", "outputMsgDescriptor", ")", "\n", "}", "else", "{", "pc", ".", "expectedInputDescriptor", "=", "nil", "\n", "}", "\n", "if", "response", ".", "Err", "{", "errMsg", ":=", "&", "protos", ".", "Error", "{", "}", "\n", "err", ":=", "proto", ".", "Unmarshal", "(", "response", ".", "Data", ",", "errMsg", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Erro decode error data: %s\"", ",", "string", "(", "response", ".", "Data", ")", ")", "\n", "continue", "\n", "}", "\n", "response", ".", "Data", ",", "err", "=", "json", ".", "Marshal", "(", "errMsg", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Erro encode error to json: %s\"", ",", "string", "(", "response", ".", "Data", ")", ")", "\n", "continue", "\n", "}", "\n", "pc", ".", "IncomingMsgChan", "<-", "response", "\n", "continue", "\n", "}", "\n", "if", "inputMsg", "==", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Not expected data: %s\"", ",", "string", "(", "response", ".", "Data", ")", ")", "\n", "continue", "\n", "}", "\n", "err", ":=", "inputMsg", ".", "Unmarshal", "(", "response", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Erro decode data: %s\"", ",", "string", "(", "response", ".", "Data", ")", ")", "\n", "continue", "\n", "}", "\n", "data", ",", "err2", ":=", "inputMsg", ".", "MarshalJSON", "(", ")", "\n", "if", "err2", "!=", "nil", "{", "logger", ".", "Log", ".", "Errorf", "(", "\"Erro encode data to json: %s\"", ",", "string", "(", "response", ".", "Data", ")", ")", "\n", "continue", "\n", "}", "\n", "response", ".", "Data", "=", "data", "\n", "pc", ".", "IncomingMsgChan", "<-", "response", "\n", "case", "<-", "pc", ".", "closeChan", ":", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Wait for new messages from the server or the connection end. If the menssage // has a response.Route, it decodes based on it. If not, it will try to decode // the menssage using the last expected response.
[ "Wait", "for", "new", "messages", "from", "the", "server", "or", "the", "connection", "end", ".", "If", "the", "menssage", "has", "a", "response", ".", "Route", "it", "decodes", "based", "on", "it", ".", "If", "not", "it", "will", "try", "to", "decode", "the", "menssage", "using", "the", "last", "expected", "response", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L363-L416
train
topfreegames/pitaya
client/protoclient.go
LoadInfo
func (pc *ProtoClient) LoadInfo(info *ProtoBufferInfo) error { if info == nil { return errors.New("protobuffer information invalid") } pc.info = *info pc.ready = true return nil }
go
func (pc *ProtoClient) LoadInfo(info *ProtoBufferInfo) error { if info == nil { return errors.New("protobuffer information invalid") } pc.info = *info pc.ready = true return nil }
[ "func", "(", "pc", "*", "ProtoClient", ")", "LoadInfo", "(", "info", "*", "ProtoBufferInfo", ")", "error", "{", "if", "info", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"protobuffer information invalid\"", ")", "\n", "}", "\n", "pc", ".", "info", "=", "*", "info", "\n", "pc", ".", "ready", "=", "true", "\n", "return", "nil", "\n", "}" ]
// LoadInfo load commands information form ProtoBufferInfo
[ "LoadInfo", "load", "commands", "information", "form", "ProtoBufferInfo" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L469-L476
train
topfreegames/pitaya
client/protoclient.go
AddPushResponse
func (pc *ProtoClient) AddPushResponse(route string, protoName string) { if route != "" && protoName != "" { var command Command command.input = "" command.output = protoName pc.info.Commands[route] = &command } }
go
func (pc *ProtoClient) AddPushResponse(route string, protoName string) { if route != "" && protoName != "" { var command Command command.input = "" command.output = protoName pc.info.Commands[route] = &command } }
[ "func", "(", "pc", "*", "ProtoClient", ")", "AddPushResponse", "(", "route", "string", ",", "protoName", "string", ")", "{", "if", "route", "!=", "\"\"", "&&", "protoName", "!=", "\"\"", "{", "var", "command", "Command", "\n", "command", ".", "input", "=", "\"\"", "\n", "command", ".", "output", "=", "protoName", "\n", "pc", ".", "info", ".", "Commands", "[", "route", "]", "=", "&", "command", "\n", "}", "\n", "}" ]
// AddPushResponse add a push response. Must be ladded before LoadInfo.
[ "AddPushResponse", "add", "a", "push", "response", ".", "Must", "be", "ladded", "before", "LoadInfo", "." ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/client/protoclient.go#L479-L487
train
topfreegames/pitaya
mocks/net.go
NewMockAddr
func NewMockAddr(ctrl *gomock.Controller) *MockAddr { mock := &MockAddr{ctrl: ctrl} mock.recorder = &MockAddrMockRecorder{mock} return mock }
go
func NewMockAddr(ctrl *gomock.Controller) *MockAddr { mock := &MockAddr{ctrl: ctrl} mock.recorder = &MockAddrMockRecorder{mock} return mock }
[ "func", "NewMockAddr", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockAddr", "{", "mock", ":=", "&", "MockAddr", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockAddrMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockAddr creates a new mock instance
[ "NewMockAddr", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L27-L31
train
topfreegames/pitaya
mocks/net.go
NewMockConn
func NewMockConn(ctrl *gomock.Controller) *MockConn { mock := &MockConn{ctrl: ctrl} mock.recorder = &MockConnMockRecorder{mock} return mock }
go
func NewMockConn(ctrl *gomock.Controller) *MockConn { mock := &MockConn{ctrl: ctrl} mock.recorder = &MockConnMockRecorder{mock} return mock }
[ "func", "NewMockConn", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockConn", "{", "mock", ":=", "&", "MockConn", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockConnMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockConn creates a new mock instance
[ "NewMockConn", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L74-L78
train
topfreegames/pitaya
mocks/net.go
Read
func (mr *MockConnMockRecorder) Read(b interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockConn)(nil).Read), b) }
go
func (mr *MockConnMockRecorder) Read(b interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockConn)(nil).Read), b) }
[ "func", "(", "mr", "*", "MockConnMockRecorder", ")", "Read", "(", "b", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"Read\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockConn", ")", "(", "nil", ")", ".", "Read", ")", ",", "b", ")", "\n", "}" ]
// Read indicates an expected call of Read
[ "Read", "indicates", "an", "expected", "call", "of", "Read" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L94-L96
train
topfreegames/pitaya
mocks/net.go
LocalAddr
func (m *MockConn) LocalAddr() net.Addr { ret := m.ctrl.Call(m, "LocalAddr") ret0, _ := ret[0].(net.Addr) return ret0 }
go
func (m *MockConn) LocalAddr() net.Addr { ret := m.ctrl.Call(m, "LocalAddr") ret0, _ := ret[0].(net.Addr) return ret0 }
[ "func", "(", "m", "*", "MockConn", ")", "LocalAddr", "(", ")", "net", ".", "Addr", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"LocalAddr\"", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "net", ".", "Addr", ")", "\n", "return", "ret0", "\n", "}" ]
// LocalAddr mocks base method
[ "LocalAddr", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L124-L128
train
topfreegames/pitaya
mocks/net.go
SetReadDeadline
func (mr *MockConnMockRecorder) SetReadDeadline(t interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetReadDeadline", reflect.TypeOf((*MockConn)(nil).SetReadDeadline), t) }
go
func (mr *MockConnMockRecorder) SetReadDeadline(t interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetReadDeadline", reflect.TypeOf((*MockConn)(nil).SetReadDeadline), t) }
[ "func", "(", "mr", "*", "MockConnMockRecorder", ")", "SetReadDeadline", "(", "t", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"SetReadDeadline\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockConn", ")", "(", "nil", ")", ".", "SetReadDeadline", ")", ",", "t", ")", "\n", "}" ]
// SetReadDeadline indicates an expected call of SetReadDeadline
[ "SetReadDeadline", "indicates", "an", "expected", "call", "of", "SetReadDeadline" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L167-L169
train
topfreegames/pitaya
mocks/net.go
SetWriteDeadline
func (m *MockConn) SetWriteDeadline(t time.Time) error { ret := m.ctrl.Call(m, "SetWriteDeadline", t) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockConn) SetWriteDeadline(t time.Time) error { ret := m.ctrl.Call(m, "SetWriteDeadline", t) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockConn", ")", "SetWriteDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"SetWriteDeadline\"", ",", "t", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// SetWriteDeadline mocks base method
[ "SetWriteDeadline", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/mocks/net.go#L172-L176
train
topfreegames/pitaya
protos/mocks/pitaya.go
NewMockPitayaClient
func NewMockPitayaClient(ctrl *gomock.Controller) *MockPitayaClient { mock := &MockPitayaClient{ctrl: ctrl} mock.recorder = &MockPitayaClientMockRecorder{mock} return mock }
go
func NewMockPitayaClient(ctrl *gomock.Controller) *MockPitayaClient { mock := &MockPitayaClient{ctrl: ctrl} mock.recorder = &MockPitayaClientMockRecorder{mock} return mock }
[ "func", "NewMockPitayaClient", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockPitayaClient", "{", "mock", ":=", "&", "MockPitayaClient", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockPitayaClientMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockPitayaClient creates a new mock instance
[ "NewMockPitayaClient", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/protos/mocks/pitaya.go#L27-L31
train
topfreegames/pitaya
protos/mocks/pitaya.go
PushToUser
func (mr *MockPitayaClientMockRecorder) PushToUser(ctx, in interface{}, opts ...interface{}) *gomock.Call { varargs := append([]interface{}{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PushToUser", reflect.TypeOf((*MockPitayaClient)(nil).PushToUser), varargs...) }
go
func (mr *MockPitayaClientMockRecorder) PushToUser(ctx, in interface{}, opts ...interface{}) *gomock.Call { varargs := append([]interface{}{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PushToUser", reflect.TypeOf((*MockPitayaClient)(nil).PushToUser), varargs...) }
[ "func", "(", "mr", "*", "MockPitayaClientMockRecorder", ")", "PushToUser", "(", "ctx", ",", "in", "interface", "{", "}", ",", "opts", "...", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "varargs", ":=", "append", "(", "[", "]", "interface", "{", "}", "{", "ctx", ",", "in", "}", ",", "opts", "...", ")", "\n", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"PushToUser\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockPitayaClient", ")", "(", "nil", ")", ".", "PushToUser", ")", ",", "varargs", "...", ")", "\n", "}" ]
// PushToUser indicates an expected call of PushToUser
[ "PushToUser", "indicates", "an", "expected", "call", "of", "PushToUser" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/protos/mocks/pitaya.go#L69-L72
train
topfreegames/pitaya
protos/mocks/pitaya.go
NewMockPitayaServer
func NewMockPitayaServer(ctrl *gomock.Controller) *MockPitayaServer { mock := &MockPitayaServer{ctrl: ctrl} mock.recorder = &MockPitayaServerMockRecorder{mock} return mock }
go
func NewMockPitayaServer(ctrl *gomock.Controller) *MockPitayaServer { mock := &MockPitayaServer{ctrl: ctrl} mock.recorder = &MockPitayaServerMockRecorder{mock} return mock }
[ "func", "NewMockPitayaServer", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockPitayaServer", "{", "mock", ":=", "&", "MockPitayaServer", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockPitayaServerMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockPitayaServer creates a new mock instance
[ "NewMockPitayaServer", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/protos/mocks/pitaya.go#L122-L126
train
topfreegames/pitaya
protos/mocks/pitaya.go
PushToUser
func (m *MockPitayaServer) PushToUser(arg0 context.Context, arg1 *protos.Push) (*protos.Response, error) { ret := m.ctrl.Call(m, "PushToUser", arg0, arg1) ret0, _ := ret[0].(*protos.Response) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockPitayaServer) PushToUser(arg0 context.Context, arg1 *protos.Push) (*protos.Response, error) { ret := m.ctrl.Call(m, "PushToUser", arg0, arg1) ret0, _ := ret[0].(*protos.Response) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockPitayaServer", ")", "PushToUser", "(", "arg0", "context", ".", "Context", ",", "arg1", "*", "protos", ".", "Push", ")", "(", "*", "protos", ".", "Response", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"PushToUser\"", ",", "arg0", ",", "arg1", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "*", "protos", ".", "Response", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// PushToUser mocks base method
[ "PushToUser", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/protos/mocks/pitaya.go#L147-L152
train
topfreegames/pitaya
modules/unique_session.go
NewUniqueSession
func NewUniqueSession(server *cluster.Server, rpcServer cluster.RPCServer, rpcClient cluster.RPCClient) *UniqueSession { return &UniqueSession{ server: server, rpcClient: rpcClient, } }
go
func NewUniqueSession(server *cluster.Server, rpcServer cluster.RPCServer, rpcClient cluster.RPCClient) *UniqueSession { return &UniqueSession{ server: server, rpcClient: rpcClient, } }
[ "func", "NewUniqueSession", "(", "server", "*", "cluster", ".", "Server", ",", "rpcServer", "cluster", ".", "RPCServer", ",", "rpcClient", "cluster", ".", "RPCClient", ")", "*", "UniqueSession", "{", "return", "&", "UniqueSession", "{", "server", ":", "server", ",", "rpcClient", ":", "rpcClient", ",", "}", "\n", "}" ]
// NewUniqueSession creates a new unique session module
[ "NewUniqueSession", "creates", "a", "new", "unique", "session", "module" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/unique_session.go#L38-L43
train
topfreegames/pitaya
modules/unique_session.go
OnUserBind
func (u *UniqueSession) OnUserBind(uid, fid string) { if u.server.ID == fid { return } oldSession := session.GetSessionByUID(uid) if oldSession != nil { // TODO: it would be nice to set this correctly oldSession.Kick(context.Background()) } }
go
func (u *UniqueSession) OnUserBind(uid, fid string) { if u.server.ID == fid { return } oldSession := session.GetSessionByUID(uid) if oldSession != nil { // TODO: it would be nice to set this correctly oldSession.Kick(context.Background()) } }
[ "func", "(", "u", "*", "UniqueSession", ")", "OnUserBind", "(", "uid", ",", "fid", "string", ")", "{", "if", "u", ".", "server", ".", "ID", "==", "fid", "{", "return", "\n", "}", "\n", "oldSession", ":=", "session", ".", "GetSessionByUID", "(", "uid", ")", "\n", "if", "oldSession", "!=", "nil", "{", "oldSession", ".", "Kick", "(", "context", ".", "Background", "(", ")", ")", "\n", "}", "\n", "}" ]
// OnUserBind method should be called when a user binds a session in remote servers
[ "OnUserBind", "method", "should", "be", "called", "when", "a", "user", "binds", "a", "session", "in", "remote", "servers" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/unique_session.go#L46-L55
train
topfreegames/pitaya
modules/unique_session.go
Init
func (u *UniqueSession) Init() error { session.OnSessionBind(func(ctx context.Context, s *session.Session) error { oldSession := session.GetSessionByUID(s.UID()) if oldSession != nil { return oldSession.Kick(ctx) } err := u.rpcClient.BroadcastSessionBind(s.UID()) return err }) return nil }
go
func (u *UniqueSession) Init() error { session.OnSessionBind(func(ctx context.Context, s *session.Session) error { oldSession := session.GetSessionByUID(s.UID()) if oldSession != nil { return oldSession.Kick(ctx) } err := u.rpcClient.BroadcastSessionBind(s.UID()) return err }) return nil }
[ "func", "(", "u", "*", "UniqueSession", ")", "Init", "(", ")", "error", "{", "session", ".", "OnSessionBind", "(", "func", "(", "ctx", "context", ".", "Context", ",", "s", "*", "session", ".", "Session", ")", "error", "{", "oldSession", ":=", "session", ".", "GetSessionByUID", "(", "s", ".", "UID", "(", ")", ")", "\n", "if", "oldSession", "!=", "nil", "{", "return", "oldSession", ".", "Kick", "(", "ctx", ")", "\n", "}", "\n", "err", ":=", "u", ".", "rpcClient", ".", "BroadcastSessionBind", "(", "s", ".", "UID", "(", ")", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "nil", "\n", "}" ]
// Init initializes the module
[ "Init", "initializes", "the", "module" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/unique_session.go#L58-L68
train
topfreegames/pitaya
modules/binary.go
NewBinary
func NewBinary(binPath string, args []string, gracefulShutdownInterval ...time.Duration) *Binary { gracefulTime := 15 * time.Second if len(gracefulShutdownInterval) > 0 { gracefulTime = gracefulShutdownInterval[0] } return &Binary{ binPath: binPath, args: args, gracefulShutdownInterval: gracefulTime, exitCh: make(chan struct{}), } }
go
func NewBinary(binPath string, args []string, gracefulShutdownInterval ...time.Duration) *Binary { gracefulTime := 15 * time.Second if len(gracefulShutdownInterval) > 0 { gracefulTime = gracefulShutdownInterval[0] } return &Binary{ binPath: binPath, args: args, gracefulShutdownInterval: gracefulTime, exitCh: make(chan struct{}), } }
[ "func", "NewBinary", "(", "binPath", "string", ",", "args", "[", "]", "string", ",", "gracefulShutdownInterval", "...", "time", ".", "Duration", ")", "*", "Binary", "{", "gracefulTime", ":=", "15", "*", "time", ".", "Second", "\n", "if", "len", "(", "gracefulShutdownInterval", ")", ">", "0", "{", "gracefulTime", "=", "gracefulShutdownInterval", "[", "0", "]", "\n", "}", "\n", "return", "&", "Binary", "{", "binPath", ":", "binPath", ",", "args", ":", "args", ",", "gracefulShutdownInterval", ":", "gracefulTime", ",", "exitCh", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "}" ]
// NewBinary creates a new binary module with the given path
[ "NewBinary", "creates", "a", "new", "binary", "module", "with", "the", "given", "path" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/binary.go#L45-L56
train
topfreegames/pitaya
modules/binary.go
Init
func (b *Binary) Init() error { b.cmd = exec.Command(b.binPath, b.args...) stdout, _ := b.cmd.StdoutPipe() stdOutScanner := bufio.NewScanner(stdout) stderr, _ := b.cmd.StderrPipe() stdErrScanner := bufio.NewScanner(stderr) go func() { for stdOutScanner.Scan() { logger.Log.Info(stdOutScanner.Text()) } }() go func() { for stdErrScanner.Scan() { logger.Log.Error(stdErrScanner.Text()) } }() err := b.cmd.Start() go func() { b.cmd.Wait() close(b.exitCh) }() return err }
go
func (b *Binary) Init() error { b.cmd = exec.Command(b.binPath, b.args...) stdout, _ := b.cmd.StdoutPipe() stdOutScanner := bufio.NewScanner(stdout) stderr, _ := b.cmd.StderrPipe() stdErrScanner := bufio.NewScanner(stderr) go func() { for stdOutScanner.Scan() { logger.Log.Info(stdOutScanner.Text()) } }() go func() { for stdErrScanner.Scan() { logger.Log.Error(stdErrScanner.Text()) } }() err := b.cmd.Start() go func() { b.cmd.Wait() close(b.exitCh) }() return err }
[ "func", "(", "b", "*", "Binary", ")", "Init", "(", ")", "error", "{", "b", ".", "cmd", "=", "exec", ".", "Command", "(", "b", ".", "binPath", ",", "b", ".", "args", "...", ")", "\n", "stdout", ",", "_", ":=", "b", ".", "cmd", ".", "StdoutPipe", "(", ")", "\n", "stdOutScanner", ":=", "bufio", ".", "NewScanner", "(", "stdout", ")", "\n", "stderr", ",", "_", ":=", "b", ".", "cmd", ".", "StderrPipe", "(", ")", "\n", "stdErrScanner", ":=", "bufio", ".", "NewScanner", "(", "stderr", ")", "\n", "go", "func", "(", ")", "{", "for", "stdOutScanner", ".", "Scan", "(", ")", "{", "logger", ".", "Log", ".", "Info", "(", "stdOutScanner", ".", "Text", "(", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "stdErrScanner", ".", "Scan", "(", ")", "{", "logger", ".", "Log", ".", "Error", "(", "stdErrScanner", ".", "Text", "(", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n", "err", ":=", "b", ".", "cmd", ".", "Start", "(", ")", "\n", "go", "func", "(", ")", "{", "b", ".", "cmd", ".", "Wait", "(", ")", "\n", "close", "(", "b", ".", "exitCh", ")", "\n", "}", "(", ")", "\n", "return", "err", "\n", "}" ]
// Init initializes the binary
[ "Init", "initializes", "the", "binary" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/binary.go#L64-L86
train
topfreegames/pitaya
modules/binary.go
Shutdown
func (b *Binary) Shutdown() error { err := b.cmd.Process.Signal(syscall.SIGTERM) if err != nil { return err } timeout := time.After(b.gracefulShutdownInterval) select { case <-b.exitCh: return nil case <-timeout: b.cmd.Process.Kill() return constants.ErrTimeoutTerminatingBinaryModule } }
go
func (b *Binary) Shutdown() error { err := b.cmd.Process.Signal(syscall.SIGTERM) if err != nil { return err } timeout := time.After(b.gracefulShutdownInterval) select { case <-b.exitCh: return nil case <-timeout: b.cmd.Process.Kill() return constants.ErrTimeoutTerminatingBinaryModule } }
[ "func", "(", "b", "*", "Binary", ")", "Shutdown", "(", ")", "error", "{", "err", ":=", "b", ".", "cmd", ".", "Process", ".", "Signal", "(", "syscall", ".", "SIGTERM", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "timeout", ":=", "time", ".", "After", "(", "b", ".", "gracefulShutdownInterval", ")", "\n", "select", "{", "case", "<-", "b", ".", "exitCh", ":", "return", "nil", "\n", "case", "<-", "timeout", ":", "b", ".", "cmd", ".", "Process", ".", "Kill", "(", ")", "\n", "return", "constants", ".", "ErrTimeoutTerminatingBinaryModule", "\n", "}", "\n", "}" ]
// Shutdown shutdowns the binary module
[ "Shutdown", "shutdowns", "the", "binary", "module" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/modules/binary.go#L89-L102
train
topfreegames/pitaya
metrics/prometheus_reporter.go
GetPrometheusReporter
func GetPrometheusReporter( serverType string, config *config.Config, constLabels map[string]string, ) (*PrometheusReporter, error) { var ( port = config.GetInt("pitaya.metrics.prometheus.port") game = config.GetString("pitaya.game") additionalLabels = config.GetStringMapString("pitaya.metrics.additionalTags") ) spec, err := NewCustomMetricsSpec(config) if err != nil { return nil, err } once.Do(func() { prometheusReporter = &PrometheusReporter{ serverType: serverType, game: game, countReportersMap: make(map[string]*prometheus.CounterVec), summaryReportersMap: make(map[string]*prometheus.SummaryVec), gaugeReportersMap: make(map[string]*prometheus.GaugeVec), } prometheusReporter.registerMetrics(constLabels, additionalLabels, spec) http.Handle("/metrics", prometheus.Handler()) go (func() { log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) })() }) return prometheusReporter, nil }
go
func GetPrometheusReporter( serverType string, config *config.Config, constLabels map[string]string, ) (*PrometheusReporter, error) { var ( port = config.GetInt("pitaya.metrics.prometheus.port") game = config.GetString("pitaya.game") additionalLabels = config.GetStringMapString("pitaya.metrics.additionalTags") ) spec, err := NewCustomMetricsSpec(config) if err != nil { return nil, err } once.Do(func() { prometheusReporter = &PrometheusReporter{ serverType: serverType, game: game, countReportersMap: make(map[string]*prometheus.CounterVec), summaryReportersMap: make(map[string]*prometheus.SummaryVec), gaugeReportersMap: make(map[string]*prometheus.GaugeVec), } prometheusReporter.registerMetrics(constLabels, additionalLabels, spec) http.Handle("/metrics", prometheus.Handler()) go (func() { log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) })() }) return prometheusReporter, nil }
[ "func", "GetPrometheusReporter", "(", "serverType", "string", ",", "config", "*", "config", ".", "Config", ",", "constLabels", "map", "[", "string", "]", "string", ",", ")", "(", "*", "PrometheusReporter", ",", "error", ")", "{", "var", "(", "port", "=", "config", ".", "GetInt", "(", "\"pitaya.metrics.prometheus.port\"", ")", "\n", "game", "=", "config", ".", "GetString", "(", "\"pitaya.game\"", ")", "\n", "additionalLabels", "=", "config", ".", "GetStringMapString", "(", "\"pitaya.metrics.additionalTags\"", ")", "\n", ")", "\n", "spec", ",", "err", ":=", "NewCustomMetricsSpec", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "once", ".", "Do", "(", "func", "(", ")", "{", "prometheusReporter", "=", "&", "PrometheusReporter", "{", "serverType", ":", "serverType", ",", "game", ":", "game", ",", "countReportersMap", ":", "make", "(", "map", "[", "string", "]", "*", "prometheus", ".", "CounterVec", ")", ",", "summaryReportersMap", ":", "make", "(", "map", "[", "string", "]", "*", "prometheus", ".", "SummaryVec", ")", ",", "gaugeReportersMap", ":", "make", "(", "map", "[", "string", "]", "*", "prometheus", ".", "GaugeVec", ")", ",", "}", "\n", "prometheusReporter", ".", "registerMetrics", "(", "constLabels", ",", "additionalLabels", ",", "spec", ")", "\n", "http", ".", "Handle", "(", "\"/metrics\"", ",", "prometheus", ".", "Handler", "(", ")", ")", "\n", "go", "(", "func", "(", ")", "{", "log", ".", "Fatal", "(", "http", ".", "ListenAndServe", "(", "fmt", ".", "Sprintf", "(", "\":%d\"", ",", "port", ")", ",", "nil", ")", ")", "\n", "}", ")", "(", ")", "\n", "}", ")", "\n", "return", "prometheusReporter", ",", "nil", "\n", "}" ]
// GetPrometheusReporter gets the prometheus reporter singleton
[ "GetPrometheusReporter", "gets", "the", "prometheus", "reporter", "singleton" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/prometheus_reporter.go#L265-L297
train
topfreegames/pitaya
metrics/prometheus_reporter.go
ReportSummary
func (p *PrometheusReporter) ReportSummary(metric string, labels map[string]string, value float64) error { sum := p.summaryReportersMap[metric] if sum != nil { labels = p.ensureLabels(labels) sum.With(labels).Observe(value) return nil } return constants.ErrMetricNotKnown }
go
func (p *PrometheusReporter) ReportSummary(metric string, labels map[string]string, value float64) error { sum := p.summaryReportersMap[metric] if sum != nil { labels = p.ensureLabels(labels) sum.With(labels).Observe(value) return nil } return constants.ErrMetricNotKnown }
[ "func", "(", "p", "*", "PrometheusReporter", ")", "ReportSummary", "(", "metric", "string", ",", "labels", "map", "[", "string", "]", "string", ",", "value", "float64", ")", "error", "{", "sum", ":=", "p", ".", "summaryReportersMap", "[", "metric", "]", "\n", "if", "sum", "!=", "nil", "{", "labels", "=", "p", ".", "ensureLabels", "(", "labels", ")", "\n", "sum", ".", "With", "(", "labels", ")", ".", "Observe", "(", "value", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "constants", ".", "ErrMetricNotKnown", "\n", "}" ]
// ReportSummary reports a summary metric
[ "ReportSummary", "reports", "a", "summary", "metric" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/prometheus_reporter.go#L300-L308
train
topfreegames/pitaya
metrics/prometheus_reporter.go
ReportCount
func (p *PrometheusReporter) ReportCount(metric string, labels map[string]string, count float64) error { cnt := p.countReportersMap[metric] if cnt != nil { labels = p.ensureLabels(labels) cnt.With(labels).Add(count) return nil } return constants.ErrMetricNotKnown }
go
func (p *PrometheusReporter) ReportCount(metric string, labels map[string]string, count float64) error { cnt := p.countReportersMap[metric] if cnt != nil { labels = p.ensureLabels(labels) cnt.With(labels).Add(count) return nil } return constants.ErrMetricNotKnown }
[ "func", "(", "p", "*", "PrometheusReporter", ")", "ReportCount", "(", "metric", "string", ",", "labels", "map", "[", "string", "]", "string", ",", "count", "float64", ")", "error", "{", "cnt", ":=", "p", ".", "countReportersMap", "[", "metric", "]", "\n", "if", "cnt", "!=", "nil", "{", "labels", "=", "p", ".", "ensureLabels", "(", "labels", ")", "\n", "cnt", ".", "With", "(", "labels", ")", ".", "Add", "(", "count", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "constants", ".", "ErrMetricNotKnown", "\n", "}" ]
// ReportCount reports a summary metric
[ "ReportCount", "reports", "a", "summary", "metric" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/prometheus_reporter.go#L311-L319
train
topfreegames/pitaya
metrics/prometheus_reporter.go
ReportGauge
func (p *PrometheusReporter) ReportGauge(metric string, labels map[string]string, value float64) error { g := p.gaugeReportersMap[metric] if g != nil { labels = p.ensureLabels(labels) g.With(labels).Set(value) return nil } return constants.ErrMetricNotKnown }
go
func (p *PrometheusReporter) ReportGauge(metric string, labels map[string]string, value float64) error { g := p.gaugeReportersMap[metric] if g != nil { labels = p.ensureLabels(labels) g.With(labels).Set(value) return nil } return constants.ErrMetricNotKnown }
[ "func", "(", "p", "*", "PrometheusReporter", ")", "ReportGauge", "(", "metric", "string", ",", "labels", "map", "[", "string", "]", "string", ",", "value", "float64", ")", "error", "{", "g", ":=", "p", ".", "gaugeReportersMap", "[", "metric", "]", "\n", "if", "g", "!=", "nil", "{", "labels", "=", "p", ".", "ensureLabels", "(", "labels", ")", "\n", "g", ".", "With", "(", "labels", ")", ".", "Set", "(", "value", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "constants", ".", "ErrMetricNotKnown", "\n", "}" ]
// ReportGauge reports a gauge metric
[ "ReportGauge", "reports", "a", "gauge", "metric" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/prometheus_reporter.go#L322-L330
train
topfreegames/pitaya
metrics/prometheus_reporter.go
ensureLabels
func (p *PrometheusReporter) ensureLabels(labels map[string]string) map[string]string { for key, defaultVal := range p.additionalLabels { if _, ok := labels[key]; !ok { labels[key] = defaultVal } } return labels }
go
func (p *PrometheusReporter) ensureLabels(labels map[string]string) map[string]string { for key, defaultVal := range p.additionalLabels { if _, ok := labels[key]; !ok { labels[key] = defaultVal } } return labels }
[ "func", "(", "p", "*", "PrometheusReporter", ")", "ensureLabels", "(", "labels", "map", "[", "string", "]", "string", ")", "map", "[", "string", "]", "string", "{", "for", "key", ",", "defaultVal", ":=", "range", "p", ".", "additionalLabels", "{", "if", "_", ",", "ok", ":=", "labels", "[", "key", "]", ";", "!", "ok", "{", "labels", "[", "key", "]", "=", "defaultVal", "\n", "}", "\n", "}", "\n", "return", "labels", "\n", "}" ]
// ensureLabels checks if labels contains the additionalLabels values, // otherwise adds them with the default values
[ "ensureLabels", "checks", "if", "labels", "contains", "the", "additionalLabels", "values", "otherwise", "adds", "them", "with", "the", "default", "values" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/metrics/prometheus_reporter.go#L334-L342
train
topfreegames/pitaya
examples/demo/worker/services/worker.go
Configure
func (w *Worker) Configure() error { err := pitaya.StartWorker(pitaya.GetConfig()) if err != nil { return err } pitaya.RegisterRPCJob(&RPCJob{}) return nil }
go
func (w *Worker) Configure() error { err := pitaya.StartWorker(pitaya.GetConfig()) if err != nil { return err } pitaya.RegisterRPCJob(&RPCJob{}) return nil }
[ "func", "(", "w", "*", "Worker", ")", "Configure", "(", ")", "error", "{", "err", ":=", "pitaya", ".", "StartWorker", "(", "pitaya", ".", "GetConfig", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "pitaya", ".", "RegisterRPCJob", "(", "&", "RPCJob", "{", "}", ")", "\n", "return", "nil", "\n", "}" ]
// Configure starts workers and register rpc job
[ "Configure", "starts", "workers", "and", "register", "rpc", "job" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/worker/services/worker.go#L18-L26
train
topfreegames/pitaya
examples/demo/worker/services/worker.go
ServerDiscovery
func (r *RPCJob) ServerDiscovery( route string, rpcMetadata map[string]interface{}, ) (serverID string, err error) { return "", nil }
go
func (r *RPCJob) ServerDiscovery( route string, rpcMetadata map[string]interface{}, ) (serverID string, err error) { return "", nil }
[ "func", "(", "r", "*", "RPCJob", ")", "ServerDiscovery", "(", "route", "string", ",", "rpcMetadata", "map", "[", "string", "]", "interface", "{", "}", ",", ")", "(", "serverID", "string", ",", "err", "error", ")", "{", "return", "\"\"", ",", "nil", "\n", "}" ]
// ServerDiscovery returns a serverID="", meaning any server // is ok
[ "ServerDiscovery", "returns", "a", "serverID", "=", "meaning", "any", "server", "is", "ok" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/worker/services/worker.go#L33-L38
train
topfreegames/pitaya
examples/demo/worker/services/worker.go
RPC
func (r *RPCJob) RPC( ctx context.Context, serverID, routeStr string, reply, arg proto.Message, ) error { return pitaya.RPCTo(ctx, serverID, routeStr, reply, arg) }
go
func (r *RPCJob) RPC( ctx context.Context, serverID, routeStr string, reply, arg proto.Message, ) error { return pitaya.RPCTo(ctx, serverID, routeStr, reply, arg) }
[ "func", "(", "r", "*", "RPCJob", ")", "RPC", "(", "ctx", "context", ".", "Context", ",", "serverID", ",", "routeStr", "string", ",", "reply", ",", "arg", "proto", ".", "Message", ",", ")", "error", "{", "return", "pitaya", ".", "RPCTo", "(", "ctx", ",", "serverID", ",", "routeStr", ",", "reply", ",", "arg", ")", "\n", "}" ]
// RPC calls pitaya's rpc
[ "RPC", "calls", "pitaya", "s", "rpc" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/worker/services/worker.go#L41-L47
train
topfreegames/pitaya
examples/demo/worker/services/worker.go
GetArgReply
func (r *RPCJob) GetArgReply( route string, ) (arg, reply proto.Message, err error) { return &protos.Arg{}, &protos.Response{}, nil }
go
func (r *RPCJob) GetArgReply( route string, ) (arg, reply proto.Message, err error) { return &protos.Arg{}, &protos.Response{}, nil }
[ "func", "(", "r", "*", "RPCJob", ")", "GetArgReply", "(", "route", "string", ",", ")", "(", "arg", ",", "reply", "proto", ".", "Message", ",", "err", "error", ")", "{", "return", "&", "protos", ".", "Arg", "{", "}", ",", "&", "protos", ".", "Response", "{", "}", ",", "nil", "\n", "}" ]
// GetArgReply returns reply and arg of LogRemote, // since we have no other methods in this example
[ "GetArgReply", "returns", "reply", "and", "arg", "of", "LogRemote", "since", "we", "have", "no", "other", "methods", "in", "this", "example" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/examples/demo/worker/services/worker.go#L51-L55
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
NewMockModule
func NewMockModule(ctrl *gomock.Controller) *MockModule { mock := &MockModule{ctrl: ctrl} mock.recorder = &MockModuleMockRecorder{mock} return mock }
go
func NewMockModule(ctrl *gomock.Controller) *MockModule { mock := &MockModule{ctrl: ctrl} mock.recorder = &MockModuleMockRecorder{mock} return mock }
[ "func", "NewMockModule", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockModule", "{", "mock", ":=", "&", "MockModule", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockModuleMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockModule creates a new mock instance
[ "NewMockModule", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L24-L28
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
AfterInit
func (mr *MockModuleMockRecorder) AfterInit() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterInit", reflect.TypeOf((*MockModule)(nil).AfterInit)) }
go
func (mr *MockModuleMockRecorder) AfterInit() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AfterInit", reflect.TypeOf((*MockModule)(nil).AfterInit)) }
[ "func", "(", "mr", "*", "MockModuleMockRecorder", ")", "AfterInit", "(", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"AfterInit\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockModule", ")", "(", "nil", ")", ".", "AfterInit", ")", ")", "\n", "}" ]
// AfterInit indicates an expected call of AfterInit
[ "AfterInit", "indicates", "an", "expected", "call", "of", "AfterInit" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L53-L55
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
NewMockBindingStorage
func NewMockBindingStorage(ctrl *gomock.Controller) *MockBindingStorage { mock := &MockBindingStorage{ctrl: ctrl} mock.recorder = &MockBindingStorageMockRecorder{mock} return mock }
go
func NewMockBindingStorage(ctrl *gomock.Controller) *MockBindingStorage { mock := &MockBindingStorage{ctrl: ctrl} mock.recorder = &MockBindingStorageMockRecorder{mock} return mock }
[ "func", "NewMockBindingStorage", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockBindingStorage", "{", "mock", ":=", "&", "MockBindingStorage", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockBindingStorageMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockBindingStorage creates a new mock instance
[ "NewMockBindingStorage", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L91-L95
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
GetUserFrontendID
func (m *MockBindingStorage) GetUserFrontendID(uid, frontendType string) (string, error) { ret := m.ctrl.Call(m, "GetUserFrontendID", uid, frontendType) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockBindingStorage) GetUserFrontendID(uid, frontendType string) (string, error) { ret := m.ctrl.Call(m, "GetUserFrontendID", uid, frontendType) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockBindingStorage", ")", "GetUserFrontendID", "(", "uid", ",", "frontendType", "string", ")", "(", "string", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"GetUserFrontendID\"", ",", "uid", ",", "frontendType", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "string", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// GetUserFrontendID mocks base method
[ "GetUserFrontendID", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L103-L108
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
GetUserFrontendID
func (mr *MockBindingStorageMockRecorder) GetUserFrontendID(uid, frontendType interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserFrontendID", reflect.TypeOf((*MockBindingStorage)(nil).GetUserFrontendID), uid, frontendType) }
go
func (mr *MockBindingStorageMockRecorder) GetUserFrontendID(uid, frontendType interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserFrontendID", reflect.TypeOf((*MockBindingStorage)(nil).GetUserFrontendID), uid, frontendType) }
[ "func", "(", "mr", "*", "MockBindingStorageMockRecorder", ")", "GetUserFrontendID", "(", "uid", ",", "frontendType", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"GetUserFrontendID\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockBindingStorage", ")", "(", "nil", ")", ".", "GetUserFrontendID", ")", ",", "uid", ",", "frontendType", ")", "\n", "}" ]
// GetUserFrontendID indicates an expected call of GetUserFrontendID
[ "GetUserFrontendID", "indicates", "an", "expected", "call", "of", "GetUserFrontendID" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L111-L113
train
topfreegames/pitaya
interfaces/mocks/interfaces.go
PutBinding
func (m *MockBindingStorage) PutBinding(uid string) error { ret := m.ctrl.Call(m, "PutBinding", uid) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockBindingStorage) PutBinding(uid string) error { ret := m.ctrl.Call(m, "PutBinding", uid) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockBindingStorage", ")", "PutBinding", "(", "uid", "string", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"PutBinding\"", ",", "uid", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// PutBinding mocks base method
[ "PutBinding", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/interfaces/mocks/interfaces.go#L116-L120
train
topfreegames/pitaya
docgenerator/descriptors.go
ProtoDescriptors
func ProtoDescriptors(protoName string) ([]byte, error) { if strings.HasSuffix(protoName, ".proto") { descriptor := proto.FileDescriptor(protoName) if descriptor == nil { return nil, constants.ErrProtodescriptor } return descriptor, nil } if strings.HasPrefix(protoName, "types.") { protoName = strings.Replace(protoName, "types.", "google.protobuf.", 1) } protoReflectTypePointer := proto.MessageType(protoName) if protoReflectTypePointer == nil { return nil, constants.ErrProtodescriptor } protoReflectType := protoReflectTypePointer.Elem() protoValue := reflect.New(protoReflectType) descriptorMethod, ok := protoReflectTypePointer.MethodByName("Descriptor") if !ok { return nil, constants.ErrProtodescriptor } descriptorValue := descriptorMethod.Func.Call([]reflect.Value{protoValue}) protoDescriptor := descriptorValue[0].Bytes() return protoDescriptor, nil }
go
func ProtoDescriptors(protoName string) ([]byte, error) { if strings.HasSuffix(protoName, ".proto") { descriptor := proto.FileDescriptor(protoName) if descriptor == nil { return nil, constants.ErrProtodescriptor } return descriptor, nil } if strings.HasPrefix(protoName, "types.") { protoName = strings.Replace(protoName, "types.", "google.protobuf.", 1) } protoReflectTypePointer := proto.MessageType(protoName) if protoReflectTypePointer == nil { return nil, constants.ErrProtodescriptor } protoReflectType := protoReflectTypePointer.Elem() protoValue := reflect.New(protoReflectType) descriptorMethod, ok := protoReflectTypePointer.MethodByName("Descriptor") if !ok { return nil, constants.ErrProtodescriptor } descriptorValue := descriptorMethod.Func.Call([]reflect.Value{protoValue}) protoDescriptor := descriptorValue[0].Bytes() return protoDescriptor, nil }
[ "func", "ProtoDescriptors", "(", "protoName", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "strings", ".", "HasSuffix", "(", "protoName", ",", "\".proto\"", ")", "{", "descriptor", ":=", "proto", ".", "FileDescriptor", "(", "protoName", ")", "\n", "if", "descriptor", "==", "nil", "{", "return", "nil", ",", "constants", ".", "ErrProtodescriptor", "\n", "}", "\n", "return", "descriptor", ",", "nil", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "protoName", ",", "\"types.\"", ")", "{", "protoName", "=", "strings", ".", "Replace", "(", "protoName", ",", "\"types.\"", ",", "\"google.protobuf.\"", ",", "1", ")", "\n", "}", "\n", "protoReflectTypePointer", ":=", "proto", ".", "MessageType", "(", "protoName", ")", "\n", "if", "protoReflectTypePointer", "==", "nil", "{", "return", "nil", ",", "constants", ".", "ErrProtodescriptor", "\n", "}", "\n", "protoReflectType", ":=", "protoReflectTypePointer", ".", "Elem", "(", ")", "\n", "protoValue", ":=", "reflect", ".", "New", "(", "protoReflectType", ")", "\n", "descriptorMethod", ",", "ok", ":=", "protoReflectTypePointer", ".", "MethodByName", "(", "\"Descriptor\"", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "constants", ".", "ErrProtodescriptor", "\n", "}", "\n", "descriptorValue", ":=", "descriptorMethod", ".", "Func", ".", "Call", "(", "[", "]", "reflect", ".", "Value", "{", "protoValue", "}", ")", "\n", "protoDescriptor", ":=", "descriptorValue", "[", "0", "]", ".", "Bytes", "(", ")", "\n", "return", "protoDescriptor", ",", "nil", "\n", "}" ]
// ProtoDescriptors returns the descriptor for a given message name or .proto file
[ "ProtoDescriptors", "returns", "the", "descriptor", "for", "a", "given", "message", "name", "or", ".", "proto", "file" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/docgenerator/descriptors.go#L12-L40
train
topfreegames/pitaya
conn/codec/mocks/packet_decoder.go
NewMockPacketDecoder
func NewMockPacketDecoder(ctrl *gomock.Controller) *MockPacketDecoder { mock := &MockPacketDecoder{ctrl: ctrl} mock.recorder = &MockPacketDecoderMockRecorder{mock} return mock }
go
func NewMockPacketDecoder(ctrl *gomock.Controller) *MockPacketDecoder { mock := &MockPacketDecoder{ctrl: ctrl} mock.recorder = &MockPacketDecoderMockRecorder{mock} return mock }
[ "func", "NewMockPacketDecoder", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockPacketDecoder", "{", "mock", ":=", "&", "MockPacketDecoder", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockPacketDecoderMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockPacketDecoder creates a new mock instance
[ "NewMockPacketDecoder", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/codec/mocks/packet_decoder.go#L25-L29
train
topfreegames/pitaya
conn/codec/mocks/packet_decoder.go
Decode
func (m *MockPacketDecoder) Decode(data []byte) ([]*packet.Packet, error) { ret := m.ctrl.Call(m, "Decode", data) ret0, _ := ret[0].([]*packet.Packet) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockPacketDecoder) Decode(data []byte) ([]*packet.Packet, error) { ret := m.ctrl.Call(m, "Decode", data) ret0, _ := ret[0].([]*packet.Packet) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockPacketDecoder", ")", "Decode", "(", "data", "[", "]", "byte", ")", "(", "[", "]", "*", "packet", ".", "Packet", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"Decode\"", ",", "data", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "[", "]", "*", "packet", ".", "Packet", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// Decode mocks base method
[ "Decode", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/codec/mocks/packet_decoder.go#L37-L42
train
topfreegames/pitaya
conn/codec/mocks/packet_decoder.go
Decode
func (mr *MockPacketDecoderMockRecorder) Decode(data interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decode", reflect.TypeOf((*MockPacketDecoder)(nil).Decode), data) }
go
func (mr *MockPacketDecoderMockRecorder) Decode(data interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decode", reflect.TypeOf((*MockPacketDecoder)(nil).Decode), data) }
[ "func", "(", "mr", "*", "MockPacketDecoderMockRecorder", ")", "Decode", "(", "data", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"Decode\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockPacketDecoder", ")", "(", "nil", ")", ".", "Decode", ")", ",", "data", ")", "\n", "}" ]
// Decode indicates an expected call of Decode
[ "Decode", "indicates", "an", "expected", "call", "of", "Decode" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/conn/codec/mocks/packet_decoder.go#L45-L47
train
topfreegames/pitaya
cluster/mocks/cluster.go
NewMockRPCServer
func NewMockRPCServer(ctrl *gomock.Controller) *MockRPCServer { mock := &MockRPCServer{ctrl: ctrl} mock.recorder = &MockRPCServerMockRecorder{mock} return mock }
go
func NewMockRPCServer(ctrl *gomock.Controller) *MockRPCServer { mock := &MockRPCServer{ctrl: ctrl} mock.recorder = &MockRPCServerMockRecorder{mock} return mock }
[ "func", "NewMockRPCServer", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockRPCServer", "{", "mock", ":=", "&", "MockRPCServer", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockRPCServerMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockRPCServer creates a new mock instance
[ "NewMockRPCServer", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L30-L34
train
topfreegames/pitaya
cluster/mocks/cluster.go
SetPitayaServer
func (m *MockRPCServer) SetPitayaServer(arg0 protos.PitayaServer) { m.ctrl.Call(m, "SetPitayaServer", arg0) }
go
func (m *MockRPCServer) SetPitayaServer(arg0 protos.PitayaServer) { m.ctrl.Call(m, "SetPitayaServer", arg0) }
[ "func", "(", "m", "*", "MockRPCServer", ")", "SetPitayaServer", "(", "arg0", "protos", ".", "PitayaServer", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"SetPitayaServer\"", ",", "arg0", ")", "\n", "}" ]
// SetPitayaServer mocks base method
[ "SetPitayaServer", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L42-L44
train
topfreegames/pitaya
cluster/mocks/cluster.go
SetPitayaServer
func (mr *MockRPCServerMockRecorder) SetPitayaServer(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPitayaServer", reflect.TypeOf((*MockRPCServer)(nil).SetPitayaServer), arg0) }
go
func (mr *MockRPCServerMockRecorder) SetPitayaServer(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPitayaServer", reflect.TypeOf((*MockRPCServer)(nil).SetPitayaServer), arg0) }
[ "func", "(", "mr", "*", "MockRPCServerMockRecorder", ")", "SetPitayaServer", "(", "arg0", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"SetPitayaServer\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockRPCServer", ")", "(", "nil", ")", ".", "SetPitayaServer", ")", ",", "arg0", ")", "\n", "}" ]
// SetPitayaServer indicates an expected call of SetPitayaServer
[ "SetPitayaServer", "indicates", "an", "expected", "call", "of", "SetPitayaServer" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L47-L49
train
topfreegames/pitaya
cluster/mocks/cluster.go
NewMockRPCClient
func NewMockRPCClient(ctrl *gomock.Controller) *MockRPCClient { mock := &MockRPCClient{ctrl: ctrl} mock.recorder = &MockRPCClientMockRecorder{mock} return mock }
go
func NewMockRPCClient(ctrl *gomock.Controller) *MockRPCClient { mock := &MockRPCClient{ctrl: ctrl} mock.recorder = &MockRPCClientMockRecorder{mock} return mock }
[ "func", "NewMockRPCClient", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockRPCClient", "{", "mock", ":=", "&", "MockRPCClient", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockRPCClientMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockRPCClient creates a new mock instance
[ "NewMockRPCClient", "creates", "a", "new", "mock", "instance" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L107-L111
train
topfreegames/pitaya
cluster/mocks/cluster.go
Send
func (mr *MockRPCClientMockRecorder) Send(route, data interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockRPCClient)(nil).Send), route, data) }
go
func (mr *MockRPCClientMockRecorder) Send(route, data interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockRPCClient)(nil).Send), route, data) }
[ "func", "(", "mr", "*", "MockRPCClientMockRecorder", ")", "Send", "(", "route", ",", "data", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"Send\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockRPCClient", ")", "(", "nil", ")", ".", "Send", ")", ",", "route", ",", "data", ")", "\n", "}" ]
// Send indicates an expected call of Send
[ "Send", "indicates", "an", "expected", "call", "of", "Send" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L126-L128
train
topfreegames/pitaya
cluster/mocks/cluster.go
SendPush
func (m *MockRPCClient) SendPush(userID string, frontendSv *cluster.Server, push *protos.Push) error { ret := m.ctrl.Call(m, "SendPush", userID, frontendSv, push) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockRPCClient) SendPush(userID string, frontendSv *cluster.Server, push *protos.Push) error { ret := m.ctrl.Call(m, "SendPush", userID, frontendSv, push) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockRPCClient", ")", "SendPush", "(", "userID", "string", ",", "frontendSv", "*", "cluster", ".", "Server", ",", "push", "*", "protos", ".", "Push", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"SendPush\"", ",", "userID", ",", "frontendSv", ",", "push", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// SendPush mocks base method
[ "SendPush", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L131-L135
train
topfreegames/pitaya
cluster/mocks/cluster.go
SendPush
func (mr *MockRPCClientMockRecorder) SendPush(userID, frontendSv, push interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendPush", reflect.TypeOf((*MockRPCClient)(nil).SendPush), userID, frontendSv, push) }
go
func (mr *MockRPCClientMockRecorder) SendPush(userID, frontendSv, push interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendPush", reflect.TypeOf((*MockRPCClient)(nil).SendPush), userID, frontendSv, push) }
[ "func", "(", "mr", "*", "MockRPCClientMockRecorder", ")", "SendPush", "(", "userID", ",", "frontendSv", ",", "push", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"SendPush\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockRPCClient", ")", "(", "nil", ")", ".", "SendPush", ")", ",", "userID", ",", "frontendSv", ",", "push", ")", "\n", "}" ]
// SendPush indicates an expected call of SendPush
[ "SendPush", "indicates", "an", "expected", "call", "of", "SendPush" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L138-L140
train
topfreegames/pitaya
cluster/mocks/cluster.go
SendKick
func (m *MockRPCClient) SendKick(userID, serverType string, kick *protos.KickMsg) error { ret := m.ctrl.Call(m, "SendKick", userID, serverType, kick) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockRPCClient) SendKick(userID, serverType string, kick *protos.KickMsg) error { ret := m.ctrl.Call(m, "SendKick", userID, serverType, kick) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockRPCClient", ")", "SendKick", "(", "userID", ",", "serverType", "string", ",", "kick", "*", "protos", ".", "KickMsg", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"SendKick\"", ",", "userID", ",", "serverType", ",", "kick", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// SendKick mocks base method
[ "SendKick", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L143-L147
train
topfreegames/pitaya
cluster/mocks/cluster.go
SendKick
func (mr *MockRPCClientMockRecorder) SendKick(userID, serverType, kick interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendKick", reflect.TypeOf((*MockRPCClient)(nil).SendKick), userID, serverType, kick) }
go
func (mr *MockRPCClientMockRecorder) SendKick(userID, serverType, kick interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendKick", reflect.TypeOf((*MockRPCClient)(nil).SendKick), userID, serverType, kick) }
[ "func", "(", "mr", "*", "MockRPCClientMockRecorder", ")", "SendKick", "(", "userID", ",", "serverType", ",", "kick", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"SendKick\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockRPCClient", ")", "(", "nil", ")", ".", "SendKick", ")", ",", "userID", ",", "serverType", ",", "kick", ")", "\n", "}" ]
// SendKick indicates an expected call of SendKick
[ "SendKick", "indicates", "an", "expected", "call", "of", "SendKick" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L150-L152
train
topfreegames/pitaya
cluster/mocks/cluster.go
BroadcastSessionBind
func (m *MockRPCClient) BroadcastSessionBind(uid string) error { ret := m.ctrl.Call(m, "BroadcastSessionBind", uid) ret0, _ := ret[0].(error) return ret0 }
go
func (m *MockRPCClient) BroadcastSessionBind(uid string) error { ret := m.ctrl.Call(m, "BroadcastSessionBind", uid) ret0, _ := ret[0].(error) return ret0 }
[ "func", "(", "m", "*", "MockRPCClient", ")", "BroadcastSessionBind", "(", "uid", "string", ")", "error", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"BroadcastSessionBind\"", ",", "uid", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "error", ")", "\n", "return", "ret0", "\n", "}" ]
// BroadcastSessionBind mocks base method
[ "BroadcastSessionBind", "mocks", "base", "method" ]
b92161d7a48c87a7759ac9cabcc23e7d56f9eebd
https://github.com/topfreegames/pitaya/blob/b92161d7a48c87a7759ac9cabcc23e7d56f9eebd/cluster/mocks/cluster.go#L155-L159
train