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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
uber/tchannel-go
|
json/context.go
|
NewContext
|
func NewContext(timeout time.Duration) (Context, context.CancelFunc) {
ctx, cancel := tchannel.NewContext(timeout)
return tchannel.WrapWithHeaders(ctx, nil), cancel
}
|
go
|
func NewContext(timeout time.Duration) (Context, context.CancelFunc) {
ctx, cancel := tchannel.NewContext(timeout)
return tchannel.WrapWithHeaders(ctx, nil), cancel
}
|
[
"func",
"NewContext",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"ctx",
",",
"cancel",
":=",
"tchannel",
".",
"NewContext",
"(",
"timeout",
")",
"\n",
"return",
"tchannel",
".",
"WrapWithHeaders",
"(",
"ctx",
",",
"nil",
")",
",",
"cancel",
"\n",
"}"
] |
// NewContext returns a Context that can be used to make JSON calls.
|
[
"NewContext",
"returns",
"a",
"Context",
"that",
"can",
"be",
"used",
"to",
"make",
"JSON",
"calls",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/json/context.go#L35-L38
|
test
|
uber/tchannel-go
|
raw/handler.go
|
WriteResponse
|
func WriteResponse(response *tchannel.InboundCallResponse, resp *Res) error {
if resp.SystemErr != nil {
return response.SendSystemError(resp.SystemErr)
}
if resp.IsErr {
if err := response.SetApplicationError(); err != nil {
return err
}
}
if err := tchannel.NewArgWriter(response.Arg2Writer()).Write(resp.Arg2); err != nil {
return err
}
return tchannel.NewArgWriter(response.Arg3Writer()).Write(resp.Arg3)
}
|
go
|
func WriteResponse(response *tchannel.InboundCallResponse, resp *Res) error {
if resp.SystemErr != nil {
return response.SendSystemError(resp.SystemErr)
}
if resp.IsErr {
if err := response.SetApplicationError(); err != nil {
return err
}
}
if err := tchannel.NewArgWriter(response.Arg2Writer()).Write(resp.Arg2); err != nil {
return err
}
return tchannel.NewArgWriter(response.Arg3Writer()).Write(resp.Arg3)
}
|
[
"func",
"WriteResponse",
"(",
"response",
"*",
"tchannel",
".",
"InboundCallResponse",
",",
"resp",
"*",
"Res",
")",
"error",
"{",
"if",
"resp",
".",
"SystemErr",
"!=",
"nil",
"{",
"return",
"response",
".",
"SendSystemError",
"(",
"resp",
".",
"SystemErr",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"IsErr",
"{",
"if",
"err",
":=",
"response",
".",
"SetApplicationError",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgWriter",
"(",
"response",
".",
"Arg2Writer",
"(",
")",
")",
".",
"Write",
"(",
"resp",
".",
"Arg2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"tchannel",
".",
"NewArgWriter",
"(",
"response",
".",
"Arg3Writer",
"(",
")",
")",
".",
"Write",
"(",
"resp",
".",
"Arg3",
")",
"\n",
"}"
] |
// WriteResponse writes the given Res to the InboundCallResponse.
|
[
"WriteResponse",
"writes",
"the",
"given",
"Res",
"to",
"the",
"InboundCallResponse",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/handler.go#L71-L84
|
test
|
uber/tchannel-go
|
raw/handler.go
|
Wrap
|
func Wrap(handler Handler) tchannel.Handler {
return tchannel.HandlerFunc(func(ctx context.Context, call *tchannel.InboundCall) {
args, err := ReadArgs(call)
if err != nil {
handler.OnError(ctx, err)
return
}
resp, err := handler.Handle(ctx, args)
response := call.Response()
if err != nil {
resp = &Res{
SystemErr: err,
}
}
if err := WriteResponse(response, resp); err != nil {
handler.OnError(ctx, err)
}
})
}
|
go
|
func Wrap(handler Handler) tchannel.Handler {
return tchannel.HandlerFunc(func(ctx context.Context, call *tchannel.InboundCall) {
args, err := ReadArgs(call)
if err != nil {
handler.OnError(ctx, err)
return
}
resp, err := handler.Handle(ctx, args)
response := call.Response()
if err != nil {
resp = &Res{
SystemErr: err,
}
}
if err := WriteResponse(response, resp); err != nil {
handler.OnError(ctx, err)
}
})
}
|
[
"func",
"Wrap",
"(",
"handler",
"Handler",
")",
"tchannel",
".",
"Handler",
"{",
"return",
"tchannel",
".",
"HandlerFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"call",
"*",
"tchannel",
".",
"InboundCall",
")",
"{",
"args",
",",
"err",
":=",
"ReadArgs",
"(",
"call",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"handler",
".",
"OnError",
"(",
"ctx",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"handler",
".",
"Handle",
"(",
"ctx",
",",
"args",
")",
"\n",
"response",
":=",
"call",
".",
"Response",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"resp",
"=",
"&",
"Res",
"{",
"SystemErr",
":",
"err",
",",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"WriteResponse",
"(",
"response",
",",
"resp",
")",
";",
"err",
"!=",
"nil",
"{",
"handler",
".",
"OnError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] |
// Wrap wraps a Handler as a tchannel.Handler that can be passed to tchannel.Register.
|
[
"Wrap",
"wraps",
"a",
"Handler",
"as",
"a",
"tchannel",
".",
"Handler",
"that",
"can",
"be",
"passed",
"to",
"tchannel",
".",
"Register",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/handler.go#L87-L106
|
test
|
uber/tchannel-go
|
tracing.go
|
initFromOpenTracing
|
func (s *injectableSpan) initFromOpenTracing(span opentracing.Span) error {
return span.Tracer().Inject(span.Context(), zipkinSpanFormat, s)
}
|
go
|
func (s *injectableSpan) initFromOpenTracing(span opentracing.Span) error {
return span.Tracer().Inject(span.Context(), zipkinSpanFormat, s)
}
|
[
"func",
"(",
"s",
"*",
"injectableSpan",
")",
"initFromOpenTracing",
"(",
"span",
"opentracing",
".",
"Span",
")",
"error",
"{",
"return",
"span",
".",
"Tracer",
"(",
")",
".",
"Inject",
"(",
"span",
".",
"Context",
"(",
")",
",",
"zipkinSpanFormat",
",",
"s",
")",
"\n",
"}"
] |
// initFromOpenTracing initializes injectableSpan fields from an OpenTracing Span,
// assuming the tracing implementation supports Zipkin-style span IDs.
|
[
"initFromOpenTracing",
"initializes",
"injectableSpan",
"fields",
"from",
"an",
"OpenTracing",
"Span",
"assuming",
"the",
"tracing",
"implementation",
"supports",
"Zipkin",
"-",
"style",
"span",
"IDs",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/tracing.go#L114-L116
|
test
|
uber/tchannel-go
|
tracing.go
|
startOutboundSpan
|
func (c *Connection) startOutboundSpan(ctx context.Context, serviceName, methodName string, call *OutboundCall, startTime time.Time) opentracing.Span {
var parent opentracing.SpanContext // ok to be nil
if s := opentracing.SpanFromContext(ctx); s != nil {
parent = s.Context()
}
span := c.Tracer().StartSpan(
methodName,
opentracing.ChildOf(parent),
opentracing.StartTime(startTime),
)
if isTracingDisabled(ctx) {
ext.SamplingPriority.Set(span, 0)
}
ext.SpanKindRPCClient.Set(span)
ext.PeerService.Set(span, serviceName)
c.setPeerHostPort(span)
span.SetTag("as", call.callReq.Headers[ArgScheme])
var injectable injectableSpan
if err := injectable.initFromOpenTracing(span); err == nil {
call.callReq.Tracing = Span(injectable)
} else {
call.callReq.Tracing.initRandom()
}
return span
}
|
go
|
func (c *Connection) startOutboundSpan(ctx context.Context, serviceName, methodName string, call *OutboundCall, startTime time.Time) opentracing.Span {
var parent opentracing.SpanContext // ok to be nil
if s := opentracing.SpanFromContext(ctx); s != nil {
parent = s.Context()
}
span := c.Tracer().StartSpan(
methodName,
opentracing.ChildOf(parent),
opentracing.StartTime(startTime),
)
if isTracingDisabled(ctx) {
ext.SamplingPriority.Set(span, 0)
}
ext.SpanKindRPCClient.Set(span)
ext.PeerService.Set(span, serviceName)
c.setPeerHostPort(span)
span.SetTag("as", call.callReq.Headers[ArgScheme])
var injectable injectableSpan
if err := injectable.initFromOpenTracing(span); err == nil {
call.callReq.Tracing = Span(injectable)
} else {
call.callReq.Tracing.initRandom()
}
return span
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"startOutboundSpan",
"(",
"ctx",
"context",
".",
"Context",
",",
"serviceName",
",",
"methodName",
"string",
",",
"call",
"*",
"OutboundCall",
",",
"startTime",
"time",
".",
"Time",
")",
"opentracing",
".",
"Span",
"{",
"var",
"parent",
"opentracing",
".",
"SpanContext",
"\n",
"if",
"s",
":=",
"opentracing",
".",
"SpanFromContext",
"(",
"ctx",
")",
";",
"s",
"!=",
"nil",
"{",
"parent",
"=",
"s",
".",
"Context",
"(",
")",
"\n",
"}",
"\n",
"span",
":=",
"c",
".",
"Tracer",
"(",
")",
".",
"StartSpan",
"(",
"methodName",
",",
"opentracing",
".",
"ChildOf",
"(",
"parent",
")",
",",
"opentracing",
".",
"StartTime",
"(",
"startTime",
")",
",",
")",
"\n",
"if",
"isTracingDisabled",
"(",
"ctx",
")",
"{",
"ext",
".",
"SamplingPriority",
".",
"Set",
"(",
"span",
",",
"0",
")",
"\n",
"}",
"\n",
"ext",
".",
"SpanKindRPCClient",
".",
"Set",
"(",
"span",
")",
"\n",
"ext",
".",
"PeerService",
".",
"Set",
"(",
"span",
",",
"serviceName",
")",
"\n",
"c",
".",
"setPeerHostPort",
"(",
"span",
")",
"\n",
"span",
".",
"SetTag",
"(",
"\"as\"",
",",
"call",
".",
"callReq",
".",
"Headers",
"[",
"ArgScheme",
"]",
")",
"\n",
"var",
"injectable",
"injectableSpan",
"\n",
"if",
"err",
":=",
"injectable",
".",
"initFromOpenTracing",
"(",
"span",
")",
";",
"err",
"==",
"nil",
"{",
"call",
".",
"callReq",
".",
"Tracing",
"=",
"Span",
"(",
"injectable",
")",
"\n",
"}",
"else",
"{",
"call",
".",
"callReq",
".",
"Tracing",
".",
"initRandom",
"(",
")",
"\n",
"}",
"\n",
"return",
"span",
"\n",
"}"
] |
// startOutboundSpan creates a new tracing span to represent the outbound RPC call.
// If the context already contains a span, it will be used as a parent, otherwise
// a new root span is created.
//
// If the tracer supports Zipkin-style trace IDs, then call.callReq.Tracing is
// initialized with those IDs. Otherwise it is assigned random values.
|
[
"startOutboundSpan",
"creates",
"a",
"new",
"tracing",
"span",
"to",
"represent",
"the",
"outbound",
"RPC",
"call",
".",
"If",
"the",
"context",
"already",
"contains",
"a",
"span",
"it",
"will",
"be",
"used",
"as",
"a",
"parent",
"otherwise",
"a",
"new",
"root",
"span",
"is",
"created",
".",
"If",
"the",
"tracer",
"supports",
"Zipkin",
"-",
"style",
"trace",
"IDs",
"then",
"call",
".",
"callReq",
".",
"Tracing",
"is",
"initialized",
"with",
"those",
"IDs",
".",
"Otherwise",
"it",
"is",
"assigned",
"random",
"values",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/tracing.go#L139-L163
|
test
|
uber/tchannel-go
|
hyperbahn/utils.go
|
intToIP4
|
func intToIP4(ip uint32) net.IP {
return net.IP{
byte(ip >> 24 & 0xff),
byte(ip >> 16 & 0xff),
byte(ip >> 8 & 0xff),
byte(ip & 0xff),
}
}
|
go
|
func intToIP4(ip uint32) net.IP {
return net.IP{
byte(ip >> 24 & 0xff),
byte(ip >> 16 & 0xff),
byte(ip >> 8 & 0xff),
byte(ip & 0xff),
}
}
|
[
"func",
"intToIP4",
"(",
"ip",
"uint32",
")",
"net",
".",
"IP",
"{",
"return",
"net",
".",
"IP",
"{",
"byte",
"(",
"ip",
">>",
"24",
"&",
"0xff",
")",
",",
"byte",
"(",
"ip",
">>",
"16",
"&",
"0xff",
")",
",",
"byte",
"(",
"ip",
">>",
"8",
"&",
"0xff",
")",
",",
"byte",
"(",
"ip",
"&",
"0xff",
")",
",",
"}",
"\n",
"}"
] |
// intToIP4 converts an integer IP representation into a 4-byte net.IP struct
|
[
"intToIP4",
"converts",
"an",
"integer",
"IP",
"representation",
"into",
"a",
"4",
"-",
"byte",
"net",
".",
"IP",
"struct"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/hyperbahn/utils.go#L31-L38
|
test
|
uber/tchannel-go
|
hyperbahn/utils.go
|
servicePeerToHostPort
|
func servicePeerToHostPort(peer *hyperbahn.ServicePeer) string {
host := intToIP4(uint32(*peer.IP.Ipv4)).String()
port := strconv.Itoa(int(peer.Port))
return net.JoinHostPort(host, port)
}
|
go
|
func servicePeerToHostPort(peer *hyperbahn.ServicePeer) string {
host := intToIP4(uint32(*peer.IP.Ipv4)).String()
port := strconv.Itoa(int(peer.Port))
return net.JoinHostPort(host, port)
}
|
[
"func",
"servicePeerToHostPort",
"(",
"peer",
"*",
"hyperbahn",
".",
"ServicePeer",
")",
"string",
"{",
"host",
":=",
"intToIP4",
"(",
"uint32",
"(",
"*",
"peer",
".",
"IP",
".",
"Ipv4",
")",
")",
".",
"String",
"(",
")",
"\n",
"port",
":=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"peer",
".",
"Port",
")",
")",
"\n",
"return",
"net",
".",
"JoinHostPort",
"(",
"host",
",",
"port",
")",
"\n",
"}"
] |
// servicePeerToHostPort converts a Hyperbahn ServicePeer into a hostPort string.
|
[
"servicePeerToHostPort",
"converts",
"a",
"Hyperbahn",
"ServicePeer",
"into",
"a",
"hostPort",
"string",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/hyperbahn/utils.go#L41-L45
|
test
|
uber/tchannel-go
|
stats/statsdreporter.go
|
NewStatsdReporter
|
func NewStatsdReporter(addr, prefix string) (tchannel.StatsReporter, error) {
client, err := statsd.NewBufferedClient(addr, prefix, time.Second, 0)
if err != nil {
return nil, err
}
return NewStatsdReporterClient(client), nil
}
|
go
|
func NewStatsdReporter(addr, prefix string) (tchannel.StatsReporter, error) {
client, err := statsd.NewBufferedClient(addr, prefix, time.Second, 0)
if err != nil {
return nil, err
}
return NewStatsdReporterClient(client), nil
}
|
[
"func",
"NewStatsdReporter",
"(",
"addr",
",",
"prefix",
"string",
")",
"(",
"tchannel",
".",
"StatsReporter",
",",
"error",
")",
"{",
"client",
",",
"err",
":=",
"statsd",
".",
"NewBufferedClient",
"(",
"addr",
",",
"prefix",
",",
"time",
".",
"Second",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewStatsdReporterClient",
"(",
"client",
")",
",",
"nil",
"\n",
"}"
] |
// NewStatsdReporter returns a StatsReporter that reports to statsd on the given addr.
|
[
"NewStatsdReporter",
"returns",
"a",
"StatsReporter",
"that",
"reports",
"to",
"statsd",
"on",
"the",
"given",
"addr",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/stats/statsdreporter.go#L40-L47
|
test
|
uber/tchannel-go
|
tos/tos_string.go
|
UnmarshalText
|
func (r *ToS) UnmarshalText(data []byte) error {
if v, ok := _tosNameToValue[string(data)]; ok {
*r = v
return nil
}
return fmt.Errorf("invalid ToS %q", string(data))
}
|
go
|
func (r *ToS) UnmarshalText(data []byte) error {
if v, ok := _tosNameToValue[string(data)]; ok {
*r = v
return nil
}
return fmt.Errorf("invalid ToS %q", string(data))
}
|
[
"func",
"(",
"r",
"*",
"ToS",
")",
"UnmarshalText",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"v",
",",
"ok",
":=",
"_tosNameToValue",
"[",
"string",
"(",
"data",
")",
"]",
";",
"ok",
"{",
"*",
"r",
"=",
"v",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid ToS %q\"",
",",
"string",
"(",
"data",
")",
")",
"\n",
"}"
] |
// UnmarshalText implements TextUnMarshaler from encoding
|
[
"UnmarshalText",
"implements",
"TextUnMarshaler",
"from",
"encoding"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/tos/tos_string.go#L46-L53
|
test
|
uber/tchannel-go
|
peer_heap.go
|
Push
|
func (ph *peerHeap) Push(x interface{}) {
n := len(ph.peerScores)
item := x.(*peerScore)
item.index = n
ph.peerScores = append(ph.peerScores, item)
}
|
go
|
func (ph *peerHeap) Push(x interface{}) {
n := len(ph.peerScores)
item := x.(*peerScore)
item.index = n
ph.peerScores = append(ph.peerScores, item)
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"Push",
"(",
"x",
"interface",
"{",
"}",
")",
"{",
"n",
":=",
"len",
"(",
"ph",
".",
"peerScores",
")",
"\n",
"item",
":=",
"x",
".",
"(",
"*",
"peerScore",
")",
"\n",
"item",
".",
"index",
"=",
"n",
"\n",
"ph",
".",
"peerScores",
"=",
"append",
"(",
"ph",
".",
"peerScores",
",",
"item",
")",
"\n",
"}"
] |
// Push implements heap Push interface
|
[
"Push",
"implements",
"heap",
"Push",
"interface"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L58-L63
|
test
|
uber/tchannel-go
|
peer_heap.go
|
Pop
|
func (ph *peerHeap) Pop() interface{} {
old := *ph
n := len(old.peerScores)
item := old.peerScores[n-1]
item.index = -1 // for safety
ph.peerScores = old.peerScores[:n-1]
return item
}
|
go
|
func (ph *peerHeap) Pop() interface{} {
old := *ph
n := len(old.peerScores)
item := old.peerScores[n-1]
item.index = -1 // for safety
ph.peerScores = old.peerScores[:n-1]
return item
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"Pop",
"(",
")",
"interface",
"{",
"}",
"{",
"old",
":=",
"*",
"ph",
"\n",
"n",
":=",
"len",
"(",
"old",
".",
"peerScores",
")",
"\n",
"item",
":=",
"old",
".",
"peerScores",
"[",
"n",
"-",
"1",
"]",
"\n",
"item",
".",
"index",
"=",
"-",
"1",
"\n",
"ph",
".",
"peerScores",
"=",
"old",
".",
"peerScores",
"[",
":",
"n",
"-",
"1",
"]",
"\n",
"return",
"item",
"\n",
"}"
] |
// Pop implements heap Pop interface
|
[
"Pop",
"implements",
"heap",
"Pop",
"interface"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L66-L73
|
test
|
uber/tchannel-go
|
peer_heap.go
|
updatePeer
|
func (ph *peerHeap) updatePeer(peerScore *peerScore) {
heap.Fix(ph, peerScore.index)
}
|
go
|
func (ph *peerHeap) updatePeer(peerScore *peerScore) {
heap.Fix(ph, peerScore.index)
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"updatePeer",
"(",
"peerScore",
"*",
"peerScore",
")",
"{",
"heap",
".",
"Fix",
"(",
"ph",
",",
"peerScore",
".",
"index",
")",
"\n",
"}"
] |
// updatePeer updates the score for the given peer.
|
[
"updatePeer",
"updates",
"the",
"score",
"for",
"the",
"given",
"peer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L76-L78
|
test
|
uber/tchannel-go
|
peer_heap.go
|
removePeer
|
func (ph *peerHeap) removePeer(peerScore *peerScore) {
heap.Remove(ph, peerScore.index)
}
|
go
|
func (ph *peerHeap) removePeer(peerScore *peerScore) {
heap.Remove(ph, peerScore.index)
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"removePeer",
"(",
"peerScore",
"*",
"peerScore",
")",
"{",
"heap",
".",
"Remove",
"(",
"ph",
",",
"peerScore",
".",
"index",
")",
"\n",
"}"
] |
// removePeer remove peer at specific index.
|
[
"removePeer",
"remove",
"peer",
"at",
"specific",
"index",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L81-L83
|
test
|
uber/tchannel-go
|
peer_heap.go
|
pushPeer
|
func (ph *peerHeap) pushPeer(peerScore *peerScore) {
ph.order++
newOrder := ph.order
// randRange will affect the deviation of peer's chosenCount
randRange := ph.Len()/2 + 1
peerScore.order = newOrder + uint64(ph.rng.Intn(randRange))
heap.Push(ph, peerScore)
}
|
go
|
func (ph *peerHeap) pushPeer(peerScore *peerScore) {
ph.order++
newOrder := ph.order
// randRange will affect the deviation of peer's chosenCount
randRange := ph.Len()/2 + 1
peerScore.order = newOrder + uint64(ph.rng.Intn(randRange))
heap.Push(ph, peerScore)
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"pushPeer",
"(",
"peerScore",
"*",
"peerScore",
")",
"{",
"ph",
".",
"order",
"++",
"\n",
"newOrder",
":=",
"ph",
".",
"order",
"\n",
"randRange",
":=",
"ph",
".",
"Len",
"(",
")",
"/",
"2",
"+",
"1",
"\n",
"peerScore",
".",
"order",
"=",
"newOrder",
"+",
"uint64",
"(",
"ph",
".",
"rng",
".",
"Intn",
"(",
"randRange",
")",
")",
"\n",
"heap",
".",
"Push",
"(",
"ph",
",",
"peerScore",
")",
"\n",
"}"
] |
// pushPeer pushes the new peer into the heap.
|
[
"pushPeer",
"pushes",
"the",
"new",
"peer",
"into",
"the",
"heap",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L91-L98
|
test
|
uber/tchannel-go
|
peer_heap.go
|
addPeer
|
func (ph *peerHeap) addPeer(peerScore *peerScore) {
ph.pushPeer(peerScore)
// Pick a random element, and swap the order with that peerScore.
r := ph.rng.Intn(ph.Len())
ph.swapOrder(peerScore.index, r)
}
|
go
|
func (ph *peerHeap) addPeer(peerScore *peerScore) {
ph.pushPeer(peerScore)
// Pick a random element, and swap the order with that peerScore.
r := ph.rng.Intn(ph.Len())
ph.swapOrder(peerScore.index, r)
}
|
[
"func",
"(",
"ph",
"*",
"peerHeap",
")",
"addPeer",
"(",
"peerScore",
"*",
"peerScore",
")",
"{",
"ph",
".",
"pushPeer",
"(",
"peerScore",
")",
"\n",
"r",
":=",
"ph",
".",
"rng",
".",
"Intn",
"(",
"ph",
".",
"Len",
"(",
")",
")",
"\n",
"ph",
".",
"swapOrder",
"(",
"peerScore",
".",
"index",
",",
"r",
")",
"\n",
"}"
] |
// AddPeer adds a peer to the peer heap.
|
[
"AddPeer",
"adds",
"a",
"peer",
"to",
"the",
"peer",
"heap",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer_heap.go#L111-L117
|
test
|
uber/tchannel-go
|
thrift/client.go
|
NewClient
|
func NewClient(ch *tchannel.Channel, serviceName string, opts *ClientOptions) TChanClient {
client := &client{
ch: ch,
sc: ch.GetSubChannel(serviceName),
serviceName: serviceName,
}
if opts != nil {
client.opts = *opts
}
return client
}
|
go
|
func NewClient(ch *tchannel.Channel, serviceName string, opts *ClientOptions) TChanClient {
client := &client{
ch: ch,
sc: ch.GetSubChannel(serviceName),
serviceName: serviceName,
}
if opts != nil {
client.opts = *opts
}
return client
}
|
[
"func",
"NewClient",
"(",
"ch",
"*",
"tchannel",
".",
"Channel",
",",
"serviceName",
"string",
",",
"opts",
"*",
"ClientOptions",
")",
"TChanClient",
"{",
"client",
":=",
"&",
"client",
"{",
"ch",
":",
"ch",
",",
"sc",
":",
"ch",
".",
"GetSubChannel",
"(",
"serviceName",
")",
",",
"serviceName",
":",
"serviceName",
",",
"}",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"client",
".",
"opts",
"=",
"*",
"opts",
"\n",
"}",
"\n",
"return",
"client",
"\n",
"}"
] |
// NewClient returns a Client that makes calls over the given tchannel to the given Hyperbahn service.
|
[
"NewClient",
"returns",
"a",
"Client",
"that",
"makes",
"calls",
"over",
"the",
"given",
"tchannel",
"to",
"the",
"given",
"Hyperbahn",
"service",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/client.go#L46-L56
|
test
|
uber/tchannel-go
|
root_peer_list.go
|
Add
|
func (l *RootPeerList) Add(hostPort string) *Peer {
l.RLock()
if p, ok := l.peersByHostPort[hostPort]; ok {
l.RUnlock()
return p
}
l.RUnlock()
l.Lock()
defer l.Unlock()
if p, ok := l.peersByHostPort[hostPort]; ok {
return p
}
var p *Peer
// To avoid duplicate connections, only the root list should create new
// peers. All other lists should keep refs to the root list's peers.
p = newPeer(l.channel, hostPort, l.onPeerStatusChanged, l.onClosedConnRemoved)
l.peersByHostPort[hostPort] = p
return p
}
|
go
|
func (l *RootPeerList) Add(hostPort string) *Peer {
l.RLock()
if p, ok := l.peersByHostPort[hostPort]; ok {
l.RUnlock()
return p
}
l.RUnlock()
l.Lock()
defer l.Unlock()
if p, ok := l.peersByHostPort[hostPort]; ok {
return p
}
var p *Peer
// To avoid duplicate connections, only the root list should create new
// peers. All other lists should keep refs to the root list's peers.
p = newPeer(l.channel, hostPort, l.onPeerStatusChanged, l.onClosedConnRemoved)
l.peersByHostPort[hostPort] = p
return p
}
|
[
"func",
"(",
"l",
"*",
"RootPeerList",
")",
"Add",
"(",
"hostPort",
"string",
")",
"*",
"Peer",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"if",
"p",
",",
"ok",
":=",
"l",
".",
"peersByHostPort",
"[",
"hostPort",
"]",
";",
"ok",
"{",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"p",
"\n",
"}",
"\n",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"if",
"p",
",",
"ok",
":=",
"l",
".",
"peersByHostPort",
"[",
"hostPort",
"]",
";",
"ok",
"{",
"return",
"p",
"\n",
"}",
"\n",
"var",
"p",
"*",
"Peer",
"\n",
"p",
"=",
"newPeer",
"(",
"l",
".",
"channel",
",",
"hostPort",
",",
"l",
".",
"onPeerStatusChanged",
",",
"l",
".",
"onClosedConnRemoved",
")",
"\n",
"l",
".",
"peersByHostPort",
"[",
"hostPort",
"]",
"=",
"p",
"\n",
"return",
"p",
"\n",
"}"
] |
// Add adds a peer to the root peer list if it does not exist, or return
// an existing peer if it exists.
|
[
"Add",
"adds",
"a",
"peer",
"to",
"the",
"root",
"peer",
"list",
"if",
"it",
"does",
"not",
"exist",
"or",
"return",
"an",
"existing",
"peer",
"if",
"it",
"exists",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/root_peer_list.go#L51-L73
|
test
|
uber/tchannel-go
|
root_peer_list.go
|
Get
|
func (l *RootPeerList) Get(hostPort string) (*Peer, bool) {
l.RLock()
p, ok := l.peersByHostPort[hostPort]
l.RUnlock()
return p, ok
}
|
go
|
func (l *RootPeerList) Get(hostPort string) (*Peer, bool) {
l.RLock()
p, ok := l.peersByHostPort[hostPort]
l.RUnlock()
return p, ok
}
|
[
"func",
"(",
"l",
"*",
"RootPeerList",
")",
"Get",
"(",
"hostPort",
"string",
")",
"(",
"*",
"Peer",
",",
"bool",
")",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"p",
",",
"ok",
":=",
"l",
".",
"peersByHostPort",
"[",
"hostPort",
"]",
"\n",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"p",
",",
"ok",
"\n",
"}"
] |
// Get returns a peer for the given hostPort if it exists.
|
[
"Get",
"returns",
"a",
"peer",
"for",
"the",
"given",
"hostPort",
"if",
"it",
"exists",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/root_peer_list.go#L86-L91
|
test
|
uber/tchannel-go
|
benchmark/options.go
|
WithTimeout
|
func WithTimeout(timeout time.Duration) Option {
return func(opts *options) {
opts.timeout = timeout
}
}
|
go
|
func WithTimeout(timeout time.Duration) Option {
return func(opts *options) {
opts.timeout = timeout
}
}
|
[
"func",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"options",
")",
"{",
"opts",
".",
"timeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
] |
// WithTimeout sets the timeout to use for each call.
|
[
"WithTimeout",
"sets",
"the",
"timeout",
"to",
"use",
"for",
"each",
"call",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/options.go#L48-L52
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
Methods
|
func (s *Service) Methods() []*Method {
if s.methods != nil {
return s.methods
}
for _, m := range s.Service.Methods {
s.methods = append(s.methods, &Method{m, s, s.state})
}
sort.Sort(byMethodName(s.methods))
return s.methods
}
|
go
|
func (s *Service) Methods() []*Method {
if s.methods != nil {
return s.methods
}
for _, m := range s.Service.Methods {
s.methods = append(s.methods, &Method{m, s, s.state})
}
sort.Sort(byMethodName(s.methods))
return s.methods
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"Methods",
"(",
")",
"[",
"]",
"*",
"Method",
"{",
"if",
"s",
".",
"methods",
"!=",
"nil",
"{",
"return",
"s",
".",
"methods",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"s",
".",
"Service",
".",
"Methods",
"{",
"s",
".",
"methods",
"=",
"append",
"(",
"s",
".",
"methods",
",",
"&",
"Method",
"{",
"m",
",",
"s",
",",
"s",
".",
"state",
"}",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"byMethodName",
"(",
"s",
".",
"methods",
")",
")",
"\n",
"return",
"s",
".",
"methods",
"\n",
"}"
] |
// Methods returns the methods on this service, not including methods from inherited services.
|
[
"Methods",
"returns",
"the",
"methods",
"on",
"this",
"service",
"not",
"including",
"methods",
"from",
"inherited",
"services",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L107-L117
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
InheritedMethods
|
func (s *Service) InheritedMethods() []string {
if s.inheritedMethods != nil {
return s.inheritedMethods
}
for svc := s.ExtendsService; svc != nil; svc = svc.ExtendsService {
for m := range svc.Service.Methods {
s.inheritedMethods = append(s.inheritedMethods, m)
}
}
sort.Strings(s.inheritedMethods)
return s.inheritedMethods
}
|
go
|
func (s *Service) InheritedMethods() []string {
if s.inheritedMethods != nil {
return s.inheritedMethods
}
for svc := s.ExtendsService; svc != nil; svc = svc.ExtendsService {
for m := range svc.Service.Methods {
s.inheritedMethods = append(s.inheritedMethods, m)
}
}
sort.Strings(s.inheritedMethods)
return s.inheritedMethods
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"InheritedMethods",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"s",
".",
"inheritedMethods",
"!=",
"nil",
"{",
"return",
"s",
".",
"inheritedMethods",
"\n",
"}",
"\n",
"for",
"svc",
":=",
"s",
".",
"ExtendsService",
";",
"svc",
"!=",
"nil",
";",
"svc",
"=",
"svc",
".",
"ExtendsService",
"{",
"for",
"m",
":=",
"range",
"svc",
".",
"Service",
".",
"Methods",
"{",
"s",
".",
"inheritedMethods",
"=",
"append",
"(",
"s",
".",
"inheritedMethods",
",",
"m",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"s",
".",
"inheritedMethods",
")",
"\n",
"return",
"s",
".",
"inheritedMethods",
"\n",
"}"
] |
// InheritedMethods returns names for inherited methods on this service.
|
[
"InheritedMethods",
"returns",
"names",
"for",
"inherited",
"methods",
"on",
"this",
"service",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L120-L133
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
Arguments
|
func (m *Method) Arguments() []*Field {
var args []*Field
for _, f := range m.Method.Arguments {
args = append(args, &Field{f, m.state})
}
return args
}
|
go
|
func (m *Method) Arguments() []*Field {
var args []*Field
for _, f := range m.Method.Arguments {
args = append(args, &Field{f, m.state})
}
return args
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"Arguments",
"(",
")",
"[",
"]",
"*",
"Field",
"{",
"var",
"args",
"[",
"]",
"*",
"Field",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"m",
".",
"Method",
".",
"Arguments",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"&",
"Field",
"{",
"f",
",",
"m",
".",
"state",
"}",
")",
"\n",
"}",
"\n",
"return",
"args",
"\n",
"}"
] |
// Arguments returns the argument declarations for this method.
|
[
"Arguments",
"returns",
"the",
"argument",
"declarations",
"for",
"this",
"method",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L159-L165
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
ArgList
|
func (m *Method) ArgList() string {
args := []string{"ctx " + contextType()}
for _, arg := range m.Arguments() {
args = append(args, arg.Declaration())
}
return strings.Join(args, ", ")
}
|
go
|
func (m *Method) ArgList() string {
args := []string{"ctx " + contextType()}
for _, arg := range m.Arguments() {
args = append(args, arg.Declaration())
}
return strings.Join(args, ", ")
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"ArgList",
"(",
")",
"string",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"ctx \"",
"+",
"contextType",
"(",
")",
"}",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"m",
".",
"Arguments",
"(",
")",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"arg",
".",
"Declaration",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"args",
",",
"\", \"",
")",
"\n",
"}"
] |
// ArgList returns the argument list for the function.
|
[
"ArgList",
"returns",
"the",
"argument",
"list",
"for",
"the",
"function",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L201-L207
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
CallList
|
func (m *Method) CallList(reqStruct string) string {
args := []string{"ctx"}
for _, arg := range m.Arguments() {
args = append(args, reqStruct+"."+arg.ArgStructName())
}
return strings.Join(args, ", ")
}
|
go
|
func (m *Method) CallList(reqStruct string) string {
args := []string{"ctx"}
for _, arg := range m.Arguments() {
args = append(args, reqStruct+"."+arg.ArgStructName())
}
return strings.Join(args, ", ")
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"CallList",
"(",
"reqStruct",
"string",
")",
"string",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"ctx\"",
"}",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"m",
".",
"Arguments",
"(",
")",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"reqStruct",
"+",
"\".\"",
"+",
"arg",
".",
"ArgStructName",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"args",
",",
"\", \"",
")",
"\n",
"}"
] |
// CallList creates the call to a function satisfying Interface from an Args struct.
|
[
"CallList",
"creates",
"the",
"call",
"to",
"a",
"function",
"satisfying",
"Interface",
"from",
"an",
"Args",
"struct",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L210-L216
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
RetType
|
func (m *Method) RetType() string {
if !m.HasReturn() {
return "error"
}
return fmt.Sprintf("(%v, %v)", m.state.goType(m.Method.ReturnType), "error")
}
|
go
|
func (m *Method) RetType() string {
if !m.HasReturn() {
return "error"
}
return fmt.Sprintf("(%v, %v)", m.state.goType(m.Method.ReturnType), "error")
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"RetType",
"(",
")",
"string",
"{",
"if",
"!",
"m",
".",
"HasReturn",
"(",
")",
"{",
"return",
"\"error\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"(%v, %v)\"",
",",
"m",
".",
"state",
".",
"goType",
"(",
"m",
".",
"Method",
".",
"ReturnType",
")",
",",
"\"error\"",
")",
"\n",
"}"
] |
// RetType returns the go return type of the method.
|
[
"RetType",
"returns",
"the",
"go",
"return",
"type",
"of",
"the",
"method",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L219-L224
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
WrapResult
|
func (m *Method) WrapResult(respVar string) string {
if !m.HasReturn() {
panic("cannot wrap a return when there is no return mode")
}
if m.state.isResultPointer(m.ReturnType) {
return respVar
}
return "&" + respVar
}
|
go
|
func (m *Method) WrapResult(respVar string) string {
if !m.HasReturn() {
panic("cannot wrap a return when there is no return mode")
}
if m.state.isResultPointer(m.ReturnType) {
return respVar
}
return "&" + respVar
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"WrapResult",
"(",
"respVar",
"string",
")",
"string",
"{",
"if",
"!",
"m",
".",
"HasReturn",
"(",
")",
"{",
"panic",
"(",
"\"cannot wrap a return when there is no return mode\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"state",
".",
"isResultPointer",
"(",
"m",
".",
"ReturnType",
")",
"{",
"return",
"respVar",
"\n",
"}",
"\n",
"return",
"\"&\"",
"+",
"respVar",
"\n",
"}"
] |
// WrapResult wraps the result variable before being used in the result struct.
|
[
"WrapResult",
"wraps",
"the",
"result",
"variable",
"before",
"being",
"used",
"in",
"the",
"result",
"struct",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L227-L236
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
ReturnWith
|
func (m *Method) ReturnWith(respName string, errName string) string {
if !m.HasReturn() {
return errName
}
return fmt.Sprintf("%v, %v", respName, errName)
}
|
go
|
func (m *Method) ReturnWith(respName string, errName string) string {
if !m.HasReturn() {
return errName
}
return fmt.Sprintf("%v, %v", respName, errName)
}
|
[
"func",
"(",
"m",
"*",
"Method",
")",
"ReturnWith",
"(",
"respName",
"string",
",",
"errName",
"string",
")",
"string",
"{",
"if",
"!",
"m",
".",
"HasReturn",
"(",
")",
"{",
"return",
"errName",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%v, %v\"",
",",
"respName",
",",
"errName",
")",
"\n",
"}"
] |
// ReturnWith takes the result name and the error name, and generates the return expression.
|
[
"ReturnWith",
"takes",
"the",
"result",
"name",
"and",
"the",
"error",
"name",
"and",
"generates",
"the",
"return",
"expression",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L239-L244
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/wrap.go
|
Declaration
|
func (a *Field) Declaration() string {
return fmt.Sprintf("%s %s", a.Name(), a.ArgType())
}
|
go
|
func (a *Field) Declaration() string {
return fmt.Sprintf("%s %s", a.Name(), a.ArgType())
}
|
[
"func",
"(",
"a",
"*",
"Field",
")",
"Declaration",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s %s\"",
",",
"a",
".",
"Name",
"(",
")",
",",
"a",
".",
"ArgType",
"(",
")",
")",
"\n",
"}"
] |
// Declaration returns the declaration for this field.
|
[
"Declaration",
"returns",
"the",
"declaration",
"for",
"this",
"field",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/wrap.go#L254-L256
|
test
|
uber/tchannel-go
|
idle_sweep.go
|
startIdleSweep
|
func startIdleSweep(ch *Channel, opts *ChannelOptions) *idleSweep {
is := &idleSweep{
ch: ch,
maxIdleTime: opts.MaxIdleTime,
idleCheckInterval: opts.IdleCheckInterval,
}
is.start()
return is
}
|
go
|
func startIdleSweep(ch *Channel, opts *ChannelOptions) *idleSweep {
is := &idleSweep{
ch: ch,
maxIdleTime: opts.MaxIdleTime,
idleCheckInterval: opts.IdleCheckInterval,
}
is.start()
return is
}
|
[
"func",
"startIdleSweep",
"(",
"ch",
"*",
"Channel",
",",
"opts",
"*",
"ChannelOptions",
")",
"*",
"idleSweep",
"{",
"is",
":=",
"&",
"idleSweep",
"{",
"ch",
":",
"ch",
",",
"maxIdleTime",
":",
"opts",
".",
"MaxIdleTime",
",",
"idleCheckInterval",
":",
"opts",
".",
"IdleCheckInterval",
",",
"}",
"\n",
"is",
".",
"start",
"(",
")",
"\n",
"return",
"is",
"\n",
"}"
] |
// startIdleSweep starts a poller that checks for idle connections at given
// intervals.
|
[
"startIdleSweep",
"starts",
"a",
"poller",
"that",
"checks",
"for",
"idle",
"connections",
"at",
"given",
"intervals",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/idle_sweep.go#L39-L48
|
test
|
uber/tchannel-go
|
idle_sweep.go
|
start
|
func (is *idleSweep) start() {
if is.started || is.idleCheckInterval <= 0 {
return
}
is.ch.log.WithFields(
LogField{"idleCheckInterval", is.idleCheckInterval},
LogField{"maxIdleTime", is.maxIdleTime},
).Info("Starting idle connections poller.")
is.started = true
is.stopCh = make(chan struct{})
go is.pollerLoop()
}
|
go
|
func (is *idleSweep) start() {
if is.started || is.idleCheckInterval <= 0 {
return
}
is.ch.log.WithFields(
LogField{"idleCheckInterval", is.idleCheckInterval},
LogField{"maxIdleTime", is.maxIdleTime},
).Info("Starting idle connections poller.")
is.started = true
is.stopCh = make(chan struct{})
go is.pollerLoop()
}
|
[
"func",
"(",
"is",
"*",
"idleSweep",
")",
"start",
"(",
")",
"{",
"if",
"is",
".",
"started",
"||",
"is",
".",
"idleCheckInterval",
"<=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"is",
".",
"ch",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"idleCheckInterval\"",
",",
"is",
".",
"idleCheckInterval",
"}",
",",
"LogField",
"{",
"\"maxIdleTime\"",
",",
"is",
".",
"maxIdleTime",
"}",
",",
")",
".",
"Info",
"(",
"\"Starting idle connections poller.\"",
")",
"\n",
"is",
".",
"started",
"=",
"true",
"\n",
"is",
".",
"stopCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"is",
".",
"pollerLoop",
"(",
")",
"\n",
"}"
] |
// Start runs the goroutine responsible for checking idle connections.
|
[
"Start",
"runs",
"the",
"goroutine",
"responsible",
"for",
"checking",
"idle",
"connections",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/idle_sweep.go#L51-L64
|
test
|
uber/tchannel-go
|
idle_sweep.go
|
Stop
|
func (is *idleSweep) Stop() {
if !is.started {
return
}
is.started = false
is.ch.log.Info("Stopping idle connections poller.")
close(is.stopCh)
}
|
go
|
func (is *idleSweep) Stop() {
if !is.started {
return
}
is.started = false
is.ch.log.Info("Stopping idle connections poller.")
close(is.stopCh)
}
|
[
"func",
"(",
"is",
"*",
"idleSweep",
")",
"Stop",
"(",
")",
"{",
"if",
"!",
"is",
".",
"started",
"{",
"return",
"\n",
"}",
"\n",
"is",
".",
"started",
"=",
"false",
"\n",
"is",
".",
"ch",
".",
"log",
".",
"Info",
"(",
"\"Stopping idle connections poller.\"",
")",
"\n",
"close",
"(",
"is",
".",
"stopCh",
")",
"\n",
"}"
] |
// Stop kills the poller checking for idle connections.
|
[
"Stop",
"kills",
"the",
"poller",
"checking",
"for",
"idle",
"connections",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/idle_sweep.go#L67-L75
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/gopath.go
|
ResolveWithGoPath
|
func ResolveWithGoPath(filename string) (string, error) {
for _, file := range goPathCandidates(filename) {
if _, err := os.Stat(file); !os.IsNotExist(err) {
return file, nil
}
}
return "", fmt.Errorf("file not found on GOPATH: %q", filename)
}
|
go
|
func ResolveWithGoPath(filename string) (string, error) {
for _, file := range goPathCandidates(filename) {
if _, err := os.Stat(file); !os.IsNotExist(err) {
return file, nil
}
}
return "", fmt.Errorf("file not found on GOPATH: %q", filename)
}
|
[
"func",
"ResolveWithGoPath",
"(",
"filename",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"for",
"_",
",",
"file",
":=",
"range",
"goPathCandidates",
"(",
"filename",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"file",
")",
";",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"file",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"file not found on GOPATH: %q\"",
",",
"filename",
")",
"\n",
"}"
] |
// ResolveWithGoPath will resolve the filename relative to GOPATH and returns
// the first file that exists, or an error otherwise.
|
[
"ResolveWithGoPath",
"will",
"resolve",
"the",
"filename",
"relative",
"to",
"GOPATH",
"and",
"returns",
"the",
"first",
"file",
"that",
"exists",
"or",
"an",
"error",
"otherwise",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/gopath.go#L31-L39
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/extends.go
|
setExtends
|
func setExtends(state map[string]parseState) error {
for _, v := range state {
for _, s := range v.services {
if s.Extends == "" {
continue
}
var searchServices []*Service
var searchFor string
parts := strings.SplitN(s.Extends, ".", 2)
// If it's not imported, then look at the current file's services.
if len(parts) < 2 {
searchServices = v.services
searchFor = s.Extends
} else {
include := v.global.includes[parts[0]]
s.ExtendsPrefix = include.pkg + "."
searchServices = state[include.file].services
searchFor = parts[1]
}
foundService := sort.Search(len(searchServices), func(i int) bool {
return searchServices[i].Name >= searchFor
})
if foundService == len(searchServices) {
return fmt.Errorf("failed to find base service %q for %q", s.Extends, s.Name)
}
s.ExtendsService = searchServices[foundService]
}
}
return nil
}
|
go
|
func setExtends(state map[string]parseState) error {
for _, v := range state {
for _, s := range v.services {
if s.Extends == "" {
continue
}
var searchServices []*Service
var searchFor string
parts := strings.SplitN(s.Extends, ".", 2)
// If it's not imported, then look at the current file's services.
if len(parts) < 2 {
searchServices = v.services
searchFor = s.Extends
} else {
include := v.global.includes[parts[0]]
s.ExtendsPrefix = include.pkg + "."
searchServices = state[include.file].services
searchFor = parts[1]
}
foundService := sort.Search(len(searchServices), func(i int) bool {
return searchServices[i].Name >= searchFor
})
if foundService == len(searchServices) {
return fmt.Errorf("failed to find base service %q for %q", s.Extends, s.Name)
}
s.ExtendsService = searchServices[foundService]
}
}
return nil
}
|
[
"func",
"setExtends",
"(",
"state",
"map",
"[",
"string",
"]",
"parseState",
")",
"error",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"state",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"v",
".",
"services",
"{",
"if",
"s",
".",
"Extends",
"==",
"\"\"",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"searchServices",
"[",
"]",
"*",
"Service",
"\n",
"var",
"searchFor",
"string",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"s",
".",
"Extends",
",",
"\".\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
"{",
"searchServices",
"=",
"v",
".",
"services",
"\n",
"searchFor",
"=",
"s",
".",
"Extends",
"\n",
"}",
"else",
"{",
"include",
":=",
"v",
".",
"global",
".",
"includes",
"[",
"parts",
"[",
"0",
"]",
"]",
"\n",
"s",
".",
"ExtendsPrefix",
"=",
"include",
".",
"pkg",
"+",
"\".\"",
"\n",
"searchServices",
"=",
"state",
"[",
"include",
".",
"file",
"]",
".",
"services",
"\n",
"searchFor",
"=",
"parts",
"[",
"1",
"]",
"\n",
"}",
"\n",
"foundService",
":=",
"sort",
".",
"Search",
"(",
"len",
"(",
"searchServices",
")",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"searchServices",
"[",
"i",
"]",
".",
"Name",
">=",
"searchFor",
"\n",
"}",
")",
"\n",
"if",
"foundService",
"==",
"len",
"(",
"searchServices",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to find base service %q for %q\"",
",",
"s",
".",
"Extends",
",",
"s",
".",
"Name",
")",
"\n",
"}",
"\n",
"s",
".",
"ExtendsService",
"=",
"searchServices",
"[",
"foundService",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// setExtends will set the ExtendsService for all services.
// It is done after all files are parsed, as services may extend those
// found in an included file.
|
[
"setExtends",
"will",
"set",
"the",
"ExtendsService",
"for",
"all",
"services",
".",
"It",
"is",
"done",
"after",
"all",
"files",
"are",
"parsed",
"as",
"services",
"may",
"extend",
"those",
"found",
"in",
"an",
"included",
"file",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/extends.go#L32-L64
|
test
|
uber/tchannel-go
|
handlers.go
|
register
|
func (hmap *handlerMap) register(h Handler, method string) {
hmap.Lock()
defer hmap.Unlock()
if hmap.handlers == nil {
hmap.handlers = make(map[string]Handler)
}
hmap.handlers[method] = h
}
|
go
|
func (hmap *handlerMap) register(h Handler, method string) {
hmap.Lock()
defer hmap.Unlock()
if hmap.handlers == nil {
hmap.handlers = make(map[string]Handler)
}
hmap.handlers[method] = h
}
|
[
"func",
"(",
"hmap",
"*",
"handlerMap",
")",
"register",
"(",
"h",
"Handler",
",",
"method",
"string",
")",
"{",
"hmap",
".",
"Lock",
"(",
")",
"\n",
"defer",
"hmap",
".",
"Unlock",
"(",
")",
"\n",
"if",
"hmap",
".",
"handlers",
"==",
"nil",
"{",
"hmap",
".",
"handlers",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Handler",
")",
"\n",
"}",
"\n",
"hmap",
".",
"handlers",
"[",
"method",
"]",
"=",
"h",
"\n",
"}"
] |
// Registers a handler
|
[
"Registers",
"a",
"handler"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/handlers.go#L81-L90
|
test
|
uber/tchannel-go
|
benchmark/internal_client.go
|
NewClient
|
func NewClient(hosts []string, optFns ...Option) Client {
opts := getOptions(optFns)
if opts.external {
return newExternalClient(hosts, opts)
}
if opts.numClients > 1 {
return newInternalMultiClient(hosts, opts)
}
return newClient(hosts, opts)
}
|
go
|
func NewClient(hosts []string, optFns ...Option) Client {
opts := getOptions(optFns)
if opts.external {
return newExternalClient(hosts, opts)
}
if opts.numClients > 1 {
return newInternalMultiClient(hosts, opts)
}
return newClient(hosts, opts)
}
|
[
"func",
"NewClient",
"(",
"hosts",
"[",
"]",
"string",
",",
"optFns",
"...",
"Option",
")",
"Client",
"{",
"opts",
":=",
"getOptions",
"(",
"optFns",
")",
"\n",
"if",
"opts",
".",
"external",
"{",
"return",
"newExternalClient",
"(",
"hosts",
",",
"opts",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"numClients",
">",
"1",
"{",
"return",
"newInternalMultiClient",
"(",
"hosts",
",",
"opts",
")",
"\n",
"}",
"\n",
"return",
"newClient",
"(",
"hosts",
",",
"opts",
")",
"\n",
"}"
] |
// NewClient returns a new Client that can make calls to a benchmark server.
|
[
"NewClient",
"returns",
"a",
"new",
"Client",
"that",
"can",
"make",
"calls",
"to",
"a",
"benchmark",
"server",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/internal_client.go#L47-L56
|
test
|
uber/tchannel-go
|
localip.go
|
ListenIP
|
func ListenIP() (net.IP, error) {
interfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
return listenIP(interfaces)
}
|
go
|
func ListenIP() (net.IP, error) {
interfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
return listenIP(interfaces)
}
|
[
"func",
"ListenIP",
"(",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"interfaces",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"listenIP",
"(",
"interfaces",
")",
"\n",
"}"
] |
// ListenIP returns the IP to bind to in Listen. It tries to find an IP that can be used
// by other machines to reach this machine.
|
[
"ListenIP",
"returns",
"the",
"IP",
"to",
"bind",
"to",
"in",
"Listen",
".",
"It",
"tries",
"to",
"find",
"an",
"IP",
"that",
"can",
"be",
"used",
"by",
"other",
"machines",
"to",
"reach",
"this",
"machine",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/localip.go#L89-L95
|
test
|
uber/tchannel-go
|
tnet/listener.go
|
Close
|
func (s *listener) Close() error {
if err := s.Listener.Close(); err != nil {
return err
}
s.cond.L.Lock()
for s.refs > 0 {
s.cond.Wait()
}
s.cond.L.Unlock()
return nil
}
|
go
|
func (s *listener) Close() error {
if err := s.Listener.Close(); err != nil {
return err
}
s.cond.L.Lock()
for s.refs > 0 {
s.cond.Wait()
}
s.cond.L.Unlock()
return nil
}
|
[
"func",
"(",
"s",
"*",
"listener",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"Listener",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"cond",
".",
"L",
".",
"Lock",
"(",
")",
"\n",
"for",
"s",
".",
"refs",
">",
"0",
"{",
"s",
".",
"cond",
".",
"Wait",
"(",
")",
"\n",
"}",
"\n",
"s",
".",
"cond",
".",
"L",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the listener.
// Any blocked Accept operations will be unblocked and return errors.
|
[
"Close",
"closes",
"the",
"listener",
".",
"Any",
"blocked",
"Accept",
"operations",
"will",
"be",
"unblocked",
"and",
"return",
"errors",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/tnet/listener.go#L85-L96
|
test
|
uber/tchannel-go
|
raw/call.go
|
ReadArgsV2
|
func ReadArgsV2(r tchannel.ArgReadable) ([]byte, []byte, error) {
var arg2, arg3 []byte
if err := tchannel.NewArgReader(r.Arg2Reader()).Read(&arg2); err != nil {
return nil, nil, err
}
if err := tchannel.NewArgReader(r.Arg3Reader()).Read(&arg3); err != nil {
return nil, nil, err
}
return arg2, arg3, nil
}
|
go
|
func ReadArgsV2(r tchannel.ArgReadable) ([]byte, []byte, error) {
var arg2, arg3 []byte
if err := tchannel.NewArgReader(r.Arg2Reader()).Read(&arg2); err != nil {
return nil, nil, err
}
if err := tchannel.NewArgReader(r.Arg3Reader()).Read(&arg3); err != nil {
return nil, nil, err
}
return arg2, arg3, nil
}
|
[
"func",
"ReadArgsV2",
"(",
"r",
"tchannel",
".",
"ArgReadable",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"arg2",
",",
"arg3",
"[",
"]",
"byte",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgReader",
"(",
"r",
".",
"Arg2Reader",
"(",
")",
")",
".",
"Read",
"(",
"&",
"arg2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgReader",
"(",
"r",
".",
"Arg3Reader",
"(",
")",
")",
".",
"Read",
"(",
"&",
"arg3",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"arg2",
",",
"arg3",
",",
"nil",
"\n",
"}"
] |
// ReadArgsV2 reads arg2 and arg3 from a reader.
|
[
"ReadArgsV2",
"reads",
"arg2",
"and",
"arg3",
"from",
"a",
"reader",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/call.go#L35-L47
|
test
|
uber/tchannel-go
|
raw/call.go
|
WriteArgs
|
func WriteArgs(call *tchannel.OutboundCall, arg2, arg3 []byte) ([]byte, []byte, *tchannel.OutboundCallResponse, error) {
if err := tchannel.NewArgWriter(call.Arg2Writer()).Write(arg2); err != nil {
return nil, nil, nil, err
}
if err := tchannel.NewArgWriter(call.Arg3Writer()).Write(arg3); err != nil {
return nil, nil, nil, err
}
resp := call.Response()
var respArg2 []byte
if err := tchannel.NewArgReader(resp.Arg2Reader()).Read(&respArg2); err != nil {
return nil, nil, nil, err
}
var respArg3 []byte
if err := tchannel.NewArgReader(resp.Arg3Reader()).Read(&respArg3); err != nil {
return nil, nil, nil, err
}
return respArg2, respArg3, resp, nil
}
|
go
|
func WriteArgs(call *tchannel.OutboundCall, arg2, arg3 []byte) ([]byte, []byte, *tchannel.OutboundCallResponse, error) {
if err := tchannel.NewArgWriter(call.Arg2Writer()).Write(arg2); err != nil {
return nil, nil, nil, err
}
if err := tchannel.NewArgWriter(call.Arg3Writer()).Write(arg3); err != nil {
return nil, nil, nil, err
}
resp := call.Response()
var respArg2 []byte
if err := tchannel.NewArgReader(resp.Arg2Reader()).Read(&respArg2); err != nil {
return nil, nil, nil, err
}
var respArg3 []byte
if err := tchannel.NewArgReader(resp.Arg3Reader()).Read(&respArg3); err != nil {
return nil, nil, nil, err
}
return respArg2, respArg3, resp, nil
}
|
[
"func",
"WriteArgs",
"(",
"call",
"*",
"tchannel",
".",
"OutboundCall",
",",
"arg2",
",",
"arg3",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"*",
"tchannel",
".",
"OutboundCallResponse",
",",
"error",
")",
"{",
"if",
"err",
":=",
"tchannel",
".",
"NewArgWriter",
"(",
"call",
".",
"Arg2Writer",
"(",
")",
")",
".",
"Write",
"(",
"arg2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgWriter",
"(",
"call",
".",
"Arg3Writer",
"(",
")",
")",
".",
"Write",
"(",
"arg3",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"resp",
":=",
"call",
".",
"Response",
"(",
")",
"\n",
"var",
"respArg2",
"[",
"]",
"byte",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgReader",
"(",
"resp",
".",
"Arg2Reader",
"(",
")",
")",
".",
"Read",
"(",
"&",
"respArg2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"respArg3",
"[",
"]",
"byte",
"\n",
"if",
"err",
":=",
"tchannel",
".",
"NewArgReader",
"(",
"resp",
".",
"Arg3Reader",
"(",
")",
")",
".",
"Read",
"(",
"&",
"respArg3",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"respArg2",
",",
"respArg3",
",",
"resp",
",",
"nil",
"\n",
"}"
] |
// WriteArgs writes the given arguments to the call, and returns the response args.
|
[
"WriteArgs",
"writes",
"the",
"given",
"arguments",
"to",
"the",
"call",
"and",
"returns",
"the",
"response",
"args",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/call.go#L50-L71
|
test
|
uber/tchannel-go
|
raw/call.go
|
Call
|
func Call(ctx context.Context, ch *tchannel.Channel, hostPort string, serviceName, method string,
arg2, arg3 []byte) ([]byte, []byte, *tchannel.OutboundCallResponse, error) {
call, err := ch.BeginCall(ctx, hostPort, serviceName, method, nil)
if err != nil {
return nil, nil, nil, err
}
return WriteArgs(call, arg2, arg3)
}
|
go
|
func Call(ctx context.Context, ch *tchannel.Channel, hostPort string, serviceName, method string,
arg2, arg3 []byte) ([]byte, []byte, *tchannel.OutboundCallResponse, error) {
call, err := ch.BeginCall(ctx, hostPort, serviceName, method, nil)
if err != nil {
return nil, nil, nil, err
}
return WriteArgs(call, arg2, arg3)
}
|
[
"func",
"Call",
"(",
"ctx",
"context",
".",
"Context",
",",
"ch",
"*",
"tchannel",
".",
"Channel",
",",
"hostPort",
"string",
",",
"serviceName",
",",
"method",
"string",
",",
"arg2",
",",
"arg3",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"*",
"tchannel",
".",
"OutboundCallResponse",
",",
"error",
")",
"{",
"call",
",",
"err",
":=",
"ch",
".",
"BeginCall",
"(",
"ctx",
",",
"hostPort",
",",
"serviceName",
",",
"method",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"WriteArgs",
"(",
"call",
",",
"arg2",
",",
"arg3",
")",
"\n",
"}"
] |
// Call makes a call to the given hostPort with the given arguments and returns the response args.
|
[
"Call",
"makes",
"a",
"call",
"to",
"the",
"given",
"hostPort",
"with",
"the",
"given",
"arguments",
"and",
"returns",
"the",
"response",
"args",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/call.go#L74-L83
|
test
|
uber/tchannel-go
|
raw/call.go
|
CallSC
|
func CallSC(ctx context.Context, sc *tchannel.SubChannel, method string, arg2, arg3 []byte) (
[]byte, []byte, *tchannel.OutboundCallResponse, error) {
call, err := sc.BeginCall(ctx, method, nil)
if err != nil {
return nil, nil, nil, err
}
return WriteArgs(call, arg2, arg3)
}
|
go
|
func CallSC(ctx context.Context, sc *tchannel.SubChannel, method string, arg2, arg3 []byte) (
[]byte, []byte, *tchannel.OutboundCallResponse, error) {
call, err := sc.BeginCall(ctx, method, nil)
if err != nil {
return nil, nil, nil, err
}
return WriteArgs(call, arg2, arg3)
}
|
[
"func",
"CallSC",
"(",
"ctx",
"context",
".",
"Context",
",",
"sc",
"*",
"tchannel",
".",
"SubChannel",
",",
"method",
"string",
",",
"arg2",
",",
"arg3",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"*",
"tchannel",
".",
"OutboundCallResponse",
",",
"error",
")",
"{",
"call",
",",
"err",
":=",
"sc",
".",
"BeginCall",
"(",
"ctx",
",",
"method",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"WriteArgs",
"(",
"call",
",",
"arg2",
",",
"arg3",
")",
"\n",
"}"
] |
// CallSC makes a call using the given subcahnnel
|
[
"CallSC",
"makes",
"a",
"call",
"using",
"the",
"given",
"subcahnnel"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/call.go#L86-L95
|
test
|
uber/tchannel-go
|
raw/call.go
|
CallV2
|
func CallV2(ctx context.Context, sc *tchannel.SubChannel, cArgs CArgs) (*CRes, error) {
call, err := sc.BeginCall(ctx, cArgs.Method, cArgs.CallOptions)
if err != nil {
return nil, err
}
arg2, arg3, res, err := WriteArgs(call, cArgs.Arg2, cArgs.Arg3)
if err != nil {
return nil, err
}
return &CRes{
Arg2: arg2,
Arg3: arg3,
AppError: res.ApplicationError(),
}, nil
}
|
go
|
func CallV2(ctx context.Context, sc *tchannel.SubChannel, cArgs CArgs) (*CRes, error) {
call, err := sc.BeginCall(ctx, cArgs.Method, cArgs.CallOptions)
if err != nil {
return nil, err
}
arg2, arg3, res, err := WriteArgs(call, cArgs.Arg2, cArgs.Arg3)
if err != nil {
return nil, err
}
return &CRes{
Arg2: arg2,
Arg3: arg3,
AppError: res.ApplicationError(),
}, nil
}
|
[
"func",
"CallV2",
"(",
"ctx",
"context",
".",
"Context",
",",
"sc",
"*",
"tchannel",
".",
"SubChannel",
",",
"cArgs",
"CArgs",
")",
"(",
"*",
"CRes",
",",
"error",
")",
"{",
"call",
",",
"err",
":=",
"sc",
".",
"BeginCall",
"(",
"ctx",
",",
"cArgs",
".",
"Method",
",",
"cArgs",
".",
"CallOptions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"arg2",
",",
"arg3",
",",
"res",
",",
"err",
":=",
"WriteArgs",
"(",
"call",
",",
"cArgs",
".",
"Arg2",
",",
"cArgs",
".",
"Arg3",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"CRes",
"{",
"Arg2",
":",
"arg2",
",",
"Arg3",
":",
"arg3",
",",
"AppError",
":",
"res",
".",
"ApplicationError",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// CallV2 makes a call and does not attempt any retries.
|
[
"CallV2",
"makes",
"a",
"call",
"and",
"does",
"not",
"attempt",
"any",
"retries",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/raw/call.go#L113-L129
|
test
|
uber/tchannel-go
|
benchmark/real_relay.go
|
NewRealRelay
|
func NewRealRelay(services map[string][]string) (Relay, error) {
hosts := &fixedHosts{hosts: services}
ch, err := tchannel.NewChannel("relay", &tchannel.ChannelOptions{
RelayHost: relaytest.HostFunc(hosts.Get),
Logger: tchannel.NewLevelLogger(tchannel.NewLogger(os.Stderr), tchannel.LogLevelWarn),
})
if err != nil {
return nil, err
}
if err := ch.ListenAndServe("127.0.0.1:0"); err != nil {
return nil, err
}
return &realRelay{
ch: ch,
hosts: hosts,
}, nil
}
|
go
|
func NewRealRelay(services map[string][]string) (Relay, error) {
hosts := &fixedHosts{hosts: services}
ch, err := tchannel.NewChannel("relay", &tchannel.ChannelOptions{
RelayHost: relaytest.HostFunc(hosts.Get),
Logger: tchannel.NewLevelLogger(tchannel.NewLogger(os.Stderr), tchannel.LogLevelWarn),
})
if err != nil {
return nil, err
}
if err := ch.ListenAndServe("127.0.0.1:0"); err != nil {
return nil, err
}
return &realRelay{
ch: ch,
hosts: hosts,
}, nil
}
|
[
"func",
"NewRealRelay",
"(",
"services",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"(",
"Relay",
",",
"error",
")",
"{",
"hosts",
":=",
"&",
"fixedHosts",
"{",
"hosts",
":",
"services",
"}",
"\n",
"ch",
",",
"err",
":=",
"tchannel",
".",
"NewChannel",
"(",
"\"relay\"",
",",
"&",
"tchannel",
".",
"ChannelOptions",
"{",
"RelayHost",
":",
"relaytest",
".",
"HostFunc",
"(",
"hosts",
".",
"Get",
")",
",",
"Logger",
":",
"tchannel",
".",
"NewLevelLogger",
"(",
"tchannel",
".",
"NewLogger",
"(",
"os",
".",
"Stderr",
")",
",",
"tchannel",
".",
"LogLevelWarn",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ch",
".",
"ListenAndServe",
"(",
"\"127.0.0.1:0\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"realRelay",
"{",
"ch",
":",
"ch",
",",
"hosts",
":",
"hosts",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewRealRelay creates a TChannel relay.
|
[
"NewRealRelay",
"creates",
"a",
"TChannel",
"relay",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/real_relay.go#L55-L73
|
test
|
uber/tchannel-go
|
thrift/server.go
|
NewServer
|
func NewServer(registrar tchannel.Registrar) *Server {
metaHandler := newMetaHandler()
server := &Server{
ch: registrar,
log: registrar.Logger(),
handlers: make(map[string]handler),
metaHandler: metaHandler,
ctxFn: defaultContextFn,
}
server.Register(newTChanMetaServer(metaHandler))
if ch, ok := registrar.(*tchannel.Channel); ok {
// Register the meta endpoints on the "tchannel" service name.
NewServer(ch.GetSubChannel("tchannel"))
}
return server
}
|
go
|
func NewServer(registrar tchannel.Registrar) *Server {
metaHandler := newMetaHandler()
server := &Server{
ch: registrar,
log: registrar.Logger(),
handlers: make(map[string]handler),
metaHandler: metaHandler,
ctxFn: defaultContextFn,
}
server.Register(newTChanMetaServer(metaHandler))
if ch, ok := registrar.(*tchannel.Channel); ok {
// Register the meta endpoints on the "tchannel" service name.
NewServer(ch.GetSubChannel("tchannel"))
}
return server
}
|
[
"func",
"NewServer",
"(",
"registrar",
"tchannel",
".",
"Registrar",
")",
"*",
"Server",
"{",
"metaHandler",
":=",
"newMetaHandler",
"(",
")",
"\n",
"server",
":=",
"&",
"Server",
"{",
"ch",
":",
"registrar",
",",
"log",
":",
"registrar",
".",
"Logger",
"(",
")",
",",
"handlers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"handler",
")",
",",
"metaHandler",
":",
"metaHandler",
",",
"ctxFn",
":",
"defaultContextFn",
",",
"}",
"\n",
"server",
".",
"Register",
"(",
"newTChanMetaServer",
"(",
"metaHandler",
")",
")",
"\n",
"if",
"ch",
",",
"ok",
":=",
"registrar",
".",
"(",
"*",
"tchannel",
".",
"Channel",
")",
";",
"ok",
"{",
"NewServer",
"(",
"ch",
".",
"GetSubChannel",
"(",
"\"tchannel\"",
")",
")",
"\n",
"}",
"\n",
"return",
"server",
"\n",
"}"
] |
// NewServer returns a server that can serve thrift services over TChannel.
|
[
"NewServer",
"returns",
"a",
"server",
"that",
"can",
"serve",
"thrift",
"services",
"over",
"TChannel",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/server.go#L51-L66
|
test
|
uber/tchannel-go
|
thrift/server.go
|
RegisterHealthHandler
|
func (s *Server) RegisterHealthHandler(f HealthFunc) {
wrapped := func(ctx Context, r HealthRequest) (bool, string) {
return f(ctx)
}
s.metaHandler.setHandler(wrapped)
}
|
go
|
func (s *Server) RegisterHealthHandler(f HealthFunc) {
wrapped := func(ctx Context, r HealthRequest) (bool, string) {
return f(ctx)
}
s.metaHandler.setHandler(wrapped)
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"RegisterHealthHandler",
"(",
"f",
"HealthFunc",
")",
"{",
"wrapped",
":=",
"func",
"(",
"ctx",
"Context",
",",
"r",
"HealthRequest",
")",
"(",
"bool",
",",
"string",
")",
"{",
"return",
"f",
"(",
"ctx",
")",
"\n",
"}",
"\n",
"s",
".",
"metaHandler",
".",
"setHandler",
"(",
"wrapped",
")",
"\n",
"}"
] |
// RegisterHealthHandler uses the user-specified function f for the Health endpoint.
|
[
"RegisterHealthHandler",
"uses",
"the",
"user",
"-",
"specified",
"function",
"f",
"for",
"the",
"Health",
"endpoint",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/server.go#L87-L92
|
test
|
uber/tchannel-go
|
thrift/server.go
|
Handle
|
func (s *Server) Handle(ctx context.Context, call *tchannel.InboundCall) {
op := call.MethodString()
service, method, ok := getServiceMethod(op)
if !ok {
log.Fatalf("Handle got call for %s which does not match the expected call format", op)
}
s.RLock()
handler, ok := s.handlers[service]
s.RUnlock()
if !ok {
log.Fatalf("Handle got call for service %v which is not registered", service)
}
if err := s.handle(ctx, handler, method, call); err != nil {
s.onError(call, err)
}
}
|
go
|
func (s *Server) Handle(ctx context.Context, call *tchannel.InboundCall) {
op := call.MethodString()
service, method, ok := getServiceMethod(op)
if !ok {
log.Fatalf("Handle got call for %s which does not match the expected call format", op)
}
s.RLock()
handler, ok := s.handlers[service]
s.RUnlock()
if !ok {
log.Fatalf("Handle got call for service %v which is not registered", service)
}
if err := s.handle(ctx, handler, method, call); err != nil {
s.onError(call, err)
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"Handle",
"(",
"ctx",
"context",
".",
"Context",
",",
"call",
"*",
"tchannel",
".",
"InboundCall",
")",
"{",
"op",
":=",
"call",
".",
"MethodString",
"(",
")",
"\n",
"service",
",",
"method",
",",
"ok",
":=",
"getServiceMethod",
"(",
"op",
")",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"Handle got call for %s which does not match the expected call format\"",
",",
"op",
")",
"\n",
"}",
"\n",
"s",
".",
"RLock",
"(",
")",
"\n",
"handler",
",",
"ok",
":=",
"s",
".",
"handlers",
"[",
"service",
"]",
"\n",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"Handle got call for service %v which is not registered\"",
",",
"service",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"handle",
"(",
"ctx",
",",
"handler",
",",
"method",
",",
"call",
")",
";",
"err",
"!=",
"nil",
"{",
"s",
".",
"onError",
"(",
"call",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// Handle handles an incoming TChannel call and forwards it to the correct handler.
|
[
"Handle",
"handles",
"an",
"incoming",
"TChannel",
"call",
"and",
"forwards",
"it",
"to",
"the",
"correct",
"handler",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/server.go#L223-L240
|
test
|
uber/tchannel-go
|
errors.go
|
MetricsKey
|
func (c SystemErrCode) MetricsKey() string {
switch c {
case ErrCodeInvalid:
// Shouldn't ever need this.
return "invalid"
case ErrCodeTimeout:
return "timeout"
case ErrCodeCancelled:
return "cancelled"
case ErrCodeBusy:
return "busy"
case ErrCodeDeclined:
return "declined"
case ErrCodeUnexpected:
return "unexpected-error"
case ErrCodeBadRequest:
return "bad-request"
case ErrCodeNetwork:
return "network-error"
case ErrCodeProtocol:
return "protocol-error"
default:
return c.String()
}
}
|
go
|
func (c SystemErrCode) MetricsKey() string {
switch c {
case ErrCodeInvalid:
// Shouldn't ever need this.
return "invalid"
case ErrCodeTimeout:
return "timeout"
case ErrCodeCancelled:
return "cancelled"
case ErrCodeBusy:
return "busy"
case ErrCodeDeclined:
return "declined"
case ErrCodeUnexpected:
return "unexpected-error"
case ErrCodeBadRequest:
return "bad-request"
case ErrCodeNetwork:
return "network-error"
case ErrCodeProtocol:
return "protocol-error"
default:
return c.String()
}
}
|
[
"func",
"(",
"c",
"SystemErrCode",
")",
"MetricsKey",
"(",
")",
"string",
"{",
"switch",
"c",
"{",
"case",
"ErrCodeInvalid",
":",
"return",
"\"invalid\"",
"\n",
"case",
"ErrCodeTimeout",
":",
"return",
"\"timeout\"",
"\n",
"case",
"ErrCodeCancelled",
":",
"return",
"\"cancelled\"",
"\n",
"case",
"ErrCodeBusy",
":",
"return",
"\"busy\"",
"\n",
"case",
"ErrCodeDeclined",
":",
"return",
"\"declined\"",
"\n",
"case",
"ErrCodeUnexpected",
":",
"return",
"\"unexpected-error\"",
"\n",
"case",
"ErrCodeBadRequest",
":",
"return",
"\"bad-request\"",
"\n",
"case",
"ErrCodeNetwork",
":",
"return",
"\"network-error\"",
"\n",
"case",
"ErrCodeProtocol",
":",
"return",
"\"protocol-error\"",
"\n",
"default",
":",
"return",
"c",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// MetricsKey is a string representation of the error code that's suitable for
// inclusion in metrics tags.
|
[
"MetricsKey",
"is",
"a",
"string",
"representation",
"of",
"the",
"error",
"code",
"that",
"s",
"suitable",
"for",
"inclusion",
"in",
"metrics",
"tags",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L102-L126
|
test
|
uber/tchannel-go
|
errors.go
|
NewSystemError
|
func NewSystemError(code SystemErrCode, msg string, args ...interface{}) error {
return SystemError{code: code, msg: fmt.Sprintf(msg, args...)}
}
|
go
|
func NewSystemError(code SystemErrCode, msg string, args ...interface{}) error {
return SystemError{code: code, msg: fmt.Sprintf(msg, args...)}
}
|
[
"func",
"NewSystemError",
"(",
"code",
"SystemErrCode",
",",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"SystemError",
"{",
"code",
":",
"code",
",",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"args",
"...",
")",
"}",
"\n",
"}"
] |
// NewSystemError defines a new SystemError with a code and message
|
[
"NewSystemError",
"defines",
"a",
"new",
"SystemError",
"with",
"a",
"code",
"and",
"message"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L163-L165
|
test
|
uber/tchannel-go
|
errors.go
|
NewWrappedSystemError
|
func NewWrappedSystemError(code SystemErrCode, wrapped error) error {
if se, ok := wrapped.(SystemError); ok {
return se
}
return SystemError{code: code, msg: fmt.Sprint(wrapped), wrapped: wrapped}
}
|
go
|
func NewWrappedSystemError(code SystemErrCode, wrapped error) error {
if se, ok := wrapped.(SystemError); ok {
return se
}
return SystemError{code: code, msg: fmt.Sprint(wrapped), wrapped: wrapped}
}
|
[
"func",
"NewWrappedSystemError",
"(",
"code",
"SystemErrCode",
",",
"wrapped",
"error",
")",
"error",
"{",
"if",
"se",
",",
"ok",
":=",
"wrapped",
".",
"(",
"SystemError",
")",
";",
"ok",
"{",
"return",
"se",
"\n",
"}",
"\n",
"return",
"SystemError",
"{",
"code",
":",
"code",
",",
"msg",
":",
"fmt",
".",
"Sprint",
"(",
"wrapped",
")",
",",
"wrapped",
":",
"wrapped",
"}",
"\n",
"}"
] |
// NewWrappedSystemError defines a new SystemError wrapping an existing error
|
[
"NewWrappedSystemError",
"defines",
"a",
"new",
"SystemError",
"wrapping",
"an",
"existing",
"error"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L168-L174
|
test
|
uber/tchannel-go
|
errors.go
|
Error
|
func (se SystemError) Error() string {
return fmt.Sprintf("tchannel error %v: %s", se.Code(), se.msg)
}
|
go
|
func (se SystemError) Error() string {
return fmt.Sprintf("tchannel error %v: %s", se.Code(), se.msg)
}
|
[
"func",
"(",
"se",
"SystemError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"tchannel error %v: %s\"",
",",
"se",
".",
"Code",
"(",
")",
",",
"se",
".",
"msg",
")",
"\n",
"}"
] |
// Error returns the code and message, conforming to the error interface
|
[
"Error",
"returns",
"the",
"code",
"and",
"message",
"conforming",
"to",
"the",
"error",
"interface"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L177-L179
|
test
|
uber/tchannel-go
|
errors.go
|
GetContextError
|
func GetContextError(err error) error {
if err == context.DeadlineExceeded {
return ErrTimeout
}
if err == context.Canceled {
return ErrRequestCancelled
}
return err
}
|
go
|
func GetContextError(err error) error {
if err == context.DeadlineExceeded {
return ErrTimeout
}
if err == context.Canceled {
return ErrRequestCancelled
}
return err
}
|
[
"func",
"GetContextError",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"==",
"context",
".",
"DeadlineExceeded",
"{",
"return",
"ErrTimeout",
"\n",
"}",
"\n",
"if",
"err",
"==",
"context",
".",
"Canceled",
"{",
"return",
"ErrRequestCancelled",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// GetContextError converts the context error to a tchannel error.
|
[
"GetContextError",
"converts",
"the",
"context",
"error",
"to",
"a",
"tchannel",
"error",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L195-L203
|
test
|
uber/tchannel-go
|
errors.go
|
GetSystemErrorCode
|
func GetSystemErrorCode(err error) SystemErrCode {
if err == nil {
return ErrCodeInvalid
}
if se, ok := err.(SystemError); ok {
return se.Code()
}
return ErrCodeUnexpected
}
|
go
|
func GetSystemErrorCode(err error) SystemErrCode {
if err == nil {
return ErrCodeInvalid
}
if se, ok := err.(SystemError); ok {
return se.Code()
}
return ErrCodeUnexpected
}
|
[
"func",
"GetSystemErrorCode",
"(",
"err",
"error",
")",
"SystemErrCode",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"ErrCodeInvalid",
"\n",
"}",
"\n",
"if",
"se",
",",
"ok",
":=",
"err",
".",
"(",
"SystemError",
")",
";",
"ok",
"{",
"return",
"se",
".",
"Code",
"(",
")",
"\n",
"}",
"\n",
"return",
"ErrCodeUnexpected",
"\n",
"}"
] |
// GetSystemErrorCode returns the code to report for the given error. If the error is a
// SystemError, we can get the code directly. Otherwise treat it as an unexpected error
|
[
"GetSystemErrorCode",
"returns",
"the",
"code",
"to",
"report",
"for",
"the",
"given",
"error",
".",
"If",
"the",
"error",
"is",
"a",
"SystemError",
"we",
"can",
"get",
"the",
"code",
"directly",
".",
"Otherwise",
"treat",
"it",
"as",
"an",
"unexpected",
"error"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/errors.go#L207-L217
|
test
|
uber/tchannel-go
|
connection.go
|
ping
|
func (c *Connection) ping(ctx context.Context) error {
req := &pingReq{id: c.NextMessageID()}
mex, err := c.outbound.newExchange(ctx, c.opts.FramePool, req.messageType(), req.ID(), 1)
if err != nil {
return c.connectionError("create ping exchange", err)
}
defer c.outbound.removeExchange(req.ID())
if err := c.sendMessage(req); err != nil {
return c.connectionError("send ping", err)
}
return c.recvMessage(ctx, &pingRes{}, mex)
}
|
go
|
func (c *Connection) ping(ctx context.Context) error {
req := &pingReq{id: c.NextMessageID()}
mex, err := c.outbound.newExchange(ctx, c.opts.FramePool, req.messageType(), req.ID(), 1)
if err != nil {
return c.connectionError("create ping exchange", err)
}
defer c.outbound.removeExchange(req.ID())
if err := c.sendMessage(req); err != nil {
return c.connectionError("send ping", err)
}
return c.recvMessage(ctx, &pingRes{}, mex)
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"ping",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"req",
":=",
"&",
"pingReq",
"{",
"id",
":",
"c",
".",
"NextMessageID",
"(",
")",
"}",
"\n",
"mex",
",",
"err",
":=",
"c",
".",
"outbound",
".",
"newExchange",
"(",
"ctx",
",",
"c",
".",
"opts",
".",
"FramePool",
",",
"req",
".",
"messageType",
"(",
")",
",",
"req",
".",
"ID",
"(",
")",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"connectionError",
"(",
"\"create ping exchange\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"c",
".",
"outbound",
".",
"removeExchange",
"(",
"req",
".",
"ID",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"sendMessage",
"(",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"connectionError",
"(",
"\"send ping\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"recvMessage",
"(",
"ctx",
",",
"&",
"pingRes",
"{",
"}",
",",
"mex",
")",
"\n",
"}"
] |
// ping sends a ping message and waits for a ping response.
|
[
"ping",
"sends",
"a",
"ping",
"message",
"and",
"waits",
"for",
"a",
"ping",
"response",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L390-L403
|
test
|
uber/tchannel-go
|
connection.go
|
handlePingRes
|
func (c *Connection) handlePingRes(frame *Frame) bool {
if err := c.outbound.forwardPeerFrame(frame); err != nil {
c.log.WithFields(LogField{"response", frame.Header}).Warn("Unexpected ping response.")
return true
}
// ping req is waiting for this frame, and will release it.
return false
}
|
go
|
func (c *Connection) handlePingRes(frame *Frame) bool {
if err := c.outbound.forwardPeerFrame(frame); err != nil {
c.log.WithFields(LogField{"response", frame.Header}).Warn("Unexpected ping response.")
return true
}
// ping req is waiting for this frame, and will release it.
return false
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"handlePingRes",
"(",
"frame",
"*",
"Frame",
")",
"bool",
"{",
"if",
"err",
":=",
"c",
".",
"outbound",
".",
"forwardPeerFrame",
"(",
"frame",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"response\"",
",",
"frame",
".",
"Header",
"}",
")",
".",
"Warn",
"(",
"\"Unexpected ping response.\"",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// handlePingRes calls registered ping handlers.
|
[
"handlePingRes",
"calls",
"registered",
"ping",
"handlers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L406-L413
|
test
|
uber/tchannel-go
|
connection.go
|
handlePingReq
|
func (c *Connection) handlePingReq(frame *Frame) {
if state := c.readState(); state != connectionActive {
c.protocolError(frame.Header.ID, errConnNotActive{"ping on incoming", state})
return
}
pingRes := &pingRes{id: frame.Header.ID}
if err := c.sendMessage(pingRes); err != nil {
c.connectionError("send pong", err)
}
}
|
go
|
func (c *Connection) handlePingReq(frame *Frame) {
if state := c.readState(); state != connectionActive {
c.protocolError(frame.Header.ID, errConnNotActive{"ping on incoming", state})
return
}
pingRes := &pingRes{id: frame.Header.ID}
if err := c.sendMessage(pingRes); err != nil {
c.connectionError("send pong", err)
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"handlePingReq",
"(",
"frame",
"*",
"Frame",
")",
"{",
"if",
"state",
":=",
"c",
".",
"readState",
"(",
")",
";",
"state",
"!=",
"connectionActive",
"{",
"c",
".",
"protocolError",
"(",
"frame",
".",
"Header",
".",
"ID",
",",
"errConnNotActive",
"{",
"\"ping on incoming\"",
",",
"state",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n",
"pingRes",
":=",
"&",
"pingRes",
"{",
"id",
":",
"frame",
".",
"Header",
".",
"ID",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"sendMessage",
"(",
"pingRes",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"connectionError",
"(",
"\"send pong\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// handlePingReq responds to the pingReq message with a pingRes.
|
[
"handlePingReq",
"responds",
"to",
"the",
"pingReq",
"message",
"with",
"a",
"pingRes",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L416-L426
|
test
|
uber/tchannel-go
|
connection.go
|
SendSystemError
|
func (c *Connection) SendSystemError(id uint32, span Span, err error) error {
frame := c.opts.FramePool.Get()
if err := frame.write(&errorMessage{
id: id,
errCode: GetSystemErrorCode(err),
tracing: span,
message: GetSystemErrorMessage(err),
}); err != nil {
// This shouldn't happen - it means writing the errorMessage is broken.
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
ErrField(err),
).Warn("Couldn't create outbound frame.")
return fmt.Errorf("failed to create outbound error frame: %v", err)
}
// When sending errors, we hold the state rlock to ensure that sendCh is not closed
// as we are sending the frame.
return c.withStateRLock(func() error {
// Errors cannot be sent if the connection has been closed.
if c.state == connectionClosed {
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
).Info("Could not send error frame on closed connection.")
return fmt.Errorf("failed to send error frame, connection state %v", c.state)
}
select {
case c.sendCh <- frame: // Good to go
return nil
default: // If the send buffer is full, log and return an error.
}
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
ErrField(err),
).Warn("Couldn't send outbound frame.")
return fmt.Errorf("failed to send error frame, buffer full")
})
}
|
go
|
func (c *Connection) SendSystemError(id uint32, span Span, err error) error {
frame := c.opts.FramePool.Get()
if err := frame.write(&errorMessage{
id: id,
errCode: GetSystemErrorCode(err),
tracing: span,
message: GetSystemErrorMessage(err),
}); err != nil {
// This shouldn't happen - it means writing the errorMessage is broken.
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
ErrField(err),
).Warn("Couldn't create outbound frame.")
return fmt.Errorf("failed to create outbound error frame: %v", err)
}
// When sending errors, we hold the state rlock to ensure that sendCh is not closed
// as we are sending the frame.
return c.withStateRLock(func() error {
// Errors cannot be sent if the connection has been closed.
if c.state == connectionClosed {
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
).Info("Could not send error frame on closed connection.")
return fmt.Errorf("failed to send error frame, connection state %v", c.state)
}
select {
case c.sendCh <- frame: // Good to go
return nil
default: // If the send buffer is full, log and return an error.
}
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
LogField{"id", id},
ErrField(err),
).Warn("Couldn't send outbound frame.")
return fmt.Errorf("failed to send error frame, buffer full")
})
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"SendSystemError",
"(",
"id",
"uint32",
",",
"span",
"Span",
",",
"err",
"error",
")",
"error",
"{",
"frame",
":=",
"c",
".",
"opts",
".",
"FramePool",
".",
"Get",
"(",
")",
"\n",
"if",
"err",
":=",
"frame",
".",
"write",
"(",
"&",
"errorMessage",
"{",
"id",
":",
"id",
",",
"errCode",
":",
"GetSystemErrorCode",
"(",
"err",
")",
",",
"tracing",
":",
"span",
",",
"message",
":",
"GetSystemErrorMessage",
"(",
"err",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"remotePeer\"",
",",
"c",
".",
"remotePeerInfo",
"}",
",",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
")",
".",
"Warn",
"(",
"\"Couldn't create outbound frame.\"",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to create outbound error frame: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"withStateRLock",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"c",
".",
"state",
"==",
"connectionClosed",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"remotePeer\"",
",",
"c",
".",
"remotePeerInfo",
"}",
",",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
",",
")",
".",
"Info",
"(",
"\"Could not send error frame on closed connection.\"",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to send error frame, connection state %v\"",
",",
"c",
".",
"state",
")",
"\n",
"}",
"\n",
"select",
"{",
"case",
"c",
".",
"sendCh",
"<-",
"frame",
":",
"return",
"nil",
"\n",
"default",
":",
"}",
"\n",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"remotePeer\"",
",",
"c",
".",
"remotePeerInfo",
"}",
",",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
")",
".",
"Warn",
"(",
"\"Couldn't send outbound frame.\"",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to send error frame, buffer full\"",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// SendSystemError sends an error frame for the given system error.
|
[
"SendSystemError",
"sends",
"an",
"error",
"frame",
"for",
"the",
"given",
"system",
"error",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L471-L514
|
test
|
uber/tchannel-go
|
connection.go
|
connectionError
|
func (c *Connection) connectionError(site string, err error) error {
var closeLogFields LogFields
if err == io.EOF {
closeLogFields = LogFields{{"reason", "network connection EOF"}}
} else {
closeLogFields = LogFields{
{"reason", "connection error"},
ErrField(err),
}
}
c.stopHealthCheck()
err = c.logConnectionError(site, err)
c.close(closeLogFields...)
// On any connection error, notify the exchanges of this error.
if c.stoppedExchanges.CAS(false, true) {
c.outbound.stopExchanges(err)
c.inbound.stopExchanges(err)
}
// checkExchanges will close the connection due to stoppedExchanges.
c.checkExchanges()
return err
}
|
go
|
func (c *Connection) connectionError(site string, err error) error {
var closeLogFields LogFields
if err == io.EOF {
closeLogFields = LogFields{{"reason", "network connection EOF"}}
} else {
closeLogFields = LogFields{
{"reason", "connection error"},
ErrField(err),
}
}
c.stopHealthCheck()
err = c.logConnectionError(site, err)
c.close(closeLogFields...)
// On any connection error, notify the exchanges of this error.
if c.stoppedExchanges.CAS(false, true) {
c.outbound.stopExchanges(err)
c.inbound.stopExchanges(err)
}
// checkExchanges will close the connection due to stoppedExchanges.
c.checkExchanges()
return err
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"connectionError",
"(",
"site",
"string",
",",
"err",
"error",
")",
"error",
"{",
"var",
"closeLogFields",
"LogFields",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"closeLogFields",
"=",
"LogFields",
"{",
"{",
"\"reason\"",
",",
"\"network connection EOF\"",
"}",
"}",
"\n",
"}",
"else",
"{",
"closeLogFields",
"=",
"LogFields",
"{",
"{",
"\"reason\"",
",",
"\"connection error\"",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
"}",
"\n",
"}",
"\n",
"c",
".",
"stopHealthCheck",
"(",
")",
"\n",
"err",
"=",
"c",
".",
"logConnectionError",
"(",
"site",
",",
"err",
")",
"\n",
"c",
".",
"close",
"(",
"closeLogFields",
"...",
")",
"\n",
"if",
"c",
".",
"stoppedExchanges",
".",
"CAS",
"(",
"false",
",",
"true",
")",
"{",
"c",
".",
"outbound",
".",
"stopExchanges",
"(",
"err",
")",
"\n",
"c",
".",
"inbound",
".",
"stopExchanges",
"(",
"err",
")",
"\n",
"}",
"\n",
"c",
".",
"checkExchanges",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// connectionError handles a connection level error
|
[
"connectionError",
"handles",
"a",
"connection",
"level",
"error"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L539-L563
|
test
|
uber/tchannel-go
|
connection.go
|
withStateLock
|
func (c *Connection) withStateLock(f func() error) error {
c.stateMut.Lock()
err := f()
c.stateMut.Unlock()
return err
}
|
go
|
func (c *Connection) withStateLock(f func() error) error {
c.stateMut.Lock()
err := f()
c.stateMut.Unlock()
return err
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"withStateLock",
"(",
"f",
"func",
"(",
")",
"error",
")",
"error",
"{",
"c",
".",
"stateMut",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"f",
"(",
")",
"\n",
"c",
".",
"stateMut",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// withStateLock performs an action with the connection state mutex locked
|
[
"withStateLock",
"performs",
"an",
"action",
"with",
"the",
"connection",
"state",
"mutex",
"locked"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L584-L590
|
test
|
uber/tchannel-go
|
connection.go
|
withStateRLock
|
func (c *Connection) withStateRLock(f func() error) error {
c.stateMut.RLock()
err := f()
c.stateMut.RUnlock()
return err
}
|
go
|
func (c *Connection) withStateRLock(f func() error) error {
c.stateMut.RLock()
err := f()
c.stateMut.RUnlock()
return err
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"withStateRLock",
"(",
"f",
"func",
"(",
")",
"error",
")",
"error",
"{",
"c",
".",
"stateMut",
".",
"RLock",
"(",
")",
"\n",
"err",
":=",
"f",
"(",
")",
"\n",
"c",
".",
"stateMut",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// withStateRLock performs an action with the connection state mutex rlocked.
|
[
"withStateRLock",
"performs",
"an",
"action",
"with",
"the",
"connection",
"state",
"mutex",
"rlocked",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L593-L599
|
test
|
uber/tchannel-go
|
connection.go
|
readFrames
|
func (c *Connection) readFrames(_ uint32) {
headerBuf := make([]byte, FrameHeaderSize)
handleErr := func(err error) {
if !c.closeNetworkCalled.Load() {
c.connectionError("read frames", err)
} else {
c.log.Debugf("Ignoring error after connection was closed: %v", err)
}
}
for {
// Read the header, avoid allocating the frame till we know the size
// we need to allocate.
if _, err := io.ReadFull(c.conn, headerBuf); err != nil {
handleErr(err)
return
}
frame := c.opts.FramePool.Get()
if err := frame.ReadBody(headerBuf, c.conn); err != nil {
handleErr(err)
c.opts.FramePool.Release(frame)
return
}
c.updateLastActivity(frame)
var releaseFrame bool
if c.relay == nil {
releaseFrame = c.handleFrameNoRelay(frame)
} else {
releaseFrame = c.handleFrameRelay(frame)
}
if releaseFrame {
c.opts.FramePool.Release(frame)
}
}
}
|
go
|
func (c *Connection) readFrames(_ uint32) {
headerBuf := make([]byte, FrameHeaderSize)
handleErr := func(err error) {
if !c.closeNetworkCalled.Load() {
c.connectionError("read frames", err)
} else {
c.log.Debugf("Ignoring error after connection was closed: %v", err)
}
}
for {
// Read the header, avoid allocating the frame till we know the size
// we need to allocate.
if _, err := io.ReadFull(c.conn, headerBuf); err != nil {
handleErr(err)
return
}
frame := c.opts.FramePool.Get()
if err := frame.ReadBody(headerBuf, c.conn); err != nil {
handleErr(err)
c.opts.FramePool.Release(frame)
return
}
c.updateLastActivity(frame)
var releaseFrame bool
if c.relay == nil {
releaseFrame = c.handleFrameNoRelay(frame)
} else {
releaseFrame = c.handleFrameRelay(frame)
}
if releaseFrame {
c.opts.FramePool.Release(frame)
}
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"readFrames",
"(",
"_",
"uint32",
")",
"{",
"headerBuf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"FrameHeaderSize",
")",
"\n",
"handleErr",
":=",
"func",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"c",
".",
"closeNetworkCalled",
".",
"Load",
"(",
")",
"{",
"c",
".",
"connectionError",
"(",
"\"read frames\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"log",
".",
"Debugf",
"(",
"\"Ignoring error after connection was closed: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"{",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"c",
".",
"conn",
",",
"headerBuf",
")",
";",
"err",
"!=",
"nil",
"{",
"handleErr",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"frame",
":=",
"c",
".",
"opts",
".",
"FramePool",
".",
"Get",
"(",
")",
"\n",
"if",
"err",
":=",
"frame",
".",
"ReadBody",
"(",
"headerBuf",
",",
"c",
".",
"conn",
")",
";",
"err",
"!=",
"nil",
"{",
"handleErr",
"(",
"err",
")",
"\n",
"c",
".",
"opts",
".",
"FramePool",
".",
"Release",
"(",
"frame",
")",
"\n",
"return",
"\n",
"}",
"\n",
"c",
".",
"updateLastActivity",
"(",
"frame",
")",
"\n",
"var",
"releaseFrame",
"bool",
"\n",
"if",
"c",
".",
"relay",
"==",
"nil",
"{",
"releaseFrame",
"=",
"c",
".",
"handleFrameNoRelay",
"(",
"frame",
")",
"\n",
"}",
"else",
"{",
"releaseFrame",
"=",
"c",
".",
"handleFrameRelay",
"(",
"frame",
")",
"\n",
"}",
"\n",
"if",
"releaseFrame",
"{",
"c",
".",
"opts",
".",
"FramePool",
".",
"Release",
"(",
"frame",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// readFrames is the loop that reads frames from the network connection and
// dispatches to the appropriate handler. Run within its own goroutine to
// prevent overlapping reads on the socket. Most handlers simply send the
// incoming frame to a channel; the init handlers are a notable exception,
// since we cannot process new frames until the initialization is complete.
|
[
"readFrames",
"is",
"the",
"loop",
"that",
"reads",
"frames",
"from",
"the",
"network",
"connection",
"and",
"dispatches",
"to",
"the",
"appropriate",
"handler",
".",
"Run",
"within",
"its",
"own",
"goroutine",
"to",
"prevent",
"overlapping",
"reads",
"on",
"the",
"socket",
".",
"Most",
"handlers",
"simply",
"send",
"the",
"incoming",
"frame",
"to",
"a",
"channel",
";",
"the",
"init",
"handlers",
"are",
"a",
"notable",
"exception",
"since",
"we",
"cannot",
"process",
"new",
"frames",
"until",
"the",
"initialization",
"is",
"complete",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L613-L651
|
test
|
uber/tchannel-go
|
connection.go
|
writeFrames
|
func (c *Connection) writeFrames(_ uint32) {
for {
select {
case f := <-c.sendCh:
if c.log.Enabled(LogLevelDebug) {
c.log.Debugf("Writing frame %s", f.Header)
}
c.updateLastActivity(f)
err := f.WriteOut(c.conn)
c.opts.FramePool.Release(f)
if err != nil {
c.connectionError("write frames", err)
return
}
case <-c.stopCh:
// If there are frames in sendCh, we want to drain them.
if len(c.sendCh) > 0 {
continue
}
// Close the network once we're no longer writing frames.
c.closeNetwork()
return
}
}
}
|
go
|
func (c *Connection) writeFrames(_ uint32) {
for {
select {
case f := <-c.sendCh:
if c.log.Enabled(LogLevelDebug) {
c.log.Debugf("Writing frame %s", f.Header)
}
c.updateLastActivity(f)
err := f.WriteOut(c.conn)
c.opts.FramePool.Release(f)
if err != nil {
c.connectionError("write frames", err)
return
}
case <-c.stopCh:
// If there are frames in sendCh, we want to drain them.
if len(c.sendCh) > 0 {
continue
}
// Close the network once we're no longer writing frames.
c.closeNetwork()
return
}
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"writeFrames",
"(",
"_",
"uint32",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"f",
":=",
"<-",
"c",
".",
"sendCh",
":",
"if",
"c",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"c",
".",
"log",
".",
"Debugf",
"(",
"\"Writing frame %s\"",
",",
"f",
".",
"Header",
")",
"\n",
"}",
"\n",
"c",
".",
"updateLastActivity",
"(",
"f",
")",
"\n",
"err",
":=",
"f",
".",
"WriteOut",
"(",
"c",
".",
"conn",
")",
"\n",
"c",
".",
"opts",
".",
"FramePool",
".",
"Release",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"connectionError",
"(",
"\"write frames\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"case",
"<-",
"c",
".",
"stopCh",
":",
"if",
"len",
"(",
"c",
".",
"sendCh",
")",
">",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"c",
".",
"closeNetwork",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// writeFrames is the main loop that pulls frames from the send channel and
// writes them to the connection.
|
[
"writeFrames",
"is",
"the",
"main",
"loop",
"that",
"pulls",
"frames",
"from",
"the",
"send",
"channel",
"and",
"writes",
"them",
"to",
"the",
"connection",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L701-L726
|
test
|
uber/tchannel-go
|
connection.go
|
hasPendingCalls
|
func (c *Connection) hasPendingCalls() bool {
if c.inbound.count() > 0 || c.outbound.count() > 0 {
return true
}
if !c.relay.canClose() {
return true
}
return false
}
|
go
|
func (c *Connection) hasPendingCalls() bool {
if c.inbound.count() > 0 || c.outbound.count() > 0 {
return true
}
if !c.relay.canClose() {
return true
}
return false
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"hasPendingCalls",
"(",
")",
"bool",
"{",
"if",
"c",
".",
"inbound",
".",
"count",
"(",
")",
">",
"0",
"||",
"c",
".",
"outbound",
".",
"count",
"(",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"!",
"c",
".",
"relay",
".",
"canClose",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// hasPendingCalls returns whether there's any pending inbound or outbound calls on this connection.
|
[
"hasPendingCalls",
"returns",
"whether",
"there",
"s",
"any",
"pending",
"inbound",
"or",
"outbound",
"calls",
"on",
"this",
"connection",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L739-L748
|
test
|
uber/tchannel-go
|
connection.go
|
checkExchanges
|
func (c *Connection) checkExchanges() {
c.callOnExchangeChange()
moveState := func(fromState, toState connectionState) bool {
err := c.withStateLock(func() error {
if c.state != fromState {
return errors.New("")
}
c.state = toState
return nil
})
return err == nil
}
curState := c.readState()
origState := curState
if curState != connectionClosed && c.stoppedExchanges.Load() {
if moveState(curState, connectionClosed) {
curState = connectionClosed
}
}
if curState == connectionStartClose {
if !c.relay.canClose() {
return
}
if c.inbound.count() == 0 && moveState(connectionStartClose, connectionInboundClosed) {
curState = connectionInboundClosed
}
}
if curState == connectionInboundClosed {
// Safety check -- this should never happen since we already did the check
// when transitioning to connectionInboundClosed.
if !c.relay.canClose() {
c.relay.logger.Error("Relay can't close even though state is InboundClosed.")
return
}
if c.outbound.count() == 0 && moveState(connectionInboundClosed, connectionClosed) {
curState = connectionClosed
}
}
if curState != origState {
// If the connection is closed, we can notify writeFrames to stop which
// closes the underlying network connection. We never close sendCh to avoid
// races causing panics, see 93ef5c112c8b321367ae52d2bd79396e2e874f31
if curState == connectionClosed {
close(c.stopCh)
}
c.log.WithFields(
LogField{"newState", curState},
).Debug("Connection state updated during shutdown.")
c.callOnCloseStateChange()
}
}
|
go
|
func (c *Connection) checkExchanges() {
c.callOnExchangeChange()
moveState := func(fromState, toState connectionState) bool {
err := c.withStateLock(func() error {
if c.state != fromState {
return errors.New("")
}
c.state = toState
return nil
})
return err == nil
}
curState := c.readState()
origState := curState
if curState != connectionClosed && c.stoppedExchanges.Load() {
if moveState(curState, connectionClosed) {
curState = connectionClosed
}
}
if curState == connectionStartClose {
if !c.relay.canClose() {
return
}
if c.inbound.count() == 0 && moveState(connectionStartClose, connectionInboundClosed) {
curState = connectionInboundClosed
}
}
if curState == connectionInboundClosed {
// Safety check -- this should never happen since we already did the check
// when transitioning to connectionInboundClosed.
if !c.relay.canClose() {
c.relay.logger.Error("Relay can't close even though state is InboundClosed.")
return
}
if c.outbound.count() == 0 && moveState(connectionInboundClosed, connectionClosed) {
curState = connectionClosed
}
}
if curState != origState {
// If the connection is closed, we can notify writeFrames to stop which
// closes the underlying network connection. We never close sendCh to avoid
// races causing panics, see 93ef5c112c8b321367ae52d2bd79396e2e874f31
if curState == connectionClosed {
close(c.stopCh)
}
c.log.WithFields(
LogField{"newState", curState},
).Debug("Connection state updated during shutdown.")
c.callOnCloseStateChange()
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"checkExchanges",
"(",
")",
"{",
"c",
".",
"callOnExchangeChange",
"(",
")",
"\n",
"moveState",
":=",
"func",
"(",
"fromState",
",",
"toState",
"connectionState",
")",
"bool",
"{",
"err",
":=",
"c",
".",
"withStateLock",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"c",
".",
"state",
"!=",
"fromState",
"{",
"return",
"errors",
".",
"New",
"(",
"\"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"state",
"=",
"toState",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}",
"\n",
"curState",
":=",
"c",
".",
"readState",
"(",
")",
"\n",
"origState",
":=",
"curState",
"\n",
"if",
"curState",
"!=",
"connectionClosed",
"&&",
"c",
".",
"stoppedExchanges",
".",
"Load",
"(",
")",
"{",
"if",
"moveState",
"(",
"curState",
",",
"connectionClosed",
")",
"{",
"curState",
"=",
"connectionClosed",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"curState",
"==",
"connectionStartClose",
"{",
"if",
"!",
"c",
".",
"relay",
".",
"canClose",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"c",
".",
"inbound",
".",
"count",
"(",
")",
"==",
"0",
"&&",
"moveState",
"(",
"connectionStartClose",
",",
"connectionInboundClosed",
")",
"{",
"curState",
"=",
"connectionInboundClosed",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"curState",
"==",
"connectionInboundClosed",
"{",
"if",
"!",
"c",
".",
"relay",
".",
"canClose",
"(",
")",
"{",
"c",
".",
"relay",
".",
"logger",
".",
"Error",
"(",
"\"Relay can't close even though state is InboundClosed.\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"c",
".",
"outbound",
".",
"count",
"(",
")",
"==",
"0",
"&&",
"moveState",
"(",
"connectionInboundClosed",
",",
"connectionClosed",
")",
"{",
"curState",
"=",
"connectionClosed",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"curState",
"!=",
"origState",
"{",
"if",
"curState",
"==",
"connectionClosed",
"{",
"close",
"(",
"c",
".",
"stopCh",
")",
"\n",
"}",
"\n",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"newState\"",
",",
"curState",
"}",
",",
")",
".",
"Debug",
"(",
"\"Connection state updated during shutdown.\"",
")",
"\n",
"c",
".",
"callOnCloseStateChange",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// checkExchanges is called whenever an exchange is removed, and when Close is called.
|
[
"checkExchanges",
"is",
"called",
"whenever",
"an",
"exchange",
"is",
"removed",
"and",
"when",
"Close",
"is",
"called",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L751-L809
|
test
|
uber/tchannel-go
|
connection.go
|
closeNetwork
|
func (c *Connection) closeNetwork() {
// NB(mmihic): The sender goroutine will exit once the connection is
// closed; no need to close the send channel (and closing the send
// channel would be dangerous since other goroutine might be sending)
c.log.Debugf("Closing underlying network connection")
c.stopHealthCheck()
c.closeNetworkCalled.Store(true)
if err := c.conn.Close(); err != nil {
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
ErrField(err),
).Warn("Couldn't close connection to peer.")
}
}
|
go
|
func (c *Connection) closeNetwork() {
// NB(mmihic): The sender goroutine will exit once the connection is
// closed; no need to close the send channel (and closing the send
// channel would be dangerous since other goroutine might be sending)
c.log.Debugf("Closing underlying network connection")
c.stopHealthCheck()
c.closeNetworkCalled.Store(true)
if err := c.conn.Close(); err != nil {
c.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
ErrField(err),
).Warn("Couldn't close connection to peer.")
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"closeNetwork",
"(",
")",
"{",
"c",
".",
"log",
".",
"Debugf",
"(",
"\"Closing underlying network connection\"",
")",
"\n",
"c",
".",
"stopHealthCheck",
"(",
")",
"\n",
"c",
".",
"closeNetworkCalled",
".",
"Store",
"(",
"true",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"conn",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"remotePeer\"",
",",
"c",
".",
"remotePeerInfo",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
")",
".",
"Warn",
"(",
"\"Couldn't close connection to peer.\"",
")",
"\n",
"}",
"\n",
"}"
] |
// closeNetwork closes the network connection and all network-related channels.
// This should only be done in response to a fatal connection or protocol
// error, or after all pending frames have been sent.
|
[
"closeNetwork",
"closes",
"the",
"network",
"connection",
"and",
"all",
"network",
"-",
"related",
"channels",
".",
"This",
"should",
"only",
"be",
"done",
"in",
"response",
"to",
"a",
"fatal",
"connection",
"or",
"protocol",
"error",
"or",
"after",
"all",
"pending",
"frames",
"have",
"been",
"sent",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L853-L866
|
test
|
uber/tchannel-go
|
connection.go
|
getLastActivityTime
|
func (c *Connection) getLastActivityTime() time.Time {
return time.Unix(0, c.lastActivity.Load())
}
|
go
|
func (c *Connection) getLastActivityTime() time.Time {
return time.Unix(0, c.lastActivity.Load())
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"getLastActivityTime",
"(",
")",
"time",
".",
"Time",
"{",
"return",
"time",
".",
"Unix",
"(",
"0",
",",
"c",
".",
"lastActivity",
".",
"Load",
"(",
")",
")",
"\n",
"}"
] |
// getLastActivityTime returns the timestamp of the last frame read or written,
// excluding pings. If no frames were transmitted yet, it will return the time
// this connection was created.
|
[
"getLastActivityTime",
"returns",
"the",
"timestamp",
"of",
"the",
"last",
"frame",
"read",
"or",
"written",
"excluding",
"pings",
".",
"If",
"no",
"frames",
"were",
"transmitted",
"yet",
"it",
"will",
"return",
"the",
"time",
"this",
"connection",
"was",
"created",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/connection.go#L871-L873
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/validate.go
|
Validate
|
func Validate(svc *parser.Service) error {
for _, m := range svc.Methods {
if err := validateMethod(svc, m); err != nil {
return err
}
}
return nil
}
|
go
|
func Validate(svc *parser.Service) error {
for _, m := range svc.Methods {
if err := validateMethod(svc, m); err != nil {
return err
}
}
return nil
}
|
[
"func",
"Validate",
"(",
"svc",
"*",
"parser",
".",
"Service",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"svc",
".",
"Methods",
"{",
"if",
"err",
":=",
"validateMethod",
"(",
"svc",
",",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate validates that the given spec is supported by thrift-gen.
|
[
"Validate",
"validates",
"that",
"the",
"given",
"spec",
"is",
"supported",
"by",
"thrift",
"-",
"gen",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/validate.go#L30-L37
|
test
|
uber/tchannel-go
|
hyperbahn/advertise.go
|
logFailedRegistrationRetry
|
func (c *Client) logFailedRegistrationRetry(errLogger tchannel.Logger, consecutiveFailures uint) {
logFn := errLogger.Info
if consecutiveFailures > maxAdvertiseFailures {
logFn = errLogger.Warn
}
logFn("Hyperbahn client registration failed, will retry.")
}
|
go
|
func (c *Client) logFailedRegistrationRetry(errLogger tchannel.Logger, consecutiveFailures uint) {
logFn := errLogger.Info
if consecutiveFailures > maxAdvertiseFailures {
logFn = errLogger.Warn
}
logFn("Hyperbahn client registration failed, will retry.")
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"logFailedRegistrationRetry",
"(",
"errLogger",
"tchannel",
".",
"Logger",
",",
"consecutiveFailures",
"uint",
")",
"{",
"logFn",
":=",
"errLogger",
".",
"Info",
"\n",
"if",
"consecutiveFailures",
">",
"maxAdvertiseFailures",
"{",
"logFn",
"=",
"errLogger",
".",
"Warn",
"\n",
"}",
"\n",
"logFn",
"(",
"\"Hyperbahn client registration failed, will retry.\"",
")",
"\n",
"}"
] |
// logFailedRegistrationRetry logs either a warning or info depending on the number of
// consecutiveFailures. If consecutiveFailures > maxAdvertiseFailures, then we log a warning.
|
[
"logFailedRegistrationRetry",
"logs",
"either",
"a",
"warning",
"or",
"info",
"depending",
"on",
"the",
"number",
"of",
"consecutiveFailures",
".",
"If",
"consecutiveFailures",
">",
"maxAdvertiseFailures",
"then",
"we",
"log",
"a",
"warning",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/hyperbahn/advertise.go#L69-L76
|
test
|
uber/tchannel-go
|
hyperbahn/advertise.go
|
initialAdvertise
|
func (c *Client) initialAdvertise() error {
var err error
for attempt := uint(0); attempt < maxAdvertiseFailures; attempt++ {
err = c.sendAdvertise()
if err == nil || err == errEphemeralPeer {
break
}
c.tchan.Logger().WithFields(tchannel.ErrField(err)).Info(
"Hyperbahn client initial registration failure, will retry")
// Back off for a while.
sleepFor := fuzzInterval(advertiseRetryInterval * time.Duration(1<<attempt))
c.sleep(sleepFor)
}
return err
}
|
go
|
func (c *Client) initialAdvertise() error {
var err error
for attempt := uint(0); attempt < maxAdvertiseFailures; attempt++ {
err = c.sendAdvertise()
if err == nil || err == errEphemeralPeer {
break
}
c.tchan.Logger().WithFields(tchannel.ErrField(err)).Info(
"Hyperbahn client initial registration failure, will retry")
// Back off for a while.
sleepFor := fuzzInterval(advertiseRetryInterval * time.Duration(1<<attempt))
c.sleep(sleepFor)
}
return err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"initialAdvertise",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"for",
"attempt",
":=",
"uint",
"(",
"0",
")",
";",
"attempt",
"<",
"maxAdvertiseFailures",
";",
"attempt",
"++",
"{",
"err",
"=",
"c",
".",
"sendAdvertise",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"||",
"err",
"==",
"errEphemeralPeer",
"{",
"break",
"\n",
"}",
"\n",
"c",
".",
"tchan",
".",
"Logger",
"(",
")",
".",
"WithFields",
"(",
"tchannel",
".",
"ErrField",
"(",
"err",
")",
")",
".",
"Info",
"(",
"\"Hyperbahn client initial registration failure, will retry\"",
")",
"\n",
"sleepFor",
":=",
"fuzzInterval",
"(",
"advertiseRetryInterval",
"*",
"time",
".",
"Duration",
"(",
"1",
"<<",
"attempt",
")",
")",
"\n",
"c",
".",
"sleep",
"(",
"sleepFor",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// initialAdvertise will do the initial Advertise call to Hyperbahn with additional
// retries on top of the built-in TChannel retries. It will use exponential backoff
// between each of the call attempts.
|
[
"initialAdvertise",
"will",
"do",
"the",
"initial",
"Advertise",
"call",
"to",
"Hyperbahn",
"with",
"additional",
"retries",
"on",
"top",
"of",
"the",
"built",
"-",
"in",
"TChannel",
"retries",
".",
"It",
"will",
"use",
"exponential",
"backoff",
"between",
"each",
"of",
"the",
"call",
"attempts",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/hyperbahn/advertise.go#L116-L132
|
test
|
uber/tchannel-go
|
relay_messages.go
|
Service
|
func (f lazyCallReq) Service() []byte {
l := f.Payload[_serviceLenIndex]
return f.Payload[_serviceNameIndex : _serviceNameIndex+l]
}
|
go
|
func (f lazyCallReq) Service() []byte {
l := f.Payload[_serviceLenIndex]
return f.Payload[_serviceNameIndex : _serviceNameIndex+l]
}
|
[
"func",
"(",
"f",
"lazyCallReq",
")",
"Service",
"(",
")",
"[",
"]",
"byte",
"{",
"l",
":=",
"f",
".",
"Payload",
"[",
"_serviceLenIndex",
"]",
"\n",
"return",
"f",
".",
"Payload",
"[",
"_serviceNameIndex",
":",
"_serviceNameIndex",
"+",
"l",
"]",
"\n",
"}"
] |
// Service returns the name of the destination service for this callReq.
|
[
"Service",
"returns",
"the",
"name",
"of",
"the",
"destination",
"service",
"for",
"this",
"callReq",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_messages.go#L144-L147
|
test
|
uber/tchannel-go
|
relay_messages.go
|
TTL
|
func (f lazyCallReq) TTL() time.Duration {
ttl := binary.BigEndian.Uint32(f.Payload[_ttlIndex : _ttlIndex+_ttlLen])
return time.Duration(ttl) * time.Millisecond
}
|
go
|
func (f lazyCallReq) TTL() time.Duration {
ttl := binary.BigEndian.Uint32(f.Payload[_ttlIndex : _ttlIndex+_ttlLen])
return time.Duration(ttl) * time.Millisecond
}
|
[
"func",
"(",
"f",
"lazyCallReq",
")",
"TTL",
"(",
")",
"time",
".",
"Duration",
"{",
"ttl",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"f",
".",
"Payload",
"[",
"_ttlIndex",
":",
"_ttlIndex",
"+",
"_ttlLen",
"]",
")",
"\n",
"return",
"time",
".",
"Duration",
"(",
"ttl",
")",
"*",
"time",
".",
"Millisecond",
"\n",
"}"
] |
// TTL returns the time to live for this callReq.
|
[
"TTL",
"returns",
"the",
"time",
"to",
"live",
"for",
"this",
"callReq",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_messages.go#L165-L168
|
test
|
uber/tchannel-go
|
relay_messages.go
|
SetTTL
|
func (f lazyCallReq) SetTTL(d time.Duration) {
ttl := uint32(d / time.Millisecond)
binary.BigEndian.PutUint32(f.Payload[_ttlIndex:_ttlIndex+_ttlLen], ttl)
}
|
go
|
func (f lazyCallReq) SetTTL(d time.Duration) {
ttl := uint32(d / time.Millisecond)
binary.BigEndian.PutUint32(f.Payload[_ttlIndex:_ttlIndex+_ttlLen], ttl)
}
|
[
"func",
"(",
"f",
"lazyCallReq",
")",
"SetTTL",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"ttl",
":=",
"uint32",
"(",
"d",
"/",
"time",
".",
"Millisecond",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"f",
".",
"Payload",
"[",
"_ttlIndex",
":",
"_ttlIndex",
"+",
"_ttlLen",
"]",
",",
"ttl",
")",
"\n",
"}"
] |
// SetTTL overwrites the frame's TTL.
|
[
"SetTTL",
"overwrites",
"the",
"frame",
"s",
"TTL",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_messages.go#L171-L174
|
test
|
uber/tchannel-go
|
relay_messages.go
|
finishesCall
|
func finishesCall(f *Frame) bool {
switch f.messageType() {
case messageTypeError:
return true
case messageTypeCallRes, messageTypeCallResContinue:
flags := f.Payload[_flagsIndex]
return flags&hasMoreFragmentsFlag == 0
default:
return false
}
}
|
go
|
func finishesCall(f *Frame) bool {
switch f.messageType() {
case messageTypeError:
return true
case messageTypeCallRes, messageTypeCallResContinue:
flags := f.Payload[_flagsIndex]
return flags&hasMoreFragmentsFlag == 0
default:
return false
}
}
|
[
"func",
"finishesCall",
"(",
"f",
"*",
"Frame",
")",
"bool",
"{",
"switch",
"f",
".",
"messageType",
"(",
")",
"{",
"case",
"messageTypeError",
":",
"return",
"true",
"\n",
"case",
"messageTypeCallRes",
",",
"messageTypeCallResContinue",
":",
"flags",
":=",
"f",
".",
"Payload",
"[",
"_flagsIndex",
"]",
"\n",
"return",
"flags",
"&",
"hasMoreFragmentsFlag",
"==",
"0",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] |
// finishesCall checks whether this frame is the last one we should expect for
// this RPC req-res.
|
[
"finishesCall",
"checks",
"whether",
"this",
"frame",
"is",
"the",
"last",
"one",
"we",
"should",
"expect",
"for",
"this",
"RPC",
"req",
"-",
"res",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_messages.go#L188-L198
|
test
|
bazelbuild/bazel-gazelle
|
rule/platform_strings.go
|
Flat
|
func (ps *PlatformStrings) Flat() []string {
unique := make(map[string]struct{})
for _, s := range ps.Generic {
unique[s] = struct{}{}
}
for _, ss := range ps.OS {
for _, s := range ss {
unique[s] = struct{}{}
}
}
for _, ss := range ps.Arch {
for _, s := range ss {
unique[s] = struct{}{}
}
}
for _, ss := range ps.Platform {
for _, s := range ss {
unique[s] = struct{}{}
}
}
flat := make([]string, 0, len(unique))
for s := range unique {
flat = append(flat, s)
}
sort.Strings(flat)
return flat
}
|
go
|
func (ps *PlatformStrings) Flat() []string {
unique := make(map[string]struct{})
for _, s := range ps.Generic {
unique[s] = struct{}{}
}
for _, ss := range ps.OS {
for _, s := range ss {
unique[s] = struct{}{}
}
}
for _, ss := range ps.Arch {
for _, s := range ss {
unique[s] = struct{}{}
}
}
for _, ss := range ps.Platform {
for _, s := range ss {
unique[s] = struct{}{}
}
}
flat := make([]string, 0, len(unique))
for s := range unique {
flat = append(flat, s)
}
sort.Strings(flat)
return flat
}
|
[
"func",
"(",
"ps",
"*",
"PlatformStrings",
")",
"Flat",
"(",
")",
"[",
"]",
"string",
"{",
"unique",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"ps",
".",
"Generic",
"{",
"unique",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"ss",
":=",
"range",
"ps",
".",
"OS",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"unique",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"ss",
":=",
"range",
"ps",
".",
"Arch",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"unique",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"ss",
":=",
"range",
"ps",
".",
"Platform",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"unique",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"flat",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"unique",
")",
")",
"\n",
"for",
"s",
":=",
"range",
"unique",
"{",
"flat",
"=",
"append",
"(",
"flat",
",",
"s",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"flat",
")",
"\n",
"return",
"flat",
"\n",
"}"
] |
// Flat returns all the strings in the set, sorted and de-duplicated.
|
[
"Flat",
"returns",
"all",
"the",
"strings",
"in",
"the",
"set",
"sorted",
"and",
"de",
"-",
"duplicated",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/platform_strings.go#L59-L85
|
test
|
bazelbuild/bazel-gazelle
|
rule/platform_strings.go
|
Map
|
func (ps *PlatformStrings) Map(f func(s string) (string, error)) (PlatformStrings, []error) {
var errors []error
mapSlice := func(ss []string) ([]string, error) {
rs := make([]string, 0, len(ss))
for _, s := range ss {
if r, err := f(s); err != nil {
errors = append(errors, err)
} else if r != "" {
rs = append(rs, r)
}
}
return rs, nil
}
result, _ := ps.MapSlice(mapSlice)
return result, errors
}
|
go
|
func (ps *PlatformStrings) Map(f func(s string) (string, error)) (PlatformStrings, []error) {
var errors []error
mapSlice := func(ss []string) ([]string, error) {
rs := make([]string, 0, len(ss))
for _, s := range ss {
if r, err := f(s); err != nil {
errors = append(errors, err)
} else if r != "" {
rs = append(rs, r)
}
}
return rs, nil
}
result, _ := ps.MapSlice(mapSlice)
return result, errors
}
|
[
"func",
"(",
"ps",
"*",
"PlatformStrings",
")",
"Map",
"(",
"f",
"func",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
")",
"(",
"PlatformStrings",
",",
"[",
"]",
"error",
")",
"{",
"var",
"errors",
"[",
"]",
"error",
"\n",
"mapSlice",
":=",
"func",
"(",
"ss",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"rs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"ss",
")",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"ss",
"{",
"if",
"r",
",",
"err",
":=",
"f",
"(",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"r",
"!=",
"\"\"",
"{",
"rs",
"=",
"append",
"(",
"rs",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rs",
",",
"nil",
"\n",
"}",
"\n",
"result",
",",
"_",
":=",
"ps",
".",
"MapSlice",
"(",
"mapSlice",
")",
"\n",
"return",
"result",
",",
"errors",
"\n",
"}"
] |
// Map applies a function that processes individual strings to the strings
// in "ps" and returns a new PlatformStrings with the result. Empty strings
// returned by the function are dropped.
|
[
"Map",
"applies",
"a",
"function",
"that",
"processes",
"individual",
"strings",
"to",
"the",
"strings",
"in",
"ps",
"and",
"returns",
"a",
"new",
"PlatformStrings",
"with",
"the",
"result",
".",
"Empty",
"strings",
"returned",
"by",
"the",
"function",
"are",
"dropped",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/platform_strings.go#L120-L135
|
test
|
bazelbuild/bazel-gazelle
|
rule/platform_strings.go
|
MapSlice
|
func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (PlatformStrings, []error) {
var errors []error
mapSlice := func(ss []string) []string {
rs, err := f(ss)
if err != nil {
errors = append(errors, err)
return nil
}
return rs
}
mapStringMap := func(m map[string][]string) map[string][]string {
if m == nil {
return nil
}
rm := make(map[string][]string)
for k, ss := range m {
ss = mapSlice(ss)
if len(ss) > 0 {
rm[k] = ss
}
}
if len(rm) == 0 {
return nil
}
return rm
}
mapPlatformMap := func(m map[Platform][]string) map[Platform][]string {
if m == nil {
return nil
}
rm := make(map[Platform][]string)
for k, ss := range m {
ss = mapSlice(ss)
if len(ss) > 0 {
rm[k] = ss
}
}
if len(rm) == 0 {
return nil
}
return rm
}
result := PlatformStrings{
Generic: mapSlice(ps.Generic),
OS: mapStringMap(ps.OS),
Arch: mapStringMap(ps.Arch),
Platform: mapPlatformMap(ps.Platform),
}
return result, errors
}
|
go
|
func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (PlatformStrings, []error) {
var errors []error
mapSlice := func(ss []string) []string {
rs, err := f(ss)
if err != nil {
errors = append(errors, err)
return nil
}
return rs
}
mapStringMap := func(m map[string][]string) map[string][]string {
if m == nil {
return nil
}
rm := make(map[string][]string)
for k, ss := range m {
ss = mapSlice(ss)
if len(ss) > 0 {
rm[k] = ss
}
}
if len(rm) == 0 {
return nil
}
return rm
}
mapPlatformMap := func(m map[Platform][]string) map[Platform][]string {
if m == nil {
return nil
}
rm := make(map[Platform][]string)
for k, ss := range m {
ss = mapSlice(ss)
if len(ss) > 0 {
rm[k] = ss
}
}
if len(rm) == 0 {
return nil
}
return rm
}
result := PlatformStrings{
Generic: mapSlice(ps.Generic),
OS: mapStringMap(ps.OS),
Arch: mapStringMap(ps.Arch),
Platform: mapPlatformMap(ps.Platform),
}
return result, errors
}
|
[
"func",
"(",
"ps",
"*",
"PlatformStrings",
")",
"MapSlice",
"(",
"f",
"func",
"(",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
")",
"(",
"PlatformStrings",
",",
"[",
"]",
"error",
")",
"{",
"var",
"errors",
"[",
"]",
"error",
"\n",
"mapSlice",
":=",
"func",
"(",
"ss",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"rs",
",",
"err",
":=",
"f",
"(",
"ss",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"rs",
"\n",
"}",
"\n",
"mapStringMap",
":=",
"func",
"(",
"m",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"rm",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n",
"for",
"k",
",",
"ss",
":=",
"range",
"m",
"{",
"ss",
"=",
"mapSlice",
"(",
"ss",
")",
"\n",
"if",
"len",
"(",
"ss",
")",
">",
"0",
"{",
"rm",
"[",
"k",
"]",
"=",
"ss",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"rm",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"rm",
"\n",
"}",
"\n",
"mapPlatformMap",
":=",
"func",
"(",
"m",
"map",
"[",
"Platform",
"]",
"[",
"]",
"string",
")",
"map",
"[",
"Platform",
"]",
"[",
"]",
"string",
"{",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"rm",
":=",
"make",
"(",
"map",
"[",
"Platform",
"]",
"[",
"]",
"string",
")",
"\n",
"for",
"k",
",",
"ss",
":=",
"range",
"m",
"{",
"ss",
"=",
"mapSlice",
"(",
"ss",
")",
"\n",
"if",
"len",
"(",
"ss",
")",
">",
"0",
"{",
"rm",
"[",
"k",
"]",
"=",
"ss",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"rm",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"rm",
"\n",
"}",
"\n",
"result",
":=",
"PlatformStrings",
"{",
"Generic",
":",
"mapSlice",
"(",
"ps",
".",
"Generic",
")",
",",
"OS",
":",
"mapStringMap",
"(",
"ps",
".",
"OS",
")",
",",
"Arch",
":",
"mapStringMap",
"(",
"ps",
".",
"Arch",
")",
",",
"Platform",
":",
"mapPlatformMap",
"(",
"ps",
".",
"Platform",
")",
",",
"}",
"\n",
"return",
"result",
",",
"errors",
"\n",
"}"
] |
// MapSlice applies a function that processes slices of strings to the strings
// in "ps" and returns a new PlatformStrings with the results.
|
[
"MapSlice",
"applies",
"a",
"function",
"that",
"processes",
"slices",
"of",
"strings",
"to",
"the",
"strings",
"in",
"ps",
"and",
"returns",
"a",
"new",
"PlatformStrings",
"with",
"the",
"results",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/platform_strings.go#L139-L192
|
test
|
bazelbuild/bazel-gazelle
|
language/proto/config.go
|
GetProtoConfig
|
func GetProtoConfig(c *config.Config) *ProtoConfig {
pc := c.Exts[protoName]
if pc == nil {
return nil
}
return pc.(*ProtoConfig)
}
|
go
|
func GetProtoConfig(c *config.Config) *ProtoConfig {
pc := c.Exts[protoName]
if pc == nil {
return nil
}
return pc.(*ProtoConfig)
}
|
[
"func",
"GetProtoConfig",
"(",
"c",
"*",
"config",
".",
"Config",
")",
"*",
"ProtoConfig",
"{",
"pc",
":=",
"c",
".",
"Exts",
"[",
"protoName",
"]",
"\n",
"if",
"pc",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"pc",
".",
"(",
"*",
"ProtoConfig",
")",
"\n",
"}"
] |
// GetProtoConfig returns the proto language configuration. If the proto
// extension was not run, it will return nil.
|
[
"GetProtoConfig",
"returns",
"the",
"proto",
"language",
"configuration",
".",
"If",
"the",
"proto",
"extension",
"was",
"not",
"run",
"it",
"will",
"return",
"nil",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/language/proto/config.go#L64-L70
|
test
|
bazelbuild/bazel-gazelle
|
rule/expr.go
|
MapExprStrings
|
func MapExprStrings(e bzl.Expr, f func(string) string) bzl.Expr {
if e == nil {
return nil
}
switch expr := e.(type) {
case *bzl.StringExpr:
s := f(expr.Value)
if s == "" {
return nil
}
ret := *expr
ret.Value = s
return &ret
case *bzl.ListExpr:
var list []bzl.Expr
for _, elem := range expr.List {
elem = MapExprStrings(elem, f)
if elem != nil {
list = append(list, elem)
}
}
if len(list) == 0 && len(expr.List) > 0 {
return nil
}
ret := *expr
ret.List = list
return &ret
case *bzl.DictExpr:
var cases []bzl.Expr
isEmpty := true
for _, kv := range expr.List {
keyval, ok := kv.(*bzl.KeyValueExpr)
if !ok {
log.Panicf("unexpected expression in generated imports dict: %#v", kv)
}
value := MapExprStrings(keyval.Value, f)
if value != nil {
cases = append(cases, &bzl.KeyValueExpr{Key: keyval.Key, Value: value})
if key, ok := keyval.Key.(*bzl.StringExpr); !ok || key.Value != "//conditions:default" {
isEmpty = false
}
}
}
if isEmpty {
return nil
}
ret := *expr
ret.List = cases
return &ret
case *bzl.CallExpr:
if x, ok := expr.X.(*bzl.Ident); !ok || x.Name != "select" || len(expr.List) != 1 {
log.Panicf("unexpected call expression in generated imports: %#v", e)
}
arg := MapExprStrings(expr.List[0], f)
if arg == nil {
return nil
}
call := *expr
call.List[0] = arg
return &call
case *bzl.BinaryExpr:
x := MapExprStrings(expr.X, f)
y := MapExprStrings(expr.Y, f)
if x == nil {
return y
}
if y == nil {
return x
}
binop := *expr
binop.X = x
binop.Y = y
return &binop
default:
return nil
}
}
|
go
|
func MapExprStrings(e bzl.Expr, f func(string) string) bzl.Expr {
if e == nil {
return nil
}
switch expr := e.(type) {
case *bzl.StringExpr:
s := f(expr.Value)
if s == "" {
return nil
}
ret := *expr
ret.Value = s
return &ret
case *bzl.ListExpr:
var list []bzl.Expr
for _, elem := range expr.List {
elem = MapExprStrings(elem, f)
if elem != nil {
list = append(list, elem)
}
}
if len(list) == 0 && len(expr.List) > 0 {
return nil
}
ret := *expr
ret.List = list
return &ret
case *bzl.DictExpr:
var cases []bzl.Expr
isEmpty := true
for _, kv := range expr.List {
keyval, ok := kv.(*bzl.KeyValueExpr)
if !ok {
log.Panicf("unexpected expression in generated imports dict: %#v", kv)
}
value := MapExprStrings(keyval.Value, f)
if value != nil {
cases = append(cases, &bzl.KeyValueExpr{Key: keyval.Key, Value: value})
if key, ok := keyval.Key.(*bzl.StringExpr); !ok || key.Value != "//conditions:default" {
isEmpty = false
}
}
}
if isEmpty {
return nil
}
ret := *expr
ret.List = cases
return &ret
case *bzl.CallExpr:
if x, ok := expr.X.(*bzl.Ident); !ok || x.Name != "select" || len(expr.List) != 1 {
log.Panicf("unexpected call expression in generated imports: %#v", e)
}
arg := MapExprStrings(expr.List[0], f)
if arg == nil {
return nil
}
call := *expr
call.List[0] = arg
return &call
case *bzl.BinaryExpr:
x := MapExprStrings(expr.X, f)
y := MapExprStrings(expr.Y, f)
if x == nil {
return y
}
if y == nil {
return x
}
binop := *expr
binop.X = x
binop.Y = y
return &binop
default:
return nil
}
}
|
[
"func",
"MapExprStrings",
"(",
"e",
"bzl",
".",
"Expr",
",",
"f",
"func",
"(",
"string",
")",
"string",
")",
"bzl",
".",
"Expr",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"expr",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"*",
"bzl",
".",
"StringExpr",
":",
"s",
":=",
"f",
"(",
"expr",
".",
"Value",
")",
"\n",
"if",
"s",
"==",
"\"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ret",
":=",
"*",
"expr",
"\n",
"ret",
".",
"Value",
"=",
"s",
"\n",
"return",
"&",
"ret",
"\n",
"case",
"*",
"bzl",
".",
"ListExpr",
":",
"var",
"list",
"[",
"]",
"bzl",
".",
"Expr",
"\n",
"for",
"_",
",",
"elem",
":=",
"range",
"expr",
".",
"List",
"{",
"elem",
"=",
"MapExprStrings",
"(",
"elem",
",",
"f",
")",
"\n",
"if",
"elem",
"!=",
"nil",
"{",
"list",
"=",
"append",
"(",
"list",
",",
"elem",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"list",
")",
"==",
"0",
"&&",
"len",
"(",
"expr",
".",
"List",
")",
">",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ret",
":=",
"*",
"expr",
"\n",
"ret",
".",
"List",
"=",
"list",
"\n",
"return",
"&",
"ret",
"\n",
"case",
"*",
"bzl",
".",
"DictExpr",
":",
"var",
"cases",
"[",
"]",
"bzl",
".",
"Expr",
"\n",
"isEmpty",
":=",
"true",
"\n",
"for",
"_",
",",
"kv",
":=",
"range",
"expr",
".",
"List",
"{",
"keyval",
",",
"ok",
":=",
"kv",
".",
"(",
"*",
"bzl",
".",
"KeyValueExpr",
")",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Panicf",
"(",
"\"unexpected expression in generated imports dict: %#v\"",
",",
"kv",
")",
"\n",
"}",
"\n",
"value",
":=",
"MapExprStrings",
"(",
"keyval",
".",
"Value",
",",
"f",
")",
"\n",
"if",
"value",
"!=",
"nil",
"{",
"cases",
"=",
"append",
"(",
"cases",
",",
"&",
"bzl",
".",
"KeyValueExpr",
"{",
"Key",
":",
"keyval",
".",
"Key",
",",
"Value",
":",
"value",
"}",
")",
"\n",
"if",
"key",
",",
"ok",
":=",
"keyval",
".",
"Key",
".",
"(",
"*",
"bzl",
".",
"StringExpr",
")",
";",
"!",
"ok",
"||",
"key",
".",
"Value",
"!=",
"\"//conditions:default\"",
"{",
"isEmpty",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"isEmpty",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ret",
":=",
"*",
"expr",
"\n",
"ret",
".",
"List",
"=",
"cases",
"\n",
"return",
"&",
"ret",
"\n",
"case",
"*",
"bzl",
".",
"CallExpr",
":",
"if",
"x",
",",
"ok",
":=",
"expr",
".",
"X",
".",
"(",
"*",
"bzl",
".",
"Ident",
")",
";",
"!",
"ok",
"||",
"x",
".",
"Name",
"!=",
"\"select\"",
"||",
"len",
"(",
"expr",
".",
"List",
")",
"!=",
"1",
"{",
"log",
".",
"Panicf",
"(",
"\"unexpected call expression in generated imports: %#v\"",
",",
"e",
")",
"\n",
"}",
"\n",
"arg",
":=",
"MapExprStrings",
"(",
"expr",
".",
"List",
"[",
"0",
"]",
",",
"f",
")",
"\n",
"if",
"arg",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"call",
":=",
"*",
"expr",
"\n",
"call",
".",
"List",
"[",
"0",
"]",
"=",
"arg",
"\n",
"return",
"&",
"call",
"\n",
"case",
"*",
"bzl",
".",
"BinaryExpr",
":",
"x",
":=",
"MapExprStrings",
"(",
"expr",
".",
"X",
",",
"f",
")",
"\n",
"y",
":=",
"MapExprStrings",
"(",
"expr",
".",
"Y",
",",
"f",
")",
"\n",
"if",
"x",
"==",
"nil",
"{",
"return",
"y",
"\n",
"}",
"\n",
"if",
"y",
"==",
"nil",
"{",
"return",
"x",
"\n",
"}",
"\n",
"binop",
":=",
"*",
"expr",
"\n",
"binop",
".",
"X",
"=",
"x",
"\n",
"binop",
".",
"Y",
"=",
"y",
"\n",
"return",
"&",
"binop",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// MapExprStrings applies a function to string sub-expressions within e.
// An expression containing the results with the same structure as e is
// returned.
|
[
"MapExprStrings",
"applies",
"a",
"function",
"to",
"string",
"sub",
"-",
"expressions",
"within",
"e",
".",
"An",
"expression",
"containing",
"the",
"results",
"with",
"the",
"same",
"structure",
"as",
"e",
"is",
"returned",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/expr.go#L30-L111
|
test
|
bazelbuild/bazel-gazelle
|
rule/expr.go
|
FlattenExpr
|
func FlattenExpr(e bzl.Expr) bzl.Expr {
ps, err := extractPlatformStringsExprs(e)
if err != nil {
return e
}
ls := makeListSquasher()
addElem := func(e bzl.Expr) bool {
s, ok := e.(*bzl.StringExpr)
if !ok {
return false
}
ls.add(s)
return true
}
addList := func(e bzl.Expr) bool {
l, ok := e.(*bzl.ListExpr)
if !ok {
return false
}
for _, elem := range l.List {
if !addElem(elem) {
return false
}
}
return true
}
addDict := func(d *bzl.DictExpr) bool {
for _, kv := range d.List {
if !addList(kv.(*bzl.KeyValueExpr).Value) {
return false
}
}
return true
}
if ps.generic != nil {
if !addList(ps.generic) {
return e
}
}
for _, d := range []*bzl.DictExpr{ps.os, ps.arch, ps.platform} {
if d == nil {
continue
}
if !addDict(d) {
return e
}
}
return ls.list()
}
|
go
|
func FlattenExpr(e bzl.Expr) bzl.Expr {
ps, err := extractPlatformStringsExprs(e)
if err != nil {
return e
}
ls := makeListSquasher()
addElem := func(e bzl.Expr) bool {
s, ok := e.(*bzl.StringExpr)
if !ok {
return false
}
ls.add(s)
return true
}
addList := func(e bzl.Expr) bool {
l, ok := e.(*bzl.ListExpr)
if !ok {
return false
}
for _, elem := range l.List {
if !addElem(elem) {
return false
}
}
return true
}
addDict := func(d *bzl.DictExpr) bool {
for _, kv := range d.List {
if !addList(kv.(*bzl.KeyValueExpr).Value) {
return false
}
}
return true
}
if ps.generic != nil {
if !addList(ps.generic) {
return e
}
}
for _, d := range []*bzl.DictExpr{ps.os, ps.arch, ps.platform} {
if d == nil {
continue
}
if !addDict(d) {
return e
}
}
return ls.list()
}
|
[
"func",
"FlattenExpr",
"(",
"e",
"bzl",
".",
"Expr",
")",
"bzl",
".",
"Expr",
"{",
"ps",
",",
"err",
":=",
"extractPlatformStringsExprs",
"(",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n",
"ls",
":=",
"makeListSquasher",
"(",
")",
"\n",
"addElem",
":=",
"func",
"(",
"e",
"bzl",
".",
"Expr",
")",
"bool",
"{",
"s",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"bzl",
".",
"StringExpr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"ls",
".",
"add",
"(",
"s",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"addList",
":=",
"func",
"(",
"e",
"bzl",
".",
"Expr",
")",
"bool",
"{",
"l",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"bzl",
".",
"ListExpr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"elem",
":=",
"range",
"l",
".",
"List",
"{",
"if",
"!",
"addElem",
"(",
"elem",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"addDict",
":=",
"func",
"(",
"d",
"*",
"bzl",
".",
"DictExpr",
")",
"bool",
"{",
"for",
"_",
",",
"kv",
":=",
"range",
"d",
".",
"List",
"{",
"if",
"!",
"addList",
"(",
"kv",
".",
"(",
"*",
"bzl",
".",
"KeyValueExpr",
")",
".",
"Value",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ps",
".",
"generic",
"!=",
"nil",
"{",
"if",
"!",
"addList",
"(",
"ps",
".",
"generic",
")",
"{",
"return",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"[",
"]",
"*",
"bzl",
".",
"DictExpr",
"{",
"ps",
".",
"os",
",",
"ps",
".",
"arch",
",",
"ps",
".",
"platform",
"}",
"{",
"if",
"d",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"addDict",
"(",
"d",
")",
"{",
"return",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ls",
".",
"list",
"(",
")",
"\n",
"}"
] |
// FlattenExpr takes an expression that may have been generated from
// PlatformStrings and returns its values in a flat, sorted, de-duplicated
// list. Comments are accumulated and de-duplicated across duplicate
// expressions. If the expression could not have been generted by
// PlatformStrings, the expression will be returned unmodified.
|
[
"FlattenExpr",
"takes",
"an",
"expression",
"that",
"may",
"have",
"been",
"generated",
"from",
"PlatformStrings",
"and",
"returns",
"its",
"values",
"in",
"a",
"flat",
"sorted",
"de",
"-",
"duplicated",
"list",
".",
"Comments",
"are",
"accumulated",
"and",
"de",
"-",
"duplicated",
"across",
"duplicate",
"expressions",
".",
"If",
"the",
"expression",
"could",
"not",
"have",
"been",
"generted",
"by",
"PlatformStrings",
"the",
"expression",
"will",
"be",
"returned",
"unmodified",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/expr.go#L118-L169
|
test
|
bazelbuild/bazel-gazelle
|
rule/expr.go
|
makePlatformStringsExpr
|
func makePlatformStringsExpr(ps platformStringsExprs) bzl.Expr {
makeSelect := func(dict *bzl.DictExpr) bzl.Expr {
return &bzl.CallExpr{
X: &bzl.Ident{Name: "select"},
List: []bzl.Expr{dict},
}
}
forceMultiline := func(e bzl.Expr) {
switch e := e.(type) {
case *bzl.ListExpr:
e.ForceMultiLine = true
case *bzl.CallExpr:
e.List[0].(*bzl.DictExpr).ForceMultiLine = true
}
}
var parts []bzl.Expr
if ps.generic != nil {
parts = append(parts, ps.generic)
}
if ps.os != nil {
parts = append(parts, makeSelect(ps.os))
}
if ps.arch != nil {
parts = append(parts, makeSelect(ps.arch))
}
if ps.platform != nil {
parts = append(parts, makeSelect(ps.platform))
}
if len(parts) == 0 {
return nil
}
if len(parts) == 1 {
return parts[0]
}
expr := parts[0]
forceMultiline(expr)
for _, part := range parts[1:] {
forceMultiline(part)
expr = &bzl.BinaryExpr{
Op: "+",
X: expr,
Y: part,
}
}
return expr
}
|
go
|
func makePlatformStringsExpr(ps platformStringsExprs) bzl.Expr {
makeSelect := func(dict *bzl.DictExpr) bzl.Expr {
return &bzl.CallExpr{
X: &bzl.Ident{Name: "select"},
List: []bzl.Expr{dict},
}
}
forceMultiline := func(e bzl.Expr) {
switch e := e.(type) {
case *bzl.ListExpr:
e.ForceMultiLine = true
case *bzl.CallExpr:
e.List[0].(*bzl.DictExpr).ForceMultiLine = true
}
}
var parts []bzl.Expr
if ps.generic != nil {
parts = append(parts, ps.generic)
}
if ps.os != nil {
parts = append(parts, makeSelect(ps.os))
}
if ps.arch != nil {
parts = append(parts, makeSelect(ps.arch))
}
if ps.platform != nil {
parts = append(parts, makeSelect(ps.platform))
}
if len(parts) == 0 {
return nil
}
if len(parts) == 1 {
return parts[0]
}
expr := parts[0]
forceMultiline(expr)
for _, part := range parts[1:] {
forceMultiline(part)
expr = &bzl.BinaryExpr{
Op: "+",
X: expr,
Y: part,
}
}
return expr
}
|
[
"func",
"makePlatformStringsExpr",
"(",
"ps",
"platformStringsExprs",
")",
"bzl",
".",
"Expr",
"{",
"makeSelect",
":=",
"func",
"(",
"dict",
"*",
"bzl",
".",
"DictExpr",
")",
"bzl",
".",
"Expr",
"{",
"return",
"&",
"bzl",
".",
"CallExpr",
"{",
"X",
":",
"&",
"bzl",
".",
"Ident",
"{",
"Name",
":",
"\"select\"",
"}",
",",
"List",
":",
"[",
"]",
"bzl",
".",
"Expr",
"{",
"dict",
"}",
",",
"}",
"\n",
"}",
"\n",
"forceMultiline",
":=",
"func",
"(",
"e",
"bzl",
".",
"Expr",
")",
"{",
"switch",
"e",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"*",
"bzl",
".",
"ListExpr",
":",
"e",
".",
"ForceMultiLine",
"=",
"true",
"\n",
"case",
"*",
"bzl",
".",
"CallExpr",
":",
"e",
".",
"List",
"[",
"0",
"]",
".",
"(",
"*",
"bzl",
".",
"DictExpr",
")",
".",
"ForceMultiLine",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"parts",
"[",
"]",
"bzl",
".",
"Expr",
"\n",
"if",
"ps",
".",
"generic",
"!=",
"nil",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"ps",
".",
"generic",
")",
"\n",
"}",
"\n",
"if",
"ps",
".",
"os",
"!=",
"nil",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"makeSelect",
"(",
"ps",
".",
"os",
")",
")",
"\n",
"}",
"\n",
"if",
"ps",
".",
"arch",
"!=",
"nil",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"makeSelect",
"(",
"ps",
".",
"arch",
")",
")",
"\n",
"}",
"\n",
"if",
"ps",
".",
"platform",
"!=",
"nil",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"makeSelect",
"(",
"ps",
".",
"platform",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"1",
"{",
"return",
"parts",
"[",
"0",
"]",
"\n",
"}",
"\n",
"expr",
":=",
"parts",
"[",
"0",
"]",
"\n",
"forceMultiline",
"(",
"expr",
")",
"\n",
"for",
"_",
",",
"part",
":=",
"range",
"parts",
"[",
"1",
":",
"]",
"{",
"forceMultiline",
"(",
"part",
")",
"\n",
"expr",
"=",
"&",
"bzl",
".",
"BinaryExpr",
"{",
"Op",
":",
"\"+\"",
",",
"X",
":",
"expr",
",",
"Y",
":",
"part",
",",
"}",
"\n",
"}",
"\n",
"return",
"expr",
"\n",
"}"
] |
// makePlatformStringsExpr constructs a single expression from the
// sub-expressions in ps.
|
[
"makePlatformStringsExpr",
"constructs",
"a",
"single",
"expression",
"from",
"the",
"sub",
"-",
"expressions",
"in",
"ps",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/expr.go#L307-L354
|
test
|
bazelbuild/bazel-gazelle
|
rule/platform.go
|
String
|
func (p Platform) String() string {
switch {
case p.OS != "" && p.Arch != "":
return p.OS + "_" + p.Arch
case p.OS != "":
return p.OS
case p.Arch != "":
return p.Arch
default:
return ""
}
}
|
go
|
func (p Platform) String() string {
switch {
case p.OS != "" && p.Arch != "":
return p.OS + "_" + p.Arch
case p.OS != "":
return p.OS
case p.Arch != "":
return p.Arch
default:
return ""
}
}
|
[
"func",
"(",
"p",
"Platform",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"{",
"case",
"p",
".",
"OS",
"!=",
"\"\"",
"&&",
"p",
".",
"Arch",
"!=",
"\"\"",
":",
"return",
"p",
".",
"OS",
"+",
"\"_\"",
"+",
"p",
".",
"Arch",
"\n",
"case",
"p",
".",
"OS",
"!=",
"\"\"",
":",
"return",
"p",
".",
"OS",
"\n",
"case",
"p",
".",
"Arch",
"!=",
"\"\"",
":",
"return",
"p",
".",
"Arch",
"\n",
"default",
":",
"return",
"\"\"",
"\n",
"}",
"\n",
"}"
] |
// String returns OS, Arch, or "OS_Arch" if both are set. This must match
// the names of config_setting rules in @io_bazel_rules_go//go/platform.
|
[
"String",
"returns",
"OS",
"Arch",
"or",
"OS_Arch",
"if",
"both",
"are",
"set",
".",
"This",
"must",
"match",
"the",
"names",
"of",
"config_setting",
"rules",
"in"
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/platform.go#L30-L41
|
test
|
bazelbuild/bazel-gazelle
|
internal/wspace/finder.go
|
Find
|
func Find(dir string) (string, error) {
dir, err := filepath.Abs(dir)
if err != nil {
return "", err
}
for {
_, err = os.Stat(filepath.Join(dir, workspaceFile))
if err == nil {
return dir, nil
}
if !os.IsNotExist(err) {
return "", err
}
if strings.HasSuffix(dir, string(os.PathSeparator)) { // stop at root dir
return "", os.ErrNotExist
}
dir = filepath.Dir(dir)
}
}
|
go
|
func Find(dir string) (string, error) {
dir, err := filepath.Abs(dir)
if err != nil {
return "", err
}
for {
_, err = os.Stat(filepath.Join(dir, workspaceFile))
if err == nil {
return dir, nil
}
if !os.IsNotExist(err) {
return "", err
}
if strings.HasSuffix(dir, string(os.PathSeparator)) { // stop at root dir
return "", os.ErrNotExist
}
dir = filepath.Dir(dir)
}
}
|
[
"func",
"Find",
"(",
"dir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"dir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"for",
"{",
"_",
",",
"err",
"=",
"os",
".",
"Stat",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"workspaceFile",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"dir",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"dir",
",",
"string",
"(",
"os",
".",
"PathSeparator",
")",
")",
"{",
"return",
"\"\"",
",",
"os",
".",
"ErrNotExist",
"\n",
"}",
"\n",
"dir",
"=",
"filepath",
".",
"Dir",
"(",
"dir",
")",
"\n",
"}",
"\n",
"}"
] |
// Find searches from the given dir and up for the WORKSPACE file
// returning the directory containing it, or an error if none found in the tree.
|
[
"Find",
"searches",
"from",
"the",
"given",
"dir",
"and",
"up",
"for",
"the",
"WORKSPACE",
"file",
"returning",
"the",
"directory",
"containing",
"it",
"or",
"an",
"error",
"if",
"none",
"found",
"in",
"the",
"tree",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/internal/wspace/finder.go#L26-L45
|
test
|
bazelbuild/bazel-gazelle
|
cmd/autogazelle/autogazelle.go
|
runGazelle
|
func runGazelle(mode mode, dirs []string) error {
if mode == fastMode && len(dirs) == 0 {
return nil
}
args := []string{os.Getenv("BAZEL_REAL"), "run", *gazelleLabel, "--", "-args"}
args = append(args, "-index=false")
if mode == fastMode {
args = append(args, "-r=false")
args = append(args, dirs...)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Printf("running gazelle: %s\n", strings.Join(cmd.Args, " "))
return cmd.Run()
}
|
go
|
func runGazelle(mode mode, dirs []string) error {
if mode == fastMode && len(dirs) == 0 {
return nil
}
args := []string{os.Getenv("BAZEL_REAL"), "run", *gazelleLabel, "--", "-args"}
args = append(args, "-index=false")
if mode == fastMode {
args = append(args, "-r=false")
args = append(args, dirs...)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Printf("running gazelle: %s\n", strings.Join(cmd.Args, " "))
return cmd.Run()
}
|
[
"func",
"runGazelle",
"(",
"mode",
"mode",
",",
"dirs",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"mode",
"==",
"fastMode",
"&&",
"len",
"(",
"dirs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"os",
".",
"Getenv",
"(",
"\"BAZEL_REAL\"",
")",
",",
"\"run\"",
",",
"*",
"gazelleLabel",
",",
"\"--\"",
",",
"\"-args\"",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"-index=false\"",
")",
"\n",
"if",
"mode",
"==",
"fastMode",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"-r=false\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"dirs",
"...",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"log",
".",
"Printf",
"(",
"\"running gazelle: %s\\n\"",
",",
"\\n",
")",
"\n",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
",",
"\" \"",
")",
"\n",
"}"
] |
// runGazelle invokes gazelle with "bazel run". In fullMode, gazelle will
// run in the entire repository. In fastMode, gazelle will only run
// in the given directories.
|
[
"runGazelle",
"invokes",
"gazelle",
"with",
"bazel",
"run",
".",
"In",
"fullMode",
"gazelle",
"will",
"run",
"in",
"the",
"entire",
"repository",
".",
"In",
"fastMode",
"gazelle",
"will",
"only",
"run",
"in",
"the",
"given",
"directories",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/cmd/autogazelle/autogazelle.go#L99-L116
|
test
|
bazelbuild/bazel-gazelle
|
cmd/autogazelle/autogazelle.go
|
restoreBuildFilesInRepo
|
func restoreBuildFilesInRepo() {
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Print(err)
return nil
}
restoreBuildFilesInDir(path)
return nil
})
if err != nil {
log.Print(err)
}
}
|
go
|
func restoreBuildFilesInRepo() {
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Print(err)
return nil
}
restoreBuildFilesInDir(path)
return nil
})
if err != nil {
log.Print(err)
}
}
|
[
"func",
"restoreBuildFilesInRepo",
"(",
")",
"{",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"\".\"",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"restoreBuildFilesInDir",
"(",
"path",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// restoreBuildFilesInRepo copies BUILD.in and BUILD.bazel.in files and
// copies them to BUILD and BUILD.bazel.
|
[
"restoreBuildFilesInRepo",
"copies",
"BUILD",
".",
"in",
"and",
"BUILD",
".",
"bazel",
".",
"in",
"files",
"and",
"copies",
"them",
"to",
"BUILD",
"and",
"BUILD",
".",
"bazel",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/cmd/autogazelle/autogazelle.go#L120-L132
|
test
|
bazelbuild/bazel-gazelle
|
merger/fix.go
|
FixLoads
|
func FixLoads(f *rule.File, knownLoads []rule.LoadInfo) {
knownFiles := make(map[string]bool)
knownKinds := make(map[string]string)
for _, l := range knownLoads {
knownFiles[l.Name] = true
for _, k := range l.Symbols {
knownKinds[k] = l.Name
}
}
// Sync the file. We need File.Loads and File.Rules to contain inserted
// statements and not deleted statements.
f.Sync()
// Scan load statements in the file. Keep track of loads of known files,
// since these may be changed. Keep track of symbols loaded from unknown
// files; we will not add loads for these.
var loads []*rule.Load
otherLoadedKinds := make(map[string]bool)
for _, l := range f.Loads {
if knownFiles[l.Name()] {
loads = append(loads, l)
continue
}
for _, sym := range l.Symbols() {
otherLoadedKinds[sym] = true
}
}
// Make a map of all the symbols from known files used in this file.
usedKinds := make(map[string]map[string]bool)
for _, r := range f.Rules {
kind := r.Kind()
if file, ok := knownKinds[kind]; ok && !otherLoadedKinds[kind] {
if usedKinds[file] == nil {
usedKinds[file] = make(map[string]bool)
}
usedKinds[file][kind] = true
}
}
// Fix the load statements. The order is important, so we iterate over
// knownLoads instead of knownFiles.
for _, known := range knownLoads {
file := known.Name
first := true
for _, l := range loads {
if l.Name() != file {
continue
}
if first {
fixLoad(l, file, usedKinds[file], knownKinds)
first = false
} else {
fixLoad(l, file, nil, knownKinds)
}
if l.IsEmpty() {
l.Delete()
}
}
if first {
load := fixLoad(nil, file, usedKinds[file], knownKinds)
if load != nil {
index := newLoadIndex(f, known.After)
load.Insert(f, index)
}
}
}
}
|
go
|
func FixLoads(f *rule.File, knownLoads []rule.LoadInfo) {
knownFiles := make(map[string]bool)
knownKinds := make(map[string]string)
for _, l := range knownLoads {
knownFiles[l.Name] = true
for _, k := range l.Symbols {
knownKinds[k] = l.Name
}
}
// Sync the file. We need File.Loads and File.Rules to contain inserted
// statements and not deleted statements.
f.Sync()
// Scan load statements in the file. Keep track of loads of known files,
// since these may be changed. Keep track of symbols loaded from unknown
// files; we will not add loads for these.
var loads []*rule.Load
otherLoadedKinds := make(map[string]bool)
for _, l := range f.Loads {
if knownFiles[l.Name()] {
loads = append(loads, l)
continue
}
for _, sym := range l.Symbols() {
otherLoadedKinds[sym] = true
}
}
// Make a map of all the symbols from known files used in this file.
usedKinds := make(map[string]map[string]bool)
for _, r := range f.Rules {
kind := r.Kind()
if file, ok := knownKinds[kind]; ok && !otherLoadedKinds[kind] {
if usedKinds[file] == nil {
usedKinds[file] = make(map[string]bool)
}
usedKinds[file][kind] = true
}
}
// Fix the load statements. The order is important, so we iterate over
// knownLoads instead of knownFiles.
for _, known := range knownLoads {
file := known.Name
first := true
for _, l := range loads {
if l.Name() != file {
continue
}
if first {
fixLoad(l, file, usedKinds[file], knownKinds)
first = false
} else {
fixLoad(l, file, nil, knownKinds)
}
if l.IsEmpty() {
l.Delete()
}
}
if first {
load := fixLoad(nil, file, usedKinds[file], knownKinds)
if load != nil {
index := newLoadIndex(f, known.After)
load.Insert(f, index)
}
}
}
}
|
[
"func",
"FixLoads",
"(",
"f",
"*",
"rule",
".",
"File",
",",
"knownLoads",
"[",
"]",
"rule",
".",
"LoadInfo",
")",
"{",
"knownFiles",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"knownKinds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"knownLoads",
"{",
"knownFiles",
"[",
"l",
".",
"Name",
"]",
"=",
"true",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"l",
".",
"Symbols",
"{",
"knownKinds",
"[",
"k",
"]",
"=",
"l",
".",
"Name",
"\n",
"}",
"\n",
"}",
"\n",
"f",
".",
"Sync",
"(",
")",
"\n",
"var",
"loads",
"[",
"]",
"*",
"rule",
".",
"Load",
"\n",
"otherLoadedKinds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"f",
".",
"Loads",
"{",
"if",
"knownFiles",
"[",
"l",
".",
"Name",
"(",
")",
"]",
"{",
"loads",
"=",
"append",
"(",
"loads",
",",
"l",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"sym",
":=",
"range",
"l",
".",
"Symbols",
"(",
")",
"{",
"otherLoadedKinds",
"[",
"sym",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"usedKinds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"f",
".",
"Rules",
"{",
"kind",
":=",
"r",
".",
"Kind",
"(",
")",
"\n",
"if",
"file",
",",
"ok",
":=",
"knownKinds",
"[",
"kind",
"]",
";",
"ok",
"&&",
"!",
"otherLoadedKinds",
"[",
"kind",
"]",
"{",
"if",
"usedKinds",
"[",
"file",
"]",
"==",
"nil",
"{",
"usedKinds",
"[",
"file",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"}",
"\n",
"usedKinds",
"[",
"file",
"]",
"[",
"kind",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"known",
":=",
"range",
"knownLoads",
"{",
"file",
":=",
"known",
".",
"Name",
"\n",
"first",
":=",
"true",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"loads",
"{",
"if",
"l",
".",
"Name",
"(",
")",
"!=",
"file",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"first",
"{",
"fixLoad",
"(",
"l",
",",
"file",
",",
"usedKinds",
"[",
"file",
"]",
",",
"knownKinds",
")",
"\n",
"first",
"=",
"false",
"\n",
"}",
"else",
"{",
"fixLoad",
"(",
"l",
",",
"file",
",",
"nil",
",",
"knownKinds",
")",
"\n",
"}",
"\n",
"if",
"l",
".",
"IsEmpty",
"(",
")",
"{",
"l",
".",
"Delete",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"first",
"{",
"load",
":=",
"fixLoad",
"(",
"nil",
",",
"file",
",",
"usedKinds",
"[",
"file",
"]",
",",
"knownKinds",
")",
"\n",
"if",
"load",
"!=",
"nil",
"{",
"index",
":=",
"newLoadIndex",
"(",
"f",
",",
"known",
".",
"After",
")",
"\n",
"load",
".",
"Insert",
"(",
"f",
",",
"index",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// FixLoads removes loads of unused go rules and adds loads of newly used rules.
// This should be called after FixFile and MergeFile, since symbols
// may be introduced that aren't loaded.
//
// This function calls File.Sync before processing loads.
|
[
"FixLoads",
"removes",
"loads",
"of",
"unused",
"go",
"rules",
"and",
"adds",
"loads",
"of",
"newly",
"used",
"rules",
".",
"This",
"should",
"be",
"called",
"after",
"FixFile",
"and",
"MergeFile",
"since",
"symbols",
"may",
"be",
"introduced",
"that",
"aren",
"t",
"loaded",
".",
"This",
"function",
"calls",
"File",
".",
"Sync",
"before",
"processing",
"loads",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/merger/fix.go#L30-L98
|
test
|
bazelbuild/bazel-gazelle
|
merger/fix.go
|
fixLoad
|
func fixLoad(load *rule.Load, file string, kinds map[string]bool, knownKinds map[string]string) *rule.Load {
if load == nil {
if len(kinds) == 0 {
return nil
}
load = rule.NewLoad(file)
}
for k := range kinds {
load.Add(k)
}
for _, k := range load.Symbols() {
if knownKinds[k] != "" && !kinds[k] {
load.Remove(k)
}
}
return load
}
|
go
|
func fixLoad(load *rule.Load, file string, kinds map[string]bool, knownKinds map[string]string) *rule.Load {
if load == nil {
if len(kinds) == 0 {
return nil
}
load = rule.NewLoad(file)
}
for k := range kinds {
load.Add(k)
}
for _, k := range load.Symbols() {
if knownKinds[k] != "" && !kinds[k] {
load.Remove(k)
}
}
return load
}
|
[
"func",
"fixLoad",
"(",
"load",
"*",
"rule",
".",
"Load",
",",
"file",
"string",
",",
"kinds",
"map",
"[",
"string",
"]",
"bool",
",",
"knownKinds",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"rule",
".",
"Load",
"{",
"if",
"load",
"==",
"nil",
"{",
"if",
"len",
"(",
"kinds",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"load",
"=",
"rule",
".",
"NewLoad",
"(",
"file",
")",
"\n",
"}",
"\n",
"for",
"k",
":=",
"range",
"kinds",
"{",
"load",
".",
"Add",
"(",
"k",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"load",
".",
"Symbols",
"(",
")",
"{",
"if",
"knownKinds",
"[",
"k",
"]",
"!=",
"\"\"",
"&&",
"!",
"kinds",
"[",
"k",
"]",
"{",
"load",
".",
"Remove",
"(",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"load",
"\n",
"}"
] |
// fixLoad updates a load statement with the given symbols. If load is nil,
// a new load may be created and returned. Symbols in kinds will be added
// to the load if they're not already present. Known symbols not in kinds
// will be removed if present. Other symbols will be preserved. If load is
// empty, nil is returned.
|
[
"fixLoad",
"updates",
"a",
"load",
"statement",
"with",
"the",
"given",
"symbols",
".",
"If",
"load",
"is",
"nil",
"a",
"new",
"load",
"may",
"be",
"created",
"and",
"returned",
".",
"Symbols",
"in",
"kinds",
"will",
"be",
"added",
"to",
"the",
"load",
"if",
"they",
"re",
"not",
"already",
"present",
".",
"Known",
"symbols",
"not",
"in",
"kinds",
"will",
"be",
"removed",
"if",
"present",
".",
"Other",
"symbols",
"will",
"be",
"preserved",
".",
"If",
"load",
"is",
"empty",
"nil",
"is",
"returned",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/merger/fix.go#L105-L122
|
test
|
bazelbuild/bazel-gazelle
|
merger/fix.go
|
newLoadIndex
|
func newLoadIndex(f *rule.File, after []string) int {
if len(after) == 0 {
return 0
}
index := 0
for _, r := range f.Rules {
for _, a := range after {
if r.Kind() == a && r.Index() >= index {
index = r.Index() + 1
}
}
}
return index
}
|
go
|
func newLoadIndex(f *rule.File, after []string) int {
if len(after) == 0 {
return 0
}
index := 0
for _, r := range f.Rules {
for _, a := range after {
if r.Kind() == a && r.Index() >= index {
index = r.Index() + 1
}
}
}
return index
}
|
[
"func",
"newLoadIndex",
"(",
"f",
"*",
"rule",
".",
"File",
",",
"after",
"[",
"]",
"string",
")",
"int",
"{",
"if",
"len",
"(",
"after",
")",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"index",
":=",
"0",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"f",
".",
"Rules",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"after",
"{",
"if",
"r",
".",
"Kind",
"(",
")",
"==",
"a",
"&&",
"r",
".",
"Index",
"(",
")",
">=",
"index",
"{",
"index",
"=",
"r",
".",
"Index",
"(",
")",
"+",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"index",
"\n",
"}"
] |
// newLoadIndex returns the index in stmts where a new load statement should
// be inserted. after is a list of function names that the load should not
// be inserted before.
|
[
"newLoadIndex",
"returns",
"the",
"index",
"in",
"stmts",
"where",
"a",
"new",
"load",
"statement",
"should",
"be",
"inserted",
".",
"after",
"is",
"a",
"list",
"of",
"function",
"names",
"that",
"the",
"load",
"should",
"not",
"be",
"inserted",
"before",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/merger/fix.go#L127-L140
|
test
|
bazelbuild/bazel-gazelle
|
merger/fix.go
|
removeLegacyGoRepository
|
func removeLegacyGoRepository(f *rule.File) {
for _, l := range f.Loads {
if l.Name() == "@io_bazel_rules_go//go:def.bzl" {
l.Remove("go_repository")
if l.IsEmpty() {
l.Delete()
}
}
}
}
|
go
|
func removeLegacyGoRepository(f *rule.File) {
for _, l := range f.Loads {
if l.Name() == "@io_bazel_rules_go//go:def.bzl" {
l.Remove("go_repository")
if l.IsEmpty() {
l.Delete()
}
}
}
}
|
[
"func",
"removeLegacyGoRepository",
"(",
"f",
"*",
"rule",
".",
"File",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"f",
".",
"Loads",
"{",
"if",
"l",
".",
"Name",
"(",
")",
"==",
"\"@io_bazel_rules_go//go:def.bzl\"",
"{",
"l",
".",
"Remove",
"(",
"\"go_repository\"",
")",
"\n",
"if",
"l",
".",
"IsEmpty",
"(",
")",
"{",
"l",
".",
"Delete",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// removeLegacyGoRepository removes loads of go_repository from
// @io_bazel_rules_go. FixLoads should be called after this; it will load from
// @bazel_gazelle.
|
[
"removeLegacyGoRepository",
"removes",
"loads",
"of",
"go_repository",
"from"
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/merger/fix.go#L190-L199
|
test
|
bazelbuild/bazel-gazelle
|
internal/version/version.go
|
Compare
|
func (x Version) Compare(y Version) int {
n := len(x)
if len(y) < n {
n = len(y)
}
for i := 0; i < n; i++ {
cmp := x[i] - y[i]
if cmp != 0 {
return cmp
}
}
return len(x) - len(y)
}
|
go
|
func (x Version) Compare(y Version) int {
n := len(x)
if len(y) < n {
n = len(y)
}
for i := 0; i < n; i++ {
cmp := x[i] - y[i]
if cmp != 0 {
return cmp
}
}
return len(x) - len(y)
}
|
[
"func",
"(",
"x",
"Version",
")",
"Compare",
"(",
"y",
"Version",
")",
"int",
"{",
"n",
":=",
"len",
"(",
"x",
")",
"\n",
"if",
"len",
"(",
"y",
")",
"<",
"n",
"{",
"n",
"=",
"len",
"(",
"y",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"cmp",
":=",
"x",
"[",
"i",
"]",
"-",
"y",
"[",
"i",
"]",
"\n",
"if",
"cmp",
"!=",
"0",
"{",
"return",
"cmp",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"len",
"(",
"x",
")",
"-",
"len",
"(",
"y",
")",
"\n",
"}"
] |
// Compare returns an integer comparing two versions lexicographically.
|
[
"Compare",
"returns",
"an",
"integer",
"comparing",
"two",
"versions",
"lexicographically",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/internal/version/version.go#L37-L49
|
test
|
bazelbuild/bazel-gazelle
|
internal/version/version.go
|
ParseVersion
|
func ParseVersion(vs string) (Version, error) {
i := strings.IndexByte(vs, '-')
if i >= 0 {
vs = vs[:i]
}
cstrs := strings.Split(vs, ".")
v := make(Version, len(cstrs))
for i, cstr := range cstrs {
cn, err := strconv.Atoi(cstr)
if err != nil {
return nil, fmt.Errorf("could not parse version string: %q is not an integer", cstr)
}
if cn < 0 {
return nil, fmt.Errorf("could not parse version string: %q is negative", cstr)
}
v[i] = cn
}
return v, nil
}
|
go
|
func ParseVersion(vs string) (Version, error) {
i := strings.IndexByte(vs, '-')
if i >= 0 {
vs = vs[:i]
}
cstrs := strings.Split(vs, ".")
v := make(Version, len(cstrs))
for i, cstr := range cstrs {
cn, err := strconv.Atoi(cstr)
if err != nil {
return nil, fmt.Errorf("could not parse version string: %q is not an integer", cstr)
}
if cn < 0 {
return nil, fmt.Errorf("could not parse version string: %q is negative", cstr)
}
v[i] = cn
}
return v, nil
}
|
[
"func",
"ParseVersion",
"(",
"vs",
"string",
")",
"(",
"Version",
",",
"error",
")",
"{",
"i",
":=",
"strings",
".",
"IndexByte",
"(",
"vs",
",",
"'-'",
")",
"\n",
"if",
"i",
">=",
"0",
"{",
"vs",
"=",
"vs",
"[",
":",
"i",
"]",
"\n",
"}",
"\n",
"cstrs",
":=",
"strings",
".",
"Split",
"(",
"vs",
",",
"\".\"",
")",
"\n",
"v",
":=",
"make",
"(",
"Version",
",",
"len",
"(",
"cstrs",
")",
")",
"\n",
"for",
"i",
",",
"cstr",
":=",
"range",
"cstrs",
"{",
"cn",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"cstr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not parse version string: %q is not an integer\"",
",",
"cstr",
")",
"\n",
"}",
"\n",
"if",
"cn",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not parse version string: %q is negative\"",
",",
"cstr",
")",
"\n",
"}",
"\n",
"v",
"[",
"i",
"]",
"=",
"cn",
"\n",
"}",
"\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] |
// ParseVersion parses a version of the form "12.34.56-abcd". Non-negative
// integer components are separated by dots. An arbitrary suffix may appear
// after '-', which is ignored.
|
[
"ParseVersion",
"parses",
"a",
"version",
"of",
"the",
"form",
"12",
".",
"34",
".",
"56",
"-",
"abcd",
".",
"Non",
"-",
"negative",
"integer",
"components",
"are",
"separated",
"by",
"dots",
".",
"An",
"arbitrary",
"suffix",
"may",
"appear",
"after",
"-",
"which",
"is",
"ignored",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/internal/version/version.go#L54-L72
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
EmptyFile
|
func EmptyFile(path, pkg string) *File {
return &File{
File: &bzl.File{Path: path, Type: bzl.TypeBuild},
Path: path,
Pkg: pkg,
}
}
|
go
|
func EmptyFile(path, pkg string) *File {
return &File{
File: &bzl.File{Path: path, Type: bzl.TypeBuild},
Path: path,
Pkg: pkg,
}
}
|
[
"func",
"EmptyFile",
"(",
"path",
",",
"pkg",
"string",
")",
"*",
"File",
"{",
"return",
"&",
"File",
"{",
"File",
":",
"&",
"bzl",
".",
"File",
"{",
"Path",
":",
"path",
",",
"Type",
":",
"bzl",
".",
"TypeBuild",
"}",
",",
"Path",
":",
"path",
",",
"Pkg",
":",
"pkg",
",",
"}",
"\n",
"}"
] |
// EmptyFile creates a File wrapped around an empty syntax tree.
|
[
"EmptyFile",
"creates",
"a",
"File",
"wrapped",
"around",
"an",
"empty",
"syntax",
"tree",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L73-L79
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
LoadWorkspaceFile
|
func LoadWorkspaceFile(path, pkg string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadWorkspaceData(path, pkg, data)
}
|
go
|
func LoadWorkspaceFile(path, pkg string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadWorkspaceData(path, pkg, data)
}
|
[
"func",
"LoadWorkspaceFile",
"(",
"path",
",",
"pkg",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"LoadWorkspaceData",
"(",
"path",
",",
"pkg",
",",
"data",
")",
"\n",
"}"
] |
// LoadWorkspaceFile is similar to LoadFile but parses the file as a WORKSPACE
// file.
|
[
"LoadWorkspaceFile",
"is",
"similar",
"to",
"LoadFile",
"but",
"parses",
"the",
"file",
"as",
"a",
"WORKSPACE",
"file",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L97-L103
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
LoadMacroFile
|
func LoadMacroFile(path, pkg, defName string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, data)
}
|
go
|
func LoadMacroFile(path, pkg, defName string) (*File, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, data)
}
|
[
"func",
"LoadMacroFile",
"(",
"path",
",",
"pkg",
",",
"defName",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"LoadMacroData",
"(",
"path",
",",
"pkg",
",",
"defName",
",",
"data",
")",
"\n",
"}"
] |
// LoadMacroFile loads a bzl file from disk, parses it, then scans for the load
// statements and the rules called from the given Starlark function. If there is
// no matching function name, then a new function with that name will be created.
// The function's syntax tree will be returned within File and can be modified by
// Sync and Save calls.
|
[
"LoadMacroFile",
"loads",
"a",
"bzl",
"file",
"from",
"disk",
"parses",
"it",
"then",
"scans",
"for",
"the",
"load",
"statements",
"and",
"the",
"rules",
"called",
"from",
"the",
"given",
"Starlark",
"function",
".",
"If",
"there",
"is",
"no",
"matching",
"function",
"name",
"then",
"a",
"new",
"function",
"with",
"that",
"name",
"will",
"be",
"created",
".",
"The",
"function",
"s",
"syntax",
"tree",
"will",
"be",
"returned",
"within",
"File",
"and",
"can",
"be",
"modified",
"by",
"Sync",
"and",
"Save",
"calls",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L110-L116
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
EmptyMacroFile
|
func EmptyMacroFile(path, pkg, defName string) (*File, error) {
_, err := os.Create(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, nil)
}
|
go
|
func EmptyMacroFile(path, pkg, defName string) (*File, error) {
_, err := os.Create(path)
if err != nil {
return nil, err
}
return LoadMacroData(path, pkg, defName, nil)
}
|
[
"func",
"EmptyMacroFile",
"(",
"path",
",",
"pkg",
",",
"defName",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"LoadMacroData",
"(",
"path",
",",
"pkg",
",",
"defName",
",",
"nil",
")",
"\n",
"}"
] |
// EmptyMacroFile creates a bzl file at the given path and within the file creates
// a Starlark function with the provided name. The function can then be modified
// by Sync and Save calls.
|
[
"EmptyMacroFile",
"creates",
"a",
"bzl",
"file",
"at",
"the",
"given",
"path",
"and",
"within",
"the",
"file",
"creates",
"a",
"Starlark",
"function",
"with",
"the",
"provided",
"name",
".",
"The",
"function",
"can",
"then",
"be",
"modified",
"by",
"Sync",
"and",
"Save",
"calls",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L121-L127
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
LoadData
|
func LoadData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseBuild(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
}
|
go
|
func LoadData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseBuild(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
}
|
[
"func",
"LoadData",
"(",
"path",
",",
"pkg",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"ast",
",",
"err",
":=",
"bzl",
".",
"ParseBuild",
"(",
"path",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ScanAST",
"(",
"pkg",
",",
"ast",
")",
",",
"nil",
"\n",
"}"
] |
// LoadData parses a build file from a byte slice and scans it for rules and
// load statements. The syntax tree within the returned File will be modified
// by editing methods.
|
[
"LoadData",
"parses",
"a",
"build",
"file",
"from",
"a",
"byte",
"slice",
"and",
"scans",
"it",
"for",
"rules",
"and",
"load",
"statements",
".",
"The",
"syntax",
"tree",
"within",
"the",
"returned",
"File",
"will",
"be",
"modified",
"by",
"editing",
"methods",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L132-L138
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
LoadWorkspaceData
|
func LoadWorkspaceData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseWorkspace(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
}
|
go
|
func LoadWorkspaceData(path, pkg string, data []byte) (*File, error) {
ast, err := bzl.ParseWorkspace(path, data)
if err != nil {
return nil, err
}
return ScanAST(pkg, ast), nil
}
|
[
"func",
"LoadWorkspaceData",
"(",
"path",
",",
"pkg",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"ast",
",",
"err",
":=",
"bzl",
".",
"ParseWorkspace",
"(",
"path",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ScanAST",
"(",
"pkg",
",",
"ast",
")",
",",
"nil",
"\n",
"}"
] |
// LoadWorkspaceData is similar to LoadData but parses the data as a
// WORKSPACE file.
|
[
"LoadWorkspaceData",
"is",
"similar",
"to",
"LoadData",
"but",
"parses",
"the",
"data",
"as",
"a",
"WORKSPACE",
"file",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L142-L148
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
LoadMacroData
|
func LoadMacroData(path, pkg, defName string, data []byte) (*File, error) {
ast, err := bzl.ParseBzl(path, data)
if err != nil {
return nil, err
}
return ScanASTBody(pkg, defName, ast), nil
}
|
go
|
func LoadMacroData(path, pkg, defName string, data []byte) (*File, error) {
ast, err := bzl.ParseBzl(path, data)
if err != nil {
return nil, err
}
return ScanASTBody(pkg, defName, ast), nil
}
|
[
"func",
"LoadMacroData",
"(",
"path",
",",
"pkg",
",",
"defName",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"ast",
",",
"err",
":=",
"bzl",
".",
"ParseBzl",
"(",
"path",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ScanASTBody",
"(",
"pkg",
",",
"defName",
",",
"ast",
")",
",",
"nil",
"\n",
"}"
] |
// LoadMacroData parses a bzl file from a byte slice and scans for the load
// statements and the rules called from the given Starlark function. If there is
// no matching function name, then a new function will be created, and added to the
// File the next time Sync is called. The function's syntax tree will be returned
// within File and can be modified by Sync and Save calls.
|
[
"LoadMacroData",
"parses",
"a",
"bzl",
"file",
"from",
"a",
"byte",
"slice",
"and",
"scans",
"for",
"the",
"load",
"statements",
"and",
"the",
"rules",
"called",
"from",
"the",
"given",
"Starlark",
"function",
".",
"If",
"there",
"is",
"no",
"matching",
"function",
"name",
"then",
"a",
"new",
"function",
"will",
"be",
"created",
"and",
"added",
"to",
"the",
"File",
"the",
"next",
"time",
"Sync",
"is",
"called",
".",
"The",
"function",
"s",
"syntax",
"tree",
"will",
"be",
"returned",
"within",
"File",
"and",
"can",
"be",
"modified",
"by",
"Sync",
"and",
"Save",
"calls",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L155-L161
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
ScanAST
|
func ScanAST(pkg string, bzlFile *bzl.File) *File {
return ScanASTBody(pkg, "", bzlFile)
}
|
go
|
func ScanAST(pkg string, bzlFile *bzl.File) *File {
return ScanASTBody(pkg, "", bzlFile)
}
|
[
"func",
"ScanAST",
"(",
"pkg",
"string",
",",
"bzlFile",
"*",
"bzl",
".",
"File",
")",
"*",
"File",
"{",
"return",
"ScanASTBody",
"(",
"pkg",
",",
"\"\"",
",",
"bzlFile",
")",
"\n",
"}"
] |
// ScanAST creates a File wrapped around the given syntax tree. This tree
// will be modified by editing methods.
|
[
"ScanAST",
"creates",
"a",
"File",
"wrapped",
"around",
"the",
"given",
"syntax",
"tree",
".",
"This",
"tree",
"will",
"be",
"modified",
"by",
"editing",
"methods",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L165-L167
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
ScanASTBody
|
func ScanASTBody(pkg, defName string, bzlFile *bzl.File) *File {
f := &File{
File: bzlFile,
Pkg: pkg,
Path: bzlFile.Path,
}
var defStmt *bzl.DefStmt
f.Rules, f.Loads, defStmt = scanExprs(defName, bzlFile.Stmt)
if defStmt != nil {
f.Rules, _, _ = scanExprs("", defStmt.Body)
f.function = &function{
stmt: defStmt,
inserted: true,
}
if len(defStmt.Body) == 1 {
if v, ok := defStmt.Body[0].(*bzl.BranchStmt); ok && v.Token == "pass" {
f.function.hasPass = true
}
}
} else if defName != "" {
f.function = &function{
stmt: &bzl.DefStmt{Name: defName},
inserted: false,
}
}
f.Directives = ParseDirectives(bzlFile)
return f
}
|
go
|
func ScanASTBody(pkg, defName string, bzlFile *bzl.File) *File {
f := &File{
File: bzlFile,
Pkg: pkg,
Path: bzlFile.Path,
}
var defStmt *bzl.DefStmt
f.Rules, f.Loads, defStmt = scanExprs(defName, bzlFile.Stmt)
if defStmt != nil {
f.Rules, _, _ = scanExprs("", defStmt.Body)
f.function = &function{
stmt: defStmt,
inserted: true,
}
if len(defStmt.Body) == 1 {
if v, ok := defStmt.Body[0].(*bzl.BranchStmt); ok && v.Token == "pass" {
f.function.hasPass = true
}
}
} else if defName != "" {
f.function = &function{
stmt: &bzl.DefStmt{Name: defName},
inserted: false,
}
}
f.Directives = ParseDirectives(bzlFile)
return f
}
|
[
"func",
"ScanASTBody",
"(",
"pkg",
",",
"defName",
"string",
",",
"bzlFile",
"*",
"bzl",
".",
"File",
")",
"*",
"File",
"{",
"f",
":=",
"&",
"File",
"{",
"File",
":",
"bzlFile",
",",
"Pkg",
":",
"pkg",
",",
"Path",
":",
"bzlFile",
".",
"Path",
",",
"}",
"\n",
"var",
"defStmt",
"*",
"bzl",
".",
"DefStmt",
"\n",
"f",
".",
"Rules",
",",
"f",
".",
"Loads",
",",
"defStmt",
"=",
"scanExprs",
"(",
"defName",
",",
"bzlFile",
".",
"Stmt",
")",
"\n",
"if",
"defStmt",
"!=",
"nil",
"{",
"f",
".",
"Rules",
",",
"_",
",",
"_",
"=",
"scanExprs",
"(",
"\"\"",
",",
"defStmt",
".",
"Body",
")",
"\n",
"f",
".",
"function",
"=",
"&",
"function",
"{",
"stmt",
":",
"defStmt",
",",
"inserted",
":",
"true",
",",
"}",
"\n",
"if",
"len",
"(",
"defStmt",
".",
"Body",
")",
"==",
"1",
"{",
"if",
"v",
",",
"ok",
":=",
"defStmt",
".",
"Body",
"[",
"0",
"]",
".",
"(",
"*",
"bzl",
".",
"BranchStmt",
")",
";",
"ok",
"&&",
"v",
".",
"Token",
"==",
"\"pass\"",
"{",
"f",
".",
"function",
".",
"hasPass",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"defName",
"!=",
"\"\"",
"{",
"f",
".",
"function",
"=",
"&",
"function",
"{",
"stmt",
":",
"&",
"bzl",
".",
"DefStmt",
"{",
"Name",
":",
"defName",
"}",
",",
"inserted",
":",
"false",
",",
"}",
"\n",
"}",
"\n",
"f",
".",
"Directives",
"=",
"ParseDirectives",
"(",
"bzlFile",
")",
"\n",
"return",
"f",
"\n",
"}"
] |
// ScanASTBody creates a File wrapped around the given syntax tree. It will also
// scan the AST for a function matching the given defName, and if the function
// does not exist it will create a new one and mark it to be added to the File
// the next time Sync is called.
|
[
"ScanASTBody",
"creates",
"a",
"File",
"wrapped",
"around",
"the",
"given",
"syntax",
"tree",
".",
"It",
"will",
"also",
"scan",
"the",
"AST",
"for",
"a",
"function",
"matching",
"the",
"given",
"defName",
"and",
"if",
"the",
"function",
"does",
"not",
"exist",
"it",
"will",
"create",
"a",
"new",
"one",
"and",
"mark",
"it",
"to",
"be",
"added",
"to",
"the",
"File",
"the",
"next",
"time",
"Sync",
"is",
"called",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L178-L205
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
MatchBuildFileName
|
func MatchBuildFileName(dir string, names []string, files []os.FileInfo) string {
for _, name := range names {
for _, fi := range files {
if fi.Name() == name && !fi.IsDir() {
return filepath.Join(dir, name)
}
}
}
return ""
}
|
go
|
func MatchBuildFileName(dir string, names []string, files []os.FileInfo) string {
for _, name := range names {
for _, fi := range files {
if fi.Name() == name && !fi.IsDir() {
return filepath.Join(dir, name)
}
}
}
return ""
}
|
[
"func",
"MatchBuildFileName",
"(",
"dir",
"string",
",",
"names",
"[",
"]",
"string",
",",
"files",
"[",
"]",
"os",
".",
"FileInfo",
")",
"string",
"{",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"for",
"_",
",",
"fi",
":=",
"range",
"files",
"{",
"if",
"fi",
".",
"Name",
"(",
")",
"==",
"name",
"&&",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"filepath",
".",
"Join",
"(",
"dir",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"\"",
"\n",
"}"
] |
// MatchBuildFileName looks for a file in files that has a name from names.
// If there is at least one matching file, a path will be returned by joining
// dir and the first matching name. If there are no matching files, the
// empty string is returned.
|
[
"MatchBuildFileName",
"looks",
"for",
"a",
"file",
"in",
"files",
"that",
"has",
"a",
"name",
"from",
"names",
".",
"If",
"there",
"is",
"at",
"least",
"one",
"matching",
"file",
"a",
"path",
"will",
"be",
"returned",
"by",
"joining",
"dir",
"and",
"the",
"first",
"matching",
"name",
".",
"If",
"there",
"are",
"no",
"matching",
"files",
"the",
"empty",
"string",
"is",
"returned",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L230-L239
|
test
|
bazelbuild/bazel-gazelle
|
rule/rule.go
|
SyncMacroFile
|
func (f *File) SyncMacroFile(from *File) {
fromFunc := *from.function.stmt
_, _, toFunc := scanExprs(from.function.stmt.Name, f.File.Stmt)
if toFunc != nil {
*toFunc = fromFunc
} else {
f.File.Stmt = append(f.File.Stmt, &fromFunc)
}
}
|
go
|
func (f *File) SyncMacroFile(from *File) {
fromFunc := *from.function.stmt
_, _, toFunc := scanExprs(from.function.stmt.Name, f.File.Stmt)
if toFunc != nil {
*toFunc = fromFunc
} else {
f.File.Stmt = append(f.File.Stmt, &fromFunc)
}
}
|
[
"func",
"(",
"f",
"*",
"File",
")",
"SyncMacroFile",
"(",
"from",
"*",
"File",
")",
"{",
"fromFunc",
":=",
"*",
"from",
".",
"function",
".",
"stmt",
"\n",
"_",
",",
"_",
",",
"toFunc",
":=",
"scanExprs",
"(",
"from",
".",
"function",
".",
"stmt",
".",
"Name",
",",
"f",
".",
"File",
".",
"Stmt",
")",
"\n",
"if",
"toFunc",
"!=",
"nil",
"{",
"*",
"toFunc",
"=",
"fromFunc",
"\n",
"}",
"else",
"{",
"f",
".",
"File",
".",
"Stmt",
"=",
"append",
"(",
"f",
".",
"File",
".",
"Stmt",
",",
"&",
"fromFunc",
")",
"\n",
"}",
"\n",
"}"
] |
// SyncMacroFile syncs the file's syntax tree with another file's. This is
// useful for keeping multiple macro definitions from the same .bzl file in sync.
|
[
"SyncMacroFile",
"syncs",
"the",
"file",
"s",
"syntax",
"tree",
"with",
"another",
"file",
"s",
".",
"This",
"is",
"useful",
"for",
"keeping",
"multiple",
"macro",
"definitions",
"from",
"the",
"same",
".",
"bzl",
"file",
"in",
"sync",
"."
] |
e3805aaca69a9deb949b47bfc45b9b1870712f4f
|
https://github.com/bazelbuild/bazel-gazelle/blob/e3805aaca69a9deb949b47bfc45b9b1870712f4f/rule/rule.go#L243-L251
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.