_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q10900 | buildClient | train | func buildClient(f func(*transportOptions) *http.Client) TransportOption {
return func(options *transportOptions) {
options.buildClient = f
}
} | go | {
"resource": ""
} |
q10901 | NewTransport | train | func NewTransport(opts ...TransportOption) *Transport {
options := newTransportOptions()
for _, opt := range opts {
opt(&options)
}
return options.newTransport()
} | go | {
"resource": ""
} |
q10902 | Stop | train | func (a *Transport) Stop() error {
return a.once.Stop(func() error {
a.connectorsGroup.Wait()
return nil
})
} | go | {
"resource": ""
} |
q10903 | StartupWait | train | func StartupWait(t time.Duration) HeapOption {
return func(c *heapConfig) {
c.startupWait = t
}
} | go | {
"resource": ""
} |
q10904 | New | train | func New(transport peer.Transport, opts ...HeapOption) *List {
cfg := defaultHeapConfig
for _, o := range opts {
o(&cfg)
}
return &List{
once: lifecycle.NewOnce(),
transport: transport,
byIdentifier: make(map[string]*peerScore),
peerAvailableEvent: make(chan struct{}, 1),
startupWait: cfg.startupWait,
}
} | go | {
"resource": ""
} |
q10905 | Update | train | func (pl *List) Update(updates peer.ListUpdates) error {
ctx, cancel := context.WithTimeout(context.Background(), pl.startupWait)
defer cancel()
if err := pl.once.WaitUntilRunning(ctx); err != nil {
return intyarpcerrors.AnnotateWithInfo(yarpcerrors.FromError(err), "%s peer list is not running", "peer heap")
}
var errs error
pl.mu.Lock()
defer pl.mu.Unlock()
for _, pid := range updates.Removals {
errs = multierr.Append(errs, pl.releasePeer(pid))
}
for _, pid := range updates.Additions {
errs = multierr.Append(errs, pl.retainPeer(pid))
}
return errs
} | go | {
"resource": ""
} |
q10906 | retainPeer | train | func (pl *List) retainPeer(pid peer.Identifier) error {
if _, ok := pl.byIdentifier[pid.Identifier()]; ok {
return peer.ErrPeerAddAlreadyInList(pid.Identifier())
}
ps := &peerScore{id: pid, list: pl}
p, err := pl.transport.RetainPeer(pid, ps)
if err != nil {
return err
}
ps.peer = p
ps.score = scorePeer(p)
ps.boundFinish = ps.finish
pl.byIdentifier[pid.Identifier()] = ps
pl.byScore.pushPeer(ps)
pl.internalNotifyStatusChanged(ps)
return nil
} | go | {
"resource": ""
} |
q10907 | releasePeer | train | func (pl *List) releasePeer(pid peer.Identifier) error {
ps, ok := pl.byIdentifier[pid.Identifier()]
if !ok {
return peer.ErrPeerRemoveNotInList(pid.Identifier())
}
if err := pl.byScore.validate(ps); err != nil {
return err
}
err := pl.transport.ReleasePeer(pid, ps)
delete(pl.byIdentifier, pid.Identifier())
pl.byScore.delete(ps.idx)
ps.list = nil
return err
} | go | {
"resource": ""
} |
q10908 | NotifyStatusChanged | train | func (pl *List) NotifyStatusChanged(pid peer.Identifier) {
pl.mu.Lock()
ps := pl.byIdentifier[pid.Identifier()]
pl.mu.Unlock()
ps.NotifyStatusChanged(pid)
} | go | {
"resource": ""
} |
q10909 | ThriftForTransport | train | func ThriftForTransport(t crossdock.T, transport string) {
t = createEchoT("thrift", transport, t)
fatals := crossdock.Fatals(t)
dispatcher := disp.CreateDispatcherForTransport(t, transport)
fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
defer dispatcher.Stop()
client := echoclient.New(dispatcher.ClientConfig("yarpc-test"))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
token := random.String(5)
pong, err := client.Echo(ctx, &echo.Ping{Beep: token})
crossdock.Fatals(t).NoError(err, "call to Echo::echo failed: %v", err)
crossdock.Assert(t).Equal(token, pong.Boop, "server said: %v", pong.Boop)
} | go | {
"resource": ""
} |
q10910 | RawForTransport | train | func RawForTransport(t crossdock.T, transport string) {
t = createEchoT("raw", transport, t)
fatals := crossdock.Fatals(t)
dispatcher := disp.CreateDispatcherForTransport(t, transport)
fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
defer dispatcher.Stop()
client := raw.New(dispatcher.ClientConfig("yarpc-test"))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
token := random.Bytes(5)
resBody, err := client.Call(ctx, "echo/raw", token)
crossdock.Fatals(t).NoError(err, "call to echo/raw failed: %v", err)
crossdock.Assert(t).True(bytes.Equal(token, resBody), "server said: %v", resBody)
} | go | {
"resource": ""
} |
q10911 | NewInboundCallWithOptions | train | func NewInboundCallWithOptions(ctx context.Context, opts ...InboundCallOption) (context.Context, *InboundCall) {
call := &InboundCall{}
for _, opt := range opts {
opt.apply(call)
}
return context.WithValue(ctx, inboundCallKey{}, call), call
} | go | {
"resource": ""
} |
q10912 | getInboundCall | train | func getInboundCall(ctx context.Context) (*InboundCall, bool) {
call, ok := ctx.Value(inboundCallKey{}).(*InboundCall)
return call, ok
} | go | {
"resource": ""
} |
q10913 | ReadFromRequest | train | func (ic *InboundCall) ReadFromRequest(req *transport.Request) error {
// TODO(abg): Maybe we should copy attributes over so that changes to the
// Request don't change the output.
ic.req = req
return nil
} | go | {
"resource": ""
} |
q10914 | ReadFromRequestMeta | train | func (ic *InboundCall) ReadFromRequestMeta(reqMeta *transport.RequestMeta) error {
ic.req = reqMeta.ToRequest()
return nil
} | go | {
"resource": ""
} |
q10915 | WriteToResponse | train | func (ic *InboundCall) WriteToResponse(resw transport.ResponseWriter) error {
var headers transport.Headers
for _, h := range ic.resHeaders {
headers = headers.With(h.k, h.v)
}
if headers.Len() > 0 {
resw.AddHeaders(headers)
}
return nil
} | go | {
"resource": ""
} |
q10916 | ExceptionType_Values | train | func ExceptionType_Values() []ExceptionType {
return []ExceptionType{
ExceptionTypeUnknown,
ExceptionTypeUnknownMethod,
ExceptionTypeInvalidMessageType,
ExceptionTypeWrongMethodName,
ExceptionTypeBadSequenceID,
ExceptionTypeMissingResult,
ExceptionTypeInternalError,
ExceptionTypeProtocolError,
ExceptionTypeInvalidTransform,
ExceptionTypeInvalidProtocol,
ExceptionTypeUnsupportedClientType,
}
} | go | {
"resource": ""
} |
q10917 | MarshalText | train | func (v ExceptionType) MarshalText() ([]byte, error) {
switch int32(v) {
case 0:
return []byte("UNKNOWN"), nil
case 1:
return []byte("UNKNOWN_METHOD"), nil
case 2:
return []byte("INVALID_MESSAGE_TYPE"), nil
case 3:
return []byte("WRONG_METHOD_NAME"), nil
case 4:
return []byte("BAD_SEQUENCE_ID"), nil
case 5:
return []byte("MISSING_RESULT"), nil
case 6:
return []byte("INTERNAL_ERROR"), nil
case 7:
return []byte("PROTOCOL_ERROR"), nil
case 8:
return []byte("INVALID_TRANSFORM"), nil
case 9:
return []byte("INVALID_PROTOCOL"), nil
case 10:
return []byte("UNSUPPORTED_CLIENT_TYPE"), nil
}
return []byte(strconv.FormatInt(int64(v), 10)), nil
} | go | {
"resource": ""
} |
q10918 | String | train | func (v ExceptionType) String() string {
w := int32(v)
switch w {
case 0:
return "UNKNOWN"
case 1:
return "UNKNOWN_METHOD"
case 2:
return "INVALID_MESSAGE_TYPE"
case 3:
return "WRONG_METHOD_NAME"
case 4:
return "BAD_SEQUENCE_ID"
case 5:
return "MISSING_RESULT"
case 6:
return "INTERNAL_ERROR"
case 7:
return "PROTOCOL_ERROR"
case 8:
return "INVALID_TRANSFORM"
case 9:
return "INVALID_PROTOCOL"
case 10:
return "UNSUPPORTED_CLIENT_TYPE"
}
return fmt.Sprintf("ExceptionType(%d)", w)
} | go | {
"resource": ""
} |
q10919 | String | train | func (v *TApplicationException) String() string {
if v == nil {
return "<nil>"
}
var fields [2]string
i := 0
if v.Message != nil {
fields[i] = fmt.Sprintf("Message: %v", *(v.Message))
i++
}
if v.Type != nil {
fields[i] = fmt.Sprintf("Type: %v", *(v.Type))
i++
}
return fmt.Sprintf("TApplicationException{%v}", strings.Join(fields[:i], ", "))
} | go | {
"resource": ""
} |
q10920 | Equals | train | func (v *TApplicationException) Equals(rhs *TApplicationException) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
if !_String_EqualsPtr(v.Message, rhs.Message) {
return false
}
if !_ExceptionType_EqualsPtr(v.Type, rhs.Type) {
return false
}
return true
} | go | {
"resource": ""
} |
q10921 | MarshalLogObject | train | func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
if v.Message != nil {
enc.AddString("message", *v.Message)
}
if v.Type != nil {
err = multierr.Append(err, enc.AddObject("type", *v.Type))
}
return err
} | go | {
"resource": ""
} |
q10922 | ClientBuilderOptions | train | func ClientBuilderOptions(_ transport.ClientConfig, f reflect.StructField) []ClientOption {
// Note that we don't use ClientConfig right now but since this code is
// called by generated code, we still accept it so that we can add logic
// based on it in the future without breaking the API (and thus, all
// generated code).
optionList := strings.Split(f.Tag.Get("thrift"), ",")
var opts []ClientOption
for _, opt := range optionList {
switch strings.ToLower(opt) {
case "multiplexed":
opts = append(opts, Multiplexed)
case "enveloped":
opts = append(opts, Enveloped)
default:
// Ignore unknown options
}
}
return opts
} | go | {
"resource": ""
} |
q10923 | Logger | train | func Logger(logger *zap.Logger) Option {
return optionFunc(func(opts *options) {
opts.logger = logger
})
} | go | {
"resource": ""
} |
q10924 | tmpl | train | func tmpl(tmpl templateIface) Option {
return optionFunc(func(opts *options) {
opts.tmpl = tmpl
})
} | go | {
"resource": ""
} |
q10925 | applyOptions | train | func applyOptions(opts ...Option) options {
options := options{
logger: zap.NewNop(),
tmpl: _defaultTmpl,
}
for _, opt := range opts {
opt.apply(&options)
}
return options
} | go | {
"resource": ""
} |
q10926 | ApplyUnaryOutbound | train | func ApplyUnaryOutbound(o transport.UnaryOutbound, f UnaryOutbound) transport.UnaryOutbound {
if f == nil {
return o
}
return unaryOutboundWithMiddleware{o: o, f: f}
} | go | {
"resource": ""
} |
q10927 | Call | train | func (f UnaryOutboundFunc) Call(ctx context.Context, request *transport.Request, out transport.UnaryOutbound) (*transport.Response, error) {
return f(ctx, request, out)
} | go | {
"resource": ""
} |
q10928 | ApplyOnewayOutbound | train | func ApplyOnewayOutbound(o transport.OnewayOutbound, f OnewayOutbound) transport.OnewayOutbound {
if f == nil {
return o
}
return onewayOutboundWithMiddleware{o: o, f: f}
} | go | {
"resource": ""
} |
q10929 | CallOneway | train | func (f OnewayOutboundFunc) CallOneway(ctx context.Context, request *transport.Request, out transport.OnewayOutbound) (transport.Ack, error) {
return f(ctx, request, out)
} | go | {
"resource": ""
} |
q10930 | ApplyStreamOutbound | train | func ApplyStreamOutbound(o transport.StreamOutbound, f StreamOutbound) transport.StreamOutbound {
if f == nil {
return o
}
return streamOutboundWithMiddleware{o: o, f: f}
} | go | {
"resource": ""
} |
q10931 | CallStream | train | func (f StreamOutboundFunc) CallStream(ctx context.Context, request *transport.StreamRequest, out transport.StreamOutbound) (*transport.ClientStream, error) {
return f(ctx, request, out)
} | go | {
"resource": ""
} |
q10932 | fill | train | func (l *logging) fill(cfg *yarpc.Config) {
cfg.Logging.Levels.ApplicationError = (*zapcore.Level)(l.Levels.ApplicationError)
} | go | {
"resource": ""
} |
q10933 | Decode | train | func (l *zapLevel) Decode(into mapdecode.Into) error {
var s string
if err := into(&s); err != nil {
return fmt.Errorf("could not decode Zap log level: %v", err)
}
err := (*zapcore.Level)(l).UnmarshalText([]byte(s))
if err != nil {
return fmt.Errorf("could not decode Zap log level: %v", err)
}
return err
} | go | {
"resource": ""
} |
q10934 | NewNopContextExtractor | train | func NewNopContextExtractor() ContextExtractor {
return ContextExtractor(func(_ context.Context) zapcore.Field { return zap.Skip() })
} | go | {
"resource": ""
} |
q10935 | NewOutboundCall | train | func NewOutboundCall(options ...CallOption) *OutboundCall {
var call OutboundCall
for _, opt := range options {
opt.apply(&call)
}
return &call
} | go | {
"resource": ""
} |
q10936 | NewStreamOutboundCall | train | func NewStreamOutboundCall(options ...CallOption) (*OutboundCall, error) {
call := NewOutboundCall(options...)
if call.responseHeaders != nil {
return nil, yarpcerrors.InvalidArgumentErrorf("response headers are not supported for streams")
}
return call, nil
} | go | {
"resource": ""
} |
q10937 | WriteToRequest | train | func (c *OutboundCall) WriteToRequest(ctx context.Context, req *transport.Request) (context.Context, error) {
for _, h := range c.headers {
req.Headers = req.Headers.With(h.k, h.v)
}
if c.shardKey != nil {
req.ShardKey = *c.shardKey
}
if c.routingKey != nil {
req.RoutingKey = *c.routingKey
}
if c.routingDelegate != nil {
req.RoutingDelegate = *c.routingDelegate
}
// NB(abg): context and error are unused for now but we want to leave room
// for CallOptions which can fail or modify the context.
return ctx, nil
} | go | {
"resource": ""
} |
q10938 | WriteToRequestMeta | train | func (c *OutboundCall) WriteToRequestMeta(ctx context.Context, reqMeta *transport.RequestMeta) (context.Context, error) {
for _, h := range c.headers {
reqMeta.Headers = reqMeta.Headers.With(h.k, h.v)
}
if c.shardKey != nil {
reqMeta.ShardKey = *c.shardKey
}
if c.routingKey != nil {
reqMeta.RoutingKey = *c.routingKey
}
if c.routingDelegate != nil {
reqMeta.RoutingDelegate = *c.routingDelegate
}
// NB(abg): context and error are unused for now but we want to leave room
// for CallOptions which can fail or modify the context.
return ctx, nil
} | go | {
"resource": ""
} |
q10939 | ReadFromResponse | train | func (c *OutboundCall) ReadFromResponse(ctx context.Context, res *transport.Response) (context.Context, error) {
// We're not using ctx right now but we may in the future.
if c.responseHeaders != nil && res.Headers.Len() > 0 {
// We make a copy of the response headers because Headers.Items() must
// never be mutated.
headers := make(map[string]string, res.Headers.Len())
for k, v := range res.Headers.Items() {
headers[k] = v
}
*c.responseHeaders = headers
}
// NB(abg): context and error are unused for now but we want to leave room
// for CallOptions which can fail or modify the context.
return ctx, nil
} | go | {
"resource": ""
} |
q10940 | NewMapRouter | train | func NewMapRouter(defaultService string) MapRouter {
return MapRouter{
defaultService: defaultService,
serviceProcedures: make(map[serviceProcedure]transport.Procedure),
serviceProcedureEncodings: make(map[serviceProcedureEncoding]transport.Procedure),
supportedEncodings: make(map[serviceProcedure][]string),
serviceNames: map[string]struct{}{defaultService: {}},
}
} | go | {
"resource": ""
} |
q10941 | Register | train | func (m MapRouter) Register(rs []transport.Procedure) {
for _, r := range rs {
if r.Service == "" {
r.Service = m.defaultService
}
if r.Name == "" {
panic("Expected procedure name not to be empty string in registration")
}
m.serviceNames[r.Service] = struct{}{}
sp := serviceProcedure{
service: r.Service,
procedure: r.Name,
}
if r.Encoding == "" {
// Protect against masking encoding-specific routes.
if _, ok := m.serviceProcedures[sp]; ok {
panic(fmt.Sprintf("Cannot register multiple handlers for every encoding for service %q and procedure %q", sp.service, sp.procedure))
}
if se, ok := m.supportedEncodings[sp]; ok {
panic(fmt.Sprintf("Cannot register a handler for every encoding for service %q and procedure %q when there are already handlers for %s", sp.service, sp.procedure, humanize.QuotedJoin(se, "and", "no encodings")))
}
// This supports wild card encodings (for backward compatibility,
// since type models like Thrift were not previously required to
// specify the encoding of every procedure).
m.serviceProcedures[sp] = r
continue
}
spe := serviceProcedureEncoding{
service: r.Service,
procedure: r.Name,
encoding: r.Encoding,
}
// Protect against overriding wildcards
if _, ok := m.serviceProcedures[sp]; ok {
panic(fmt.Sprintf("Cannot register a handler for both (service, procedure) on any * encoding and (service, procedure, encoding), specifically (%q, %q, %q)", r.Service, r.Name, r.Encoding))
}
// Route to individual handlers for unique combinations of service,
// procedure, and encoding. This shall henceforth be the
// recommended way for models to register procedures.
m.serviceProcedureEncodings[spe] = r
// Record supported encodings.
m.supportedEncodings[sp] = append(m.supportedEncodings[sp], string(r.Encoding))
}
} | go | {
"resource": ""
} |
q10942 | Procedures | train | func (m MapRouter) Procedures() []transport.Procedure {
procs := make([]transport.Procedure, 0, len(m.serviceProcedures)+len(m.serviceProcedureEncodings))
for _, v := range m.serviceProcedures {
procs = append(procs, v)
}
for _, v := range m.serviceProcedureEncodings {
procs = append(procs, v)
}
sort.Sort(sortableProcedures(procs))
return procs
} | go | {
"resource": ""
} |
q10943 | getAvailableServiceNames | train | func getAvailableServiceNames(svcMap map[string]struct{}) string {
var serviceNames []string
for key := range svcMap {
serviceNames = append(serviceNames, strconv.Quote(key))
}
// Sort the string array to generate consistent result
sort.Strings(serviceNames)
return strings.Join(serviceNames, ", ")
} | go | {
"resource": ""
} |
q10944 | NewInbound | train | func (t *ChannelTransport) NewInbound() *ChannelInbound {
return &ChannelInbound{
once: lifecycle.NewOnce(),
transport: t,
}
} | go | {
"resource": ""
} |
q10945 | ToBytes | train | func ToBytes(tracer opentracing.Tracer, spanContext opentracing.SpanContext, req *transport.Request) ([]byte, error) {
spanBytes, err := spanContextToBytes(tracer, spanContext)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(req.Body)
if err != nil {
return nil, err
}
rpc := internal.RPC{
SpanContext: spanBytes,
CallerName: req.Caller,
ServiceName: req.Service,
Encoding: string(req.Encoding),
Procedure: req.Procedure,
Headers: req.Headers.Items(),
ShardKey: &req.ShardKey,
RoutingKey: &req.RoutingKey,
RoutingDelegate: &req.RoutingDelegate,
Body: body,
}
wireValue, err := rpc.ToWire()
if err != nil {
return nil, err
}
var writer bytes.Buffer
// use the first byte to version the serialization
if err := writer.WriteByte(version); err != nil {
return nil, err
}
err = protocol.Binary.Encode(wireValue, &writer)
return writer.Bytes(), err
} | go | {
"resource": ""
} |
q10946 | FromBytes | train | func FromBytes(tracer opentracing.Tracer, request []byte) (opentracing.SpanContext, *transport.Request, error) {
if len(request) <= 1 {
return nil, nil, errors.New("cannot deserialize empty request")
}
// check valid thrift serialization byte
if request[0] != 0 {
return nil, nil,
fmt.Errorf(
"unsupported YARPC serialization version '%v' found during deserialization",
request[0])
}
reader := bytes.NewReader(request[1:])
wireValue, err := protocol.Binary.Decode(reader, wire.TStruct)
if err != nil {
return nil, nil, err
}
var rpc internal.RPC
if err = rpc.FromWire(wireValue); err != nil {
return nil, nil, err
}
req := transport.Request{
Caller: rpc.CallerName,
Service: rpc.ServiceName,
Encoding: transport.Encoding(rpc.Encoding),
Procedure: rpc.Procedure,
Headers: transport.HeadersFromMap(rpc.Headers),
Body: bytes.NewBuffer(rpc.Body),
}
if rpc.ShardKey != nil {
req.ShardKey = *rpc.ShardKey
}
if rpc.RoutingKey != nil {
req.RoutingKey = *rpc.RoutingKey
}
if rpc.RoutingDelegate != nil {
req.RoutingDelegate = *rpc.RoutingDelegate
}
spanContext, err := spanContextFromBytes(tracer, rpc.SpanContext)
if err != nil {
return nil, nil, err
}
return spanContext, &req, nil
} | go | {
"resource": ""
} |
q10947 | NewServerStream | train | func NewServerStream(s Stream, options ...ServerStreamOption) (*ServerStream, error) {
if s == nil {
return nil, yarpcerrors.InvalidArgumentErrorf("non-nil stream is required")
}
return &ServerStream{stream: s}, nil
} | go | {
"resource": ""
} |
q10948 | SendMessage | train | func (s *ServerStream) SendMessage(ctx context.Context, msg *StreamMessage) error {
return s.stream.SendMessage(ctx, msg)
} | go | {
"resource": ""
} |
q10949 | ReceiveMessage | train | func (s *ServerStream) ReceiveMessage(ctx context.Context) (*StreamMessage, error) {
return s.stream.ReceiveMessage(ctx)
} | go | {
"resource": ""
} |
q10950 | NewClientStream | train | func NewClientStream(s StreamCloser, options ...ClientStreamOption) (*ClientStream, error) {
if s == nil {
return nil, yarpcerrors.InvalidArgumentErrorf("non-nil stream with close is required")
}
return &ClientStream{stream: s}, nil
} | go | {
"resource": ""
} |
q10951 | Close | train | func (s *ClientStream) Close(ctx context.Context) error {
return s.stream.Close(ctx)
} | go | {
"resource": ""
} |
q10952 | String | train | func (v *EchoResponse) String() string {
if v == nil {
return "<nil>"
}
var fields [2]string
i := 0
fields[i] = fmt.Sprintf("Message: %v", v.Message)
i++
fields[i] = fmt.Sprintf("Count: %v", v.Count)
i++
return fmt.Sprintf("EchoResponse{%v}", strings.Join(fields[:i], ", "))
} | go | {
"resource": ""
} |
q10953 | Equals | train | func (v *EchoResponse) Equals(rhs *EchoResponse) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
if !(v.Message == rhs.Message) {
return false
}
if !(v.Count == rhs.Count) {
return false
}
return true
} | go | {
"resource": ""
} |
q10954 | MarshalLogObject | train | func (v *EchoResponse) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
enc.AddString("message", v.Message)
enc.AddInt16("count", v.Count)
return err
} | go | {
"resource": ""
} |
q10955 | fileDescriptorClosureVarName | train | func fileDescriptorClosureVarName(f *protoplugin.File) (string, error) {
name := f.GetName()
if name == "" {
return "", fmt.Errorf("could not create fileDescriptorClosureVarName: %s has no name", f)
}
// Use a sha256 of the filename instead of the filename to prevent any characters that are illegal
// as golang identifiers and to discourage external usage of this constant.
h := sha256.Sum256([]byte(name))
return fmt.Sprintf("yarpcFileDescriptorClosure%s", hex.EncodeToString(h[:8])), nil
} | go | {
"resource": ""
} |
q10956 | Wrap | train | func (c *ContextWrapper) Wrap(ctx context.Context) context.Context {
return metadata.NewOutgoingContext(ctx, c.md)
} | go | {
"resource": ""
} |
q10957 | WithHeader | train | func (c *ContextWrapper) WithHeader(key, value string) *ContextWrapper {
return c.copyAndAdd(key, value)
} | go | {
"resource": ""
} |
q10958 | String | train | func (v *SinkRequest) String() string {
if v == nil {
return "<nil>"
}
var fields [1]string
i := 0
fields[i] = fmt.Sprintf("Message: %v", v.Message)
i++
return fmt.Sprintf("SinkRequest{%v}", strings.Join(fields[:i], ", "))
} | go | {
"resource": ""
} |
q10959 | Equals | train | func (v *SinkRequest) Equals(rhs *SinkRequest) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
if !(v.Message == rhs.Message) {
return false
}
return true
} | go | {
"resource": ""
} |
q10960 | MarshalLogObject | train | func (v *SinkRequest) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
enc.AddString("message", v.Message)
return err
} | go | {
"resource": ""
} |
q10961 | Run | train | func Run(t crossdock.T) {
fatals := crossdock.Fatals(t)
server := t.Param(params.HTTPServer)
fatals.NotEmpty(server, "server is required")
httpTransport := http.NewTransport()
disp := yarpc.NewDispatcher(yarpc.Config{
Name: "client",
Outbounds: yarpc.Outbounds{
"yarpc-test": {
Unary: httpTransport.NewSingleOutbound(fmt.Sprintf("http://%s:8085", server)),
},
},
})
fatals.NoError(disp.Start(), "could not start Dispatcher")
defer disp.Stop()
runRaw(t, disp)
} | go | {
"resource": ""
} |
q10962 | runRaw | train | func runRaw(t crossdock.T, disp *yarpc.Dispatcher) {
assert := crossdock.Assert(t)
fatals := crossdock.Fatals(t)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
client := raw.New(disp.ClientConfig("yarpc-test"))
_, err := client.Call(ctx, "handlertimeout/raw", nil)
fatals.Error(err, "expected an error")
if yarpcerrors.FromError(err).Code() == yarpcerrors.CodeInvalidArgument {
t.Skipf("handlertimeout/raw method not implemented: %v", err)
return
}
assert.Equal(yarpcerrors.CodeDeadlineExceeded, yarpcerrors.FromError(err).Code(), "is an error with code CodeDeadlineExceeded: %v", err)
} | go | {
"resource": ""
} |
q10963 | BuildProcedures | train | func BuildProcedures(params BuildProceduresParams) []transport.Procedure {
procedures := make([]transport.Procedure, 0, 2*(len(params.UnaryHandlerParams)+len(params.OnewayHandlerParams)))
for _, unaryHandlerParams := range params.UnaryHandlerParams {
procedures = append(
procedures,
transport.Procedure{
Name: procedure.ToName(params.ServiceName, unaryHandlerParams.MethodName),
HandlerSpec: transport.NewUnaryHandlerSpec(unaryHandlerParams.Handler),
Encoding: Encoding,
},
transport.Procedure{
Name: procedure.ToName(params.ServiceName, unaryHandlerParams.MethodName),
HandlerSpec: transport.NewUnaryHandlerSpec(unaryHandlerParams.Handler),
Encoding: JSONEncoding,
},
)
}
for _, onewayHandlerParams := range params.OnewayHandlerParams {
procedures = append(
procedures,
transport.Procedure{
Name: procedure.ToName(params.ServiceName, onewayHandlerParams.MethodName),
HandlerSpec: transport.NewOnewayHandlerSpec(onewayHandlerParams.Handler),
Encoding: Encoding,
},
transport.Procedure{
Name: procedure.ToName(params.ServiceName, onewayHandlerParams.MethodName),
HandlerSpec: transport.NewOnewayHandlerSpec(onewayHandlerParams.Handler),
Encoding: JSONEncoding,
},
)
}
for _, streamHandlerParams := range params.StreamHandlerParams {
procedures = append(
procedures,
transport.Procedure{
Name: procedure.ToName(params.ServiceName, streamHandlerParams.MethodName),
HandlerSpec: transport.NewStreamHandlerSpec(streamHandlerParams.Handler),
Encoding: Encoding,
},
transport.Procedure{
Name: procedure.ToName(params.ServiceName, streamHandlerParams.MethodName),
HandlerSpec: transport.NewStreamHandlerSpec(streamHandlerParams.Handler),
Encoding: JSONEncoding,
},
)
}
return procedures
} | go | {
"resource": ""
} |
q10964 | NewStreamClient | train | func NewStreamClient(params ClientParams) StreamClient {
return newClient(params.ServiceName, params.ClientConfig, params.Options...)
} | go | {
"resource": ""
} |
q10965 | NewUnaryHandler | train | func NewUnaryHandler(params UnaryHandlerParams) transport.UnaryHandler {
return newUnaryHandler(params.Handle, params.NewRequest)
} | go | {
"resource": ""
} |
q10966 | NewOnewayHandler | train | func NewOnewayHandler(params OnewayHandlerParams) transport.OnewayHandler {
return newOnewayHandler(params.Handle, params.NewRequest)
} | go | {
"resource": ""
} |
q10967 | ClientBuilderOptions | train | func ClientBuilderOptions(_ transport.ClientConfig, structField reflect.StructField) []ClientOption {
var opts []ClientOption
for _, opt := range uniqueLowercaseStrings(strings.Split(structField.Tag.Get("proto"), ",")) {
switch opt {
case "json":
opts = append(opts, UseJSON)
}
}
return opts
} | go | {
"resource": ""
} |
q10968 | CastError | train | func CastError(expectedType proto.Message, actualType proto.Message) error {
return yarpcerrors.Newf(yarpcerrors.CodeInternal, "expected proto.Message to have type %T but had type %T", expectedType, actualType)
} | go | {
"resource": ""
} |
q10969 | Receive | train | func (c *ClientStream) Receive(newMessage func() proto.Message, options ...yarpc.StreamOption) (proto.Message, error) {
return readFromStream(context.Background(), c.stream, newMessage)
} | go | {
"resource": ""
} |
q10970 | Send | train | func (c *ClientStream) Send(message proto.Message, options ...yarpc.StreamOption) error {
return writeToStream(context.Background(), c.stream, message)
} | go | {
"resource": ""
} |
q10971 | Close | train | func (c *ClientStream) Close(options ...yarpc.StreamOption) error {
return c.stream.Close(context.Background())
} | go | {
"resource": ""
} |
q10972 | Receive | train | func (s *ServerStream) Receive(newMessage func() proto.Message, options ...yarpc.StreamOption) (proto.Message, error) {
return readFromStream(context.Background(), s.stream, newMessage)
} | go | {
"resource": ""
} |
q10973 | Send | train | func (s *ServerStream) Send(message proto.Message, options ...yarpc.StreamOption) error {
return writeToStream(context.Background(), s.stream, message)
} | go | {
"resource": ""
} |
q10974 | Expand | train | func Expand(s string) string {
lines := strings.Split(s, "\n")
for i, l := range lines {
lines[i] = expandLine(l)
}
return strings.Join(lines, "\n")
} | go | {
"resource": ""
} |
q10975 | NewEchoYARPCClient | train | func NewEchoYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) EchoYARPCClient {
return &_EchoYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.crossdock.Echo",
ClientConfig: clientConfig,
Options: options,
},
)}
} | go | {
"resource": ""
} |
q10976 | BuildEchoYARPCProcedures | train | func BuildEchoYARPCProcedures(server EchoYARPCServer) []transport.Procedure {
handler := &_EchoYARPCHandler{server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.crossdock.Echo",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{
{
MethodName: "Echo",
Handler: protobuf.NewUnaryHandler(
protobuf.UnaryHandlerParams{
Handle: handler.Echo,
NewRequest: newEchoServiceEchoYARPCRequest,
},
),
},
},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{},
},
)
} | go | {
"resource": ""
} |
q10977 | NewOnewayYARPCClient | train | func NewOnewayYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) OnewayYARPCClient {
return &_OnewayYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.crossdock.Oneway",
ClientConfig: clientConfig,
Options: options,
},
)}
} | go | {
"resource": ""
} |
q10978 | BuildOnewayYARPCProcedures | train | func BuildOnewayYARPCProcedures(server OnewayYARPCServer) []transport.Procedure {
handler := &_OnewayYARPCHandler{server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.crossdock.Oneway",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{
{
MethodName: "Echo",
Handler: protobuf.NewOnewayHandler(
protobuf.OnewayHandlerParams{
Handle: handler.Echo,
NewRequest: newOnewayServiceEchoYARPCRequest,
},
),
},
},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{},
},
)
} | go | {
"resource": ""
} |
q10979 | BadResponse | train | func BadResponse(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error) {
// func is not serializable
result := map[string]interface{}{"foo": func() {}}
return result, nil
} | go | {
"resource": ""
} |
q10980 | callHome | train | func (o *onewayHandler) callHome(ctx context.Context, callBackAddr string, body []byte, encoding transport.Encoding) {
// reduce the chance of a race condition
time.Sleep(time.Millisecond * 100)
if callBackAddr == "" {
panic("could not find callBackAddr in headers")
}
out := o.httpTransport.NewSingleOutbound("http://" + callBackAddr)
if err := out.Start(); err != nil {
panic(fmt.Sprintf("could not start outbound: %s", err))
}
defer out.Stop()
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
_, err := out.CallOneway(ctx, &transport.Request{
Caller: "oneway-server",
Service: "oneway-client",
Procedure: "call-back",
Encoding: raw.Encoding,
Body: bytes.NewReader(body),
})
if err != nil {
panic(fmt.Sprintf("could not make call back to client: %s", err))
}
} | go | {
"resource": ""
} |
q10981 | ApplyRouteTable | train | func ApplyRouteTable(r transport.RouteTable, m Router) transport.RouteTable {
if m == nil {
return r
}
return routeTableWithMiddleware{r: r, m: m}
} | go | {
"resource": ""
} |
q10982 | TransportSpec | train | func TransportSpec(opts ...Option) yarpcconfig.TransportSpec {
var ts transportSpec
for _, o := range opts {
switch opt := o.(type) {
case TransportOption:
ts.TransportOptions = append(ts.TransportOptions, opt)
case InboundOption:
ts.InboundOptions = append(ts.InboundOptions, opt)
case OutboundOption:
ts.OutboundOptions = append(ts.OutboundOptions, opt)
default:
panic(fmt.Sprintf("unknown option of type %T: %v", o, o))
}
}
return ts.Spec()
} | go | {
"resource": ""
} |
q10983 | NewPool | train | func NewPool(opts ...Option) *Pool {
pool := &Pool{}
for _, opt := range opts {
opt(pool)
}
return pool
} | go | {
"resource": ""
} |
q10984 | Get | train | func (p *Pool) Get() *Buffer {
buf, ok := p.pool.Get().(*Buffer)
if !ok {
buf = newBuffer(p)
} else {
buf.reuse()
}
return buf
} | go | {
"resource": ""
} |
q10985 | ResponseHeaders | train | func ResponseHeaders(h *map[string]string) CallOption {
return CallOption{func(o *OutboundCall) { o.responseHeaders = h }}
} | go | {
"resource": ""
} |
q10986 | WithHeader | train | func WithHeader(k, v string) CallOption {
return CallOption{func(o *OutboundCall) {
o.headers = append(o.headers, keyValuePair{k: k, v: v})
}}
} | go | {
"resource": ""
} |
q10987 | WithShardKey | train | func WithShardKey(sk string) CallOption {
return CallOption{func(o *OutboundCall) { o.shardKey = &sk }}
} | go | {
"resource": ""
} |
q10988 | WithRoutingKey | train | func WithRoutingKey(rk string) CallOption {
return CallOption{func(o *OutboundCall) { o.routingKey = &rk }}
} | go | {
"resource": ""
} |
q10989 | WithRoutingDelegate | train | func WithRoutingDelegate(rd string) CallOption {
return CallOption{func(o *OutboundCall) { o.routingDelegate = &rd }}
} | go | {
"resource": ""
} |
q10990 | JSONForTransport | train | func JSONForTransport(t crossdock.T, transport string) {
t = createEchoT("json", transport, t)
fatals := crossdock.Fatals(t)
dispatcher := disp.CreateDispatcherForTransport(t, transport)
fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
defer dispatcher.Stop()
client := json.New(dispatcher.ClientConfig("yarpc-test"))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
var response jsonEcho
token := random.String(5)
err := client.Call(ctx, "echo", &jsonEcho{Token: token}, &response)
crossdock.Fatals(t).NoError(err, "call to echo failed: %v", err)
crossdock.Assert(t).Equal(token, response.Token, "server said: %v", response.Token)
} | go | {
"resource": ""
} |
q10991 | String | train | func (v *Hello_Sink_Args) String() string {
if v == nil {
return "<nil>"
}
var fields [1]string
i := 0
if v.Snk != nil {
fields[i] = fmt.Sprintf("Snk: %v", v.Snk)
i++
}
return fmt.Sprintf("Hello_Sink_Args{%v}", strings.Join(fields[:i], ", "))
} | go | {
"resource": ""
} |
q10992 | Equals | train | func (v *Hello_Sink_Args) Equals(rhs *Hello_Sink_Args) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
if !((v.Snk == nil && rhs.Snk == nil) || (v.Snk != nil && rhs.Snk != nil && v.Snk.Equals(rhs.Snk))) {
return false
}
return true
} | go | {
"resource": ""
} |
q10993 | MarshalLogObject | train | func (v *Hello_Sink_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
if v.Snk != nil {
err = multierr.Append(err, enc.AddObject("snk", v.Snk))
}
return err
} | go | {
"resource": ""
} |
q10994 | GetSnk | train | func (v *Hello_Sink_Args) GetSnk() (o *SinkRequest) {
if v != nil && v.Snk != nil {
return v.Snk
}
return
} | go | {
"resource": ""
} |
q10995 | PopString | train | func (m AttributeMap) PopString(name string) (string, error) {
var s string
_, err := m.Pop(name, &s)
return s, err
} | go | {
"resource": ""
} |
q10996 | PopBool | train | func (m AttributeMap) PopBool(name string) (bool, error) {
var b bool
_, err := m.Pop(name, &b)
return b, err
} | go | {
"resource": ""
} |
q10997 | Pop | train | func (m AttributeMap) Pop(name string, dst interface{}, opts ...mapdecode.Option) (bool, error) {
ok, err := m.Get(name, dst, opts...)
if ok {
delete(m, name)
}
return ok, err
} | go | {
"resource": ""
} |
q10998 | Get | train | func (m AttributeMap) Get(name string, dst interface{}, opts ...mapdecode.Option) (bool, error) {
v, ok := m[name]
if !ok {
return ok, nil
}
err := DecodeInto(dst, v, opts...)
if err != nil {
err = fmt.Errorf("failed to read attribute %q: %v. got error: %s", name, v, err)
}
return true, err
} | go | {
"resource": ""
} |
q10999 | Keys | train | func (m AttributeMap) Keys() []string {
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
return keys
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.