id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
10,400
mdlayher/vsock
vsock.go
Listen
func Listen(port uint32) (*Listener, error) { cid, err := ContextID() if err != nil { // No addresses available. return nil, opError(opListen, err, nil, nil) } l, err := listen(cid, port) if err != nil { // No remote address available. return nil, opError(opListen, err, &Addr{ ContextID: cid, Port: port, }, nil) } return l, nil }
go
func Listen(port uint32) (*Listener, error) { cid, err := ContextID() if err != nil { // No addresses available. return nil, opError(opListen, err, nil, nil) } l, err := listen(cid, port) if err != nil { // No remote address available. return nil, opError(opListen, err, &Addr{ ContextID: cid, Port: port, }, nil) } return l, nil }
[ "func", "Listen", "(", "port", "uint32", ")", "(", "*", "Listener", ",", "error", ")", "{", "cid", ",", "err", ":=", "ContextID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// No addresses available.", "return", "nil", ",", "opError", "(", "opListen", ",", "err", ",", "nil", ",", "nil", ")", "\n", "}", "\n\n", "l", ",", "err", ":=", "listen", "(", "cid", ",", "port", ")", "\n", "if", "err", "!=", "nil", "{", "// No remote address available.", "return", "nil", ",", "opError", "(", "opListen", ",", "err", ",", "&", "Addr", "{", "ContextID", ":", "cid", ",", "Port", ":", "port", ",", "}", ",", "nil", ")", "\n", "}", "\n\n", "return", "l", ",", "nil", "\n", "}" ]
// Listen opens a connection-oriented net.Listener for incoming VM sockets // connections. The port parameter specifies the port for the Listener. // // To allow the server to assign a port automatically, specify 0 for port. // The address of the server can be retrieved using the Addr method. // // When the Listener is no longer needed, Close must be called to free resources.
[ "Listen", "opens", "a", "connection", "-", "oriented", "net", ".", "Listener", "for", "incoming", "VM", "sockets", "connections", ".", "The", "port", "parameter", "specifies", "the", "port", "for", "the", "Listener", ".", "To", "allow", "the", "server", "to", "assign", "a", "port", "automatically", "specify", "0", "for", "port", ".", "The", "address", "of", "the", "server", "can", "be", "retrieved", "using", "the", "Addr", "method", ".", "When", "the", "Listener", "is", "no", "longer", "needed", "Close", "must", "be", "called", "to", "free", "resources", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L65-L82
10,401
mdlayher/vsock
vsock.go
Close
func (l *Listener) Close() error { return l.opError(opClose, l.l.Close()) }
go
func (l *Listener) Close() error { return l.opError(opClose, l.l.Close()) }
[ "func", "(", "l", "*", "Listener", ")", "Close", "(", ")", "error", "{", "return", "l", ".", "opError", "(", "opClose", ",", "l", ".", "l", ".", "Close", "(", ")", ")", "\n", "}" ]
// Close stops listening on the VM sockets address. Already Accepted connections // are not closed.
[ "Close", "stops", "listening", "on", "the", "VM", "sockets", "address", ".", "Already", "Accepted", "connections", "are", "not", "closed", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L109-L111
10,402
mdlayher/vsock
vsock.go
SetDeadline
func (l *Listener) SetDeadline(t time.Time) error { return l.opError(opSet, l.l.SetDeadline(t)) }
go
func (l *Listener) SetDeadline(t time.Time) error { return l.opError(opSet, l.l.SetDeadline(t)) }
[ "func", "(", "l", "*", "Listener", ")", "SetDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "return", "l", ".", "opError", "(", "opSet", ",", "l", ".", "l", ".", "SetDeadline", "(", "t", ")", ")", "\n", "}" ]
// SetDeadline sets the deadline associated with the listener. A zero time value // disables the deadline. // // SetDeadline only works with Go 1.12+.
[ "SetDeadline", "sets", "the", "deadline", "associated", "with", "the", "listener", ".", "A", "zero", "time", "value", "disables", "the", "deadline", ".", "SetDeadline", "only", "works", "with", "Go", "1", ".", "12", "+", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L117-L119
10,403
mdlayher/vsock
vsock.go
opError
func (l *Listener) opError(op string, err error) error { // No remote address for a Listener. return opError(op, err, l.Addr(), nil) }
go
func (l *Listener) opError(op string, err error) error { // No remote address for a Listener. return opError(op, err, l.Addr(), nil) }
[ "func", "(", "l", "*", "Listener", ")", "opError", "(", "op", "string", ",", "err", "error", ")", "error", "{", "// No remote address for a Listener.", "return", "opError", "(", "op", ",", "err", ",", "l", ".", "Addr", "(", ")", ",", "nil", ")", "\n", "}" ]
// opError is a convenience for the function opError that also passes the local // address of the Listener.
[ "opError", "is", "a", "convenience", "for", "the", "function", "opError", "that", "also", "passes", "the", "local", "address", "of", "the", "Listener", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L123-L126
10,404
mdlayher/vsock
vsock.go
Dial
func Dial(contextID, port uint32) (*Conn, error) { c, err := dial(contextID, port) if err != nil { // No local address, but we have a remote address we can return. return nil, opError(opDial, err, nil, &Addr{ ContextID: contextID, Port: port, }) } return c, nil }
go
func Dial(contextID, port uint32) (*Conn, error) { c, err := dial(contextID, port) if err != nil { // No local address, but we have a remote address we can return. return nil, opError(opDial, err, nil, &Addr{ ContextID: contextID, Port: port, }) } return c, nil }
[ "func", "Dial", "(", "contextID", ",", "port", "uint32", ")", "(", "*", "Conn", ",", "error", ")", "{", "c", ",", "err", ":=", "dial", "(", "contextID", ",", "port", ")", "\n", "if", "err", "!=", "nil", "{", "// No local address, but we have a remote address we can return.", "return", "nil", ",", "opError", "(", "opDial", ",", "err", ",", "nil", ",", "&", "Addr", "{", "ContextID", ":", "contextID", ",", "Port", ":", "port", ",", "}", ")", "\n", "}", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// Dial dials a connection-oriented net.Conn to a VM sockets server. // The contextID and port parameters specify the address of the server. // // If dialing a connection from the hypervisor to a virtual machine, the VM's // context ID should be specified. // // If dialing from a VM to the hypervisor, Hypervisor should be used to // communicate with the hypervisor process, or Host should be used to // communicate with other processes on the host machine. // // When the connection is no longer needed, Close must be called to free resources.
[ "Dial", "dials", "a", "connection", "-", "oriented", "net", ".", "Conn", "to", "a", "VM", "sockets", "server", ".", "The", "contextID", "and", "port", "parameters", "specify", "the", "address", "of", "the", "server", ".", "If", "dialing", "a", "connection", "from", "the", "hypervisor", "to", "a", "virtual", "machine", "the", "VM", "s", "context", "ID", "should", "be", "specified", ".", "If", "dialing", "from", "a", "VM", "to", "the", "hypervisor", "Hypervisor", "should", "be", "used", "to", "communicate", "with", "the", "hypervisor", "process", "or", "Host", "should", "be", "used", "to", "communicate", "with", "other", "processes", "on", "the", "host", "machine", ".", "When", "the", "connection", "is", "no", "longer", "needed", "Close", "must", "be", "called", "to", "free", "resources", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L139-L150
10,405
mdlayher/vsock
vsock.go
CloseRead
func (c *Conn) CloseRead() error { return c.opError(opClose, c.fd.Shutdown(shutRd)) }
go
func (c *Conn) CloseRead() error { return c.opError(opClose, c.fd.Shutdown(shutRd)) }
[ "func", "(", "c", "*", "Conn", ")", "CloseRead", "(", ")", "error", "{", "return", "c", ".", "opError", "(", "opClose", ",", "c", ".", "fd", ".", "Shutdown", "(", "shutRd", ")", ")", "\n", "}" ]
// CloseRead shuts down the reading side of the VM sockets connection. Most // callers should just use Close. // // CloseRead only works with Go 1.12+.
[ "CloseRead", "shuts", "down", "the", "reading", "side", "of", "the", "VM", "sockets", "connection", ".", "Most", "callers", "should", "just", "use", "Close", ".", "CloseRead", "only", "works", "with", "Go", "1", ".", "12", "+", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L171-L173
10,406
mdlayher/vsock
vsock.go
CloseWrite
func (c *Conn) CloseWrite() error { return c.opError(opClose, c.fd.Shutdown(shutWr)) }
go
func (c *Conn) CloseWrite() error { return c.opError(opClose, c.fd.Shutdown(shutWr)) }
[ "func", "(", "c", "*", "Conn", ")", "CloseWrite", "(", ")", "error", "{", "return", "c", ".", "opError", "(", "opClose", ",", "c", ".", "fd", ".", "Shutdown", "(", "shutWr", ")", ")", "\n", "}" ]
// CloseWrite shuts down the writing side of the VM sockets connection. Most // callers should just use Close. // // CloseWrite only works with Go 1.12+.
[ "CloseWrite", "shuts", "down", "the", "writing", "side", "of", "the", "VM", "sockets", "connection", ".", "Most", "callers", "should", "just", "use", "Close", ".", "CloseWrite", "only", "works", "with", "Go", "1", ".", "12", "+", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L179-L181
10,407
mdlayher/vsock
vsock.go
SyscallConn
func (c *Conn) SyscallConn() (syscall.RawConn, error) { rc, err := c.fd.SyscallConn() if err != nil { return nil, c.opError(opSyscallConn, err) } return &rawConn{ rc: rc, local: c.local, remote: c.remote, }, nil }
go
func (c *Conn) SyscallConn() (syscall.RawConn, error) { rc, err := c.fd.SyscallConn() if err != nil { return nil, c.opError(opSyscallConn, err) } return &rawConn{ rc: rc, local: c.local, remote: c.remote, }, nil }
[ "func", "(", "c", "*", "Conn", ")", "SyscallConn", "(", ")", "(", "syscall", ".", "RawConn", ",", "error", ")", "{", "rc", ",", "err", ":=", "c", ".", "fd", ".", "SyscallConn", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "c", ".", "opError", "(", "opSyscallConn", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "rawConn", "{", "rc", ":", "rc", ",", "local", ":", "c", ".", "local", ",", "remote", ":", "c", ".", "remote", ",", "}", ",", "nil", "\n", "}" ]
// SyscallConn returns a raw network connection. This implements the // syscall.Conn interface.
[ "SyscallConn", "returns", "a", "raw", "network", "connection", ".", "This", "implements", "the", "syscall", ".", "Conn", "interface", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L238-L249
10,408
mdlayher/vsock
vsock.go
opError
func (c *Conn) opError(op string, err error) error { return opError(op, err, c.local, c.remote) }
go
func (c *Conn) opError(op string, err error) error { return opError(op, err, c.local, c.remote) }
[ "func", "(", "c", "*", "Conn", ")", "opError", "(", "op", "string", ",", "err", "error", ")", "error", "{", "return", "opError", "(", "op", ",", "err", ",", "c", ".", "local", ",", "c", ".", "remote", ")", "\n", "}" ]
// opError is a convenience for the function opError that also passes the local // and remote addresses of the Conn.
[ "opError", "is", "a", "convenience", "for", "the", "function", "opError", "that", "also", "passes", "the", "local", "and", "remote", "addresses", "of", "the", "Conn", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L253-L255
10,409
mdlayher/vsock
vsock.go
Control
func (rc *rawConn) Control(fn func(fd uintptr)) error { return rc.opError(opRawControl, rc.rc.Control(fn)) }
go
func (rc *rawConn) Control(fn func(fd uintptr)) error { return rc.opError(opRawControl, rc.rc.Control(fn)) }
[ "func", "(", "rc", "*", "rawConn", ")", "Control", "(", "fn", "func", "(", "fd", "uintptr", ")", ")", "error", "{", "return", "rc", ".", "opError", "(", "opRawControl", ",", "rc", ".", "rc", ".", "Control", "(", "fn", ")", ")", "\n", "}" ]
// Control implements the syscall.RawConn Control method.
[ "Control", "implements", "the", "syscall", ".", "RawConn", "Control", "method", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L268-L270
10,410
mdlayher/vsock
vsock.go
Read
func (rc *rawConn) Read(fn func(fd uintptr) (done bool)) error { return rc.opError(opRawRead, rc.rc.Read(fn)) }
go
func (rc *rawConn) Read(fn func(fd uintptr) (done bool)) error { return rc.opError(opRawRead, rc.rc.Read(fn)) }
[ "func", "(", "rc", "*", "rawConn", ")", "Read", "(", "fn", "func", "(", "fd", "uintptr", ")", "(", "done", "bool", ")", ")", "error", "{", "return", "rc", ".", "opError", "(", "opRawRead", ",", "rc", ".", "rc", ".", "Read", "(", "fn", ")", ")", "\n", "}" ]
// Control implements the syscall.RawConn Read method.
[ "Control", "implements", "the", "syscall", ".", "RawConn", "Read", "method", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L273-L275
10,411
mdlayher/vsock
vsock.go
Write
func (rc *rawConn) Write(fn func(fd uintptr) (done bool)) error { return rc.opError(opRawWrite, rc.rc.Write(fn)) }
go
func (rc *rawConn) Write(fn func(fd uintptr) (done bool)) error { return rc.opError(opRawWrite, rc.rc.Write(fn)) }
[ "func", "(", "rc", "*", "rawConn", ")", "Write", "(", "fn", "func", "(", "fd", "uintptr", ")", "(", "done", "bool", ")", ")", "error", "{", "return", "rc", ".", "opError", "(", "opRawWrite", ",", "rc", ".", "rc", ".", "Write", "(", "fn", ")", ")", "\n", "}" ]
// Control implements the syscall.RawConn Write method.
[ "Control", "implements", "the", "syscall", ".", "RawConn", "Write", "method", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L278-L280
10,412
mdlayher/vsock
vsock.go
opError
func (rc *rawConn) opError(op string, err error) error { return opError(op, err, rc.local, rc.remote) }
go
func (rc *rawConn) opError(op string, err error) error { return opError(op, err, rc.local, rc.remote) }
[ "func", "(", "rc", "*", "rawConn", ")", "opError", "(", "op", "string", ",", "err", "error", ")", "error", "{", "return", "opError", "(", "op", ",", "err", ",", "rc", ".", "local", ",", "rc", ".", "remote", ")", "\n", "}" ]
// opError is a convenience for the function opError that also passes the local // and remote addresses of the rawConn.
[ "opError", "is", "a", "convenience", "for", "the", "function", "opError", "that", "also", "passes", "the", "local", "and", "remote", "addresses", "of", "the", "rawConn", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L284-L286
10,413
mdlayher/vsock
vsock.go
String
func (a *Addr) String() string { var host string switch a.ContextID { case Hypervisor: host = fmt.Sprintf("hypervisor(%d)", a.ContextID) case cidReserved: host = fmt.Sprintf("reserved(%d)", a.ContextID) case Host: host = fmt.Sprintf("host(%d)", a.ContextID) default: host = fmt.Sprintf("vm(%d)", a.ContextID) } return fmt.Sprintf("%s:%d", host, a.Port) }
go
func (a *Addr) String() string { var host string switch a.ContextID { case Hypervisor: host = fmt.Sprintf("hypervisor(%d)", a.ContextID) case cidReserved: host = fmt.Sprintf("reserved(%d)", a.ContextID) case Host: host = fmt.Sprintf("host(%d)", a.ContextID) default: host = fmt.Sprintf("vm(%d)", a.ContextID) } return fmt.Sprintf("%s:%d", host, a.Port) }
[ "func", "(", "a", "*", "Addr", ")", "String", "(", ")", "string", "{", "var", "host", "string", "\n\n", "switch", "a", ".", "ContextID", "{", "case", "Hypervisor", ":", "host", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "ContextID", ")", "\n", "case", "cidReserved", ":", "host", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "ContextID", ")", "\n", "case", "Host", ":", "host", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "ContextID", ")", "\n", "default", ":", "host", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "ContextID", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "host", ",", "a", ".", "Port", ")", "\n", "}" ]
// String returns a human-readable representation of Addr, and indicates if // ContextID is meant to be used for a hypervisor, host, VM, etc.
[ "String", "returns", "a", "human", "-", "readable", "representation", "of", "Addr", "and", "indicates", "if", "ContextID", "is", "meant", "to", "be", "used", "for", "a", "hypervisor", "host", "VM", "etc", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L301-L316
10,414
mdlayher/vsock
vsock.go
fileName
func (a *Addr) fileName() string { return fmt.Sprintf("%s:%s", a.Network(), a.String()) }
go
func (a *Addr) fileName() string { return fmt.Sprintf("%s:%s", a.Network(), a.String()) }
[ "func", "(", "a", "*", "Addr", ")", "fileName", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ".", "Network", "(", ")", ",", "a", ".", "String", "(", ")", ")", "\n", "}" ]
// fileName returns a file name for use with os.NewFile for Addr.
[ "fileName", "returns", "a", "file", "name", "for", "use", "with", "os", ".", "NewFile", "for", "Addr", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L319-L321
10,415
mdlayher/vsock
vsock.go
opError
func opError(op string, err error, local, remote net.Addr) error { if err == nil { return nil } // Unwrap inner errors from error types. // // TODO(mdlayher): errors.Cause or similar in Go 1.13. switch xerr := err.(type) { // os.PathError produced by os.File method calls. case *os.PathError: // Although we could make use of xerr.Op here, we're passing it manually // for consistency, since some of the Conn calls we are making don't // wrap an os.File, which would return an Op for us. // // As a special case, if the error is related to access to the /dev/vsock // device, we don't unwrap it, so the caller has more context as to why // their operation actually failed than "permission denied" or similar. if xerr.Path != devVsock { err = xerr.Err } } switch { case err == io.EOF, isErrno(err, enotconn): // We may see a literal io.EOF as happens with x/net/nettest, but // "transport not connected" also means io.EOF in Go. return io.EOF case err == os.ErrClosed, isErrno(err, ebadf), strings.Contains(err.Error(), "use of closed"): // Different operations may return different errors that all effectively // indicate a closed file. // // To rectify the differences, net.TCPConn uses an error with this text // from internal/poll for the backing file already being closed. err = errors.New("use of closed network connection") default: // Nothing to do, return this directly. } // Determine source and addr using the rules defined by net.OpError's // documentation: https://golang.org/pkg/net/#OpError. var source, addr net.Addr switch op { case opClose, opDial, opRawRead, opRawWrite, opRead, opWrite: if local != nil { source = local } if remote != nil { addr = remote } case opAccept, opListen, opRawControl, opSet, opSyscallConn: if local != nil { addr = local } } return &net.OpError{ Op: op, Net: network, Source: source, Addr: addr, Err: err, } }
go
func opError(op string, err error, local, remote net.Addr) error { if err == nil { return nil } // Unwrap inner errors from error types. // // TODO(mdlayher): errors.Cause or similar in Go 1.13. switch xerr := err.(type) { // os.PathError produced by os.File method calls. case *os.PathError: // Although we could make use of xerr.Op here, we're passing it manually // for consistency, since some of the Conn calls we are making don't // wrap an os.File, which would return an Op for us. // // As a special case, if the error is related to access to the /dev/vsock // device, we don't unwrap it, so the caller has more context as to why // their operation actually failed than "permission denied" or similar. if xerr.Path != devVsock { err = xerr.Err } } switch { case err == io.EOF, isErrno(err, enotconn): // We may see a literal io.EOF as happens with x/net/nettest, but // "transport not connected" also means io.EOF in Go. return io.EOF case err == os.ErrClosed, isErrno(err, ebadf), strings.Contains(err.Error(), "use of closed"): // Different operations may return different errors that all effectively // indicate a closed file. // // To rectify the differences, net.TCPConn uses an error with this text // from internal/poll for the backing file already being closed. err = errors.New("use of closed network connection") default: // Nothing to do, return this directly. } // Determine source and addr using the rules defined by net.OpError's // documentation: https://golang.org/pkg/net/#OpError. var source, addr net.Addr switch op { case opClose, opDial, opRawRead, opRawWrite, opRead, opWrite: if local != nil { source = local } if remote != nil { addr = remote } case opAccept, opListen, opRawControl, opSet, opSyscallConn: if local != nil { addr = local } } return &net.OpError{ Op: op, Net: network, Source: source, Addr: addr, Err: err, } }
[ "func", "opError", "(", "op", "string", ",", "err", "error", ",", "local", ",", "remote", "net", ".", "Addr", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "// Unwrap inner errors from error types.", "//", "// TODO(mdlayher): errors.Cause or similar in Go 1.13.", "switch", "xerr", ":=", "err", ".", "(", "type", ")", "{", "// os.PathError produced by os.File method calls.", "case", "*", "os", ".", "PathError", ":", "// Although we could make use of xerr.Op here, we're passing it manually", "// for consistency, since some of the Conn calls we are making don't", "// wrap an os.File, which would return an Op for us.", "//", "// As a special case, if the error is related to access to the /dev/vsock", "// device, we don't unwrap it, so the caller has more context as to why", "// their operation actually failed than \"permission denied\" or similar.", "if", "xerr", ".", "Path", "!=", "devVsock", "{", "err", "=", "xerr", ".", "Err", "\n", "}", "\n", "}", "\n\n", "switch", "{", "case", "err", "==", "io", ".", "EOF", ",", "isErrno", "(", "err", ",", "enotconn", ")", ":", "// We may see a literal io.EOF as happens with x/net/nettest, but", "// \"transport not connected\" also means io.EOF in Go.", "return", "io", ".", "EOF", "\n", "case", "err", "==", "os", ".", "ErrClosed", ",", "isErrno", "(", "err", ",", "ebadf", ")", ",", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", ":", "// Different operations may return different errors that all effectively", "// indicate a closed file.", "//", "// To rectify the differences, net.TCPConn uses an error with this text", "// from internal/poll for the backing file already being closed.", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "default", ":", "// Nothing to do, return this directly.", "}", "\n\n", "// Determine source and addr using the rules defined by net.OpError's", "// documentation: https://golang.org/pkg/net/#OpError.", "var", "source", ",", "addr", "net", ".", "Addr", "\n", "switch", "op", "{", "case", "opClose", ",", "opDial", ",", "opRawRead", ",", "opRawWrite", ",", "opRead", ",", "opWrite", ":", "if", "local", "!=", "nil", "{", "source", "=", "local", "\n", "}", "\n", "if", "remote", "!=", "nil", "{", "addr", "=", "remote", "\n", "}", "\n", "case", "opAccept", ",", "opListen", ",", "opRawControl", ",", "opSet", ",", "opSyscallConn", ":", "if", "local", "!=", "nil", "{", "addr", "=", "local", "\n", "}", "\n", "}", "\n\n", "return", "&", "net", ".", "OpError", "{", "Op", ":", "op", ",", "Net", ":", "network", ",", "Source", ":", "source", ",", "Addr", ":", "addr", ",", "Err", ":", "err", ",", "}", "\n", "}" ]
// opError unpacks err if possible, producing a net.OpError with the input // parameters in order to implement net.Conn. As a convenience, opError returns // nil if the input error is nil.
[ "opError", "unpacks", "err", "if", "possible", "producing", "a", "net", ".", "OpError", "with", "the", "input", "parameters", "in", "order", "to", "implement", "net", ".", "Conn", ".", "As", "a", "convenience", "opError", "returns", "nil", "if", "the", "input", "error", "is", "nil", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/vsock.go#L336-L399
10,416
mdlayher/vsock
listener_linux.go
Accept
func (l *listener) Accept() (net.Conn, error) { cfd, sa, err := l.fd.Accept4(0) if err != nil { return nil, err } savm := sa.(*unix.SockaddrVM) remote := &Addr{ ContextID: savm.CID, Port: savm.Port, } return newConn(cfd, l.addr, remote) }
go
func (l *listener) Accept() (net.Conn, error) { cfd, sa, err := l.fd.Accept4(0) if err != nil { return nil, err } savm := sa.(*unix.SockaddrVM) remote := &Addr{ ContextID: savm.CID, Port: savm.Port, } return newConn(cfd, l.addr, remote) }
[ "func", "(", "l", "*", "listener", ")", "Accept", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "cfd", ",", "sa", ",", "err", ":=", "l", ".", "fd", ".", "Accept4", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "savm", ":=", "sa", ".", "(", "*", "unix", ".", "SockaddrVM", ")", "\n", "remote", ":=", "&", "Addr", "{", "ContextID", ":", "savm", ".", "CID", ",", "Port", ":", "savm", ".", "Port", ",", "}", "\n\n", "return", "newConn", "(", "cfd", ",", "l", ".", "addr", ",", "remote", ")", "\n", "}" ]
// Accept accepts a single connection from the listener, and sets up // a net.Conn backed by conn.
[ "Accept", "accepts", "a", "single", "connection", "from", "the", "listener", "and", "sets", "up", "a", "net", ".", "Conn", "backed", "by", "conn", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/listener_linux.go#L28-L41
10,417
mdlayher/vsock
listener_linux.go
listen
func listen(cid, port uint32) (*Listener, error) { lfd, err := newListenFD() if err != nil { return nil, err } return listenLinux(lfd, cid, port) }
go
func listen(cid, port uint32) (*Listener, error) { lfd, err := newListenFD() if err != nil { return nil, err } return listenLinux(lfd, cid, port) }
[ "func", "listen", "(", "cid", ",", "port", "uint32", ")", "(", "*", "Listener", ",", "error", ")", "{", "lfd", ",", "err", ":=", "newListenFD", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "listenLinux", "(", "lfd", ",", "cid", ",", "port", ")", "\n", "}" ]
// listen is the entry point for Listen on Linux.
[ "listen", "is", "the", "entry", "point", "for", "Listen", "on", "Linux", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/listener_linux.go#L44-L51
10,418
mdlayher/vsock
listener_linux.go
listenLinux
func listenLinux(lfd listenFD, cid, port uint32) (l *Listener, err error) { defer func() { if err != nil { // If any system calls fail during setup, the socket must be closed // to avoid file descriptor leaks. _ = lfd.EarlyClose() } }() // Zero-value for "any port" is friendlier in Go than a constant. if port == 0 { port = unix.VMADDR_PORT_ANY } sa := &unix.SockaddrVM{ CID: cid, Port: port, } if err := lfd.Bind(sa); err != nil { return nil, err } if err := lfd.Listen(unix.SOMAXCONN); err != nil { return nil, err } lsa, err := lfd.Getsockname() if err != nil { return nil, err } // Done with blocking mode setup, transition to non-blocking before the // caller has a chance to start calling things concurrently that might make // the locking situation tricky. // // Note: if any calls fail after this point, lfd.Close should be invoked // for cleanup because the socket is now non-blocking. if err := lfd.SetNonblocking("vsock-listen"); err != nil { return nil, err } lsavm := lsa.(*unix.SockaddrVM) addr := &Addr{ ContextID: lsavm.CID, Port: lsavm.Port, } return &Listener{ l: &listener{ fd: lfd, addr: addr, }, }, nil }
go
func listenLinux(lfd listenFD, cid, port uint32) (l *Listener, err error) { defer func() { if err != nil { // If any system calls fail during setup, the socket must be closed // to avoid file descriptor leaks. _ = lfd.EarlyClose() } }() // Zero-value for "any port" is friendlier in Go than a constant. if port == 0 { port = unix.VMADDR_PORT_ANY } sa := &unix.SockaddrVM{ CID: cid, Port: port, } if err := lfd.Bind(sa); err != nil { return nil, err } if err := lfd.Listen(unix.SOMAXCONN); err != nil { return nil, err } lsa, err := lfd.Getsockname() if err != nil { return nil, err } // Done with blocking mode setup, transition to non-blocking before the // caller has a chance to start calling things concurrently that might make // the locking situation tricky. // // Note: if any calls fail after this point, lfd.Close should be invoked // for cleanup because the socket is now non-blocking. if err := lfd.SetNonblocking("vsock-listen"); err != nil { return nil, err } lsavm := lsa.(*unix.SockaddrVM) addr := &Addr{ ContextID: lsavm.CID, Port: lsavm.Port, } return &Listener{ l: &listener{ fd: lfd, addr: addr, }, }, nil }
[ "func", "listenLinux", "(", "lfd", "listenFD", ",", "cid", ",", "port", "uint32", ")", "(", "l", "*", "Listener", ",", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "// If any system calls fail during setup, the socket must be closed", "// to avoid file descriptor leaks.", "_", "=", "lfd", ".", "EarlyClose", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "// Zero-value for \"any port\" is friendlier in Go than a constant.", "if", "port", "==", "0", "{", "port", "=", "unix", ".", "VMADDR_PORT_ANY", "\n", "}", "\n\n", "sa", ":=", "&", "unix", ".", "SockaddrVM", "{", "CID", ":", "cid", ",", "Port", ":", "port", ",", "}", "\n\n", "if", "err", ":=", "lfd", ".", "Bind", "(", "sa", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "lfd", ".", "Listen", "(", "unix", ".", "SOMAXCONN", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "lsa", ",", "err", ":=", "lfd", ".", "Getsockname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Done with blocking mode setup, transition to non-blocking before the", "// caller has a chance to start calling things concurrently that might make", "// the locking situation tricky.", "//", "// Note: if any calls fail after this point, lfd.Close should be invoked", "// for cleanup because the socket is now non-blocking.", "if", "err", ":=", "lfd", ".", "SetNonblocking", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "lsavm", ":=", "lsa", ".", "(", "*", "unix", ".", "SockaddrVM", ")", "\n", "addr", ":=", "&", "Addr", "{", "ContextID", ":", "lsavm", ".", "CID", ",", "Port", ":", "lsavm", ".", "Port", ",", "}", "\n\n", "return", "&", "Listener", "{", "l", ":", "&", "listener", "{", "fd", ":", "lfd", ",", "addr", ":", "addr", ",", "}", ",", "}", ",", "nil", "\n", "}" ]
// listenLinux is the entry point for tests on Linux.
[ "listenLinux", "is", "the", "entry", "point", "for", "tests", "on", "Linux", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/listener_linux.go#L54-L108
10,419
mdlayher/vsock
fd_linux.go
newListenFD
func newListenFD() (*sysListenFD, error) { fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0) if err != nil { return nil, err } return &sysListenFD{ fd: fd, }, nil }
go
func newListenFD() (*sysListenFD, error) { fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0) if err != nil { return nil, err } return &sysListenFD{ fd: fd, }, nil }
[ "func", "newListenFD", "(", ")", "(", "*", "sysListenFD", ",", "error", ")", "{", "fd", ",", "err", ":=", "unix", ".", "Socket", "(", "unix", ".", "AF_VSOCK", ",", "unix", ".", "SOCK_STREAM", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "sysListenFD", "{", "fd", ":", "fd", ",", "}", ",", "nil", "\n", "}" ]
// newListenFD creates a sysListenFD in its default blocking mode.
[ "newListenFD", "creates", "a", "sysListenFD", "in", "its", "default", "blocking", "mode", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/fd_linux.go#L36-L45
10,420
mdlayher/vsock
fd_linux.go
Accept4
func (lfd *sysListenFD) Accept4(flags int) (connFD, unix.Sockaddr, error) { // Invoke Go version-specific logic for accept. newFD, sa, err := lfd.accept4(flags) if err != nil { return nil, nil, err } // Create a non-blocking connFD which will be used to implement net.Conn. cfd := &sysConnFD{fd: newFD} return cfd, sa, nil }
go
func (lfd *sysListenFD) Accept4(flags int) (connFD, unix.Sockaddr, error) { // Invoke Go version-specific logic for accept. newFD, sa, err := lfd.accept4(flags) if err != nil { return nil, nil, err } // Create a non-blocking connFD which will be used to implement net.Conn. cfd := &sysConnFD{fd: newFD} return cfd, sa, nil }
[ "func", "(", "lfd", "*", "sysListenFD", ")", "Accept4", "(", "flags", "int", ")", "(", "connFD", ",", "unix", ".", "Sockaddr", ",", "error", ")", "{", "// Invoke Go version-specific logic for accept.", "newFD", ",", "sa", ",", "err", ":=", "lfd", ".", "accept4", "(", "flags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "// Create a non-blocking connFD which will be used to implement net.Conn.", "cfd", ":=", "&", "sysConnFD", "{", "fd", ":", "newFD", "}", "\n", "return", "cfd", ",", "sa", ",", "nil", "\n", "}" ]
// Non-blocking mode methods.
[ "Non", "-", "blocking", "mode", "methods", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/fd_linux.go#L72-L82
10,421
mdlayher/vsock
fd_linux.go
newConnFD
func newConnFD() (*sysConnFD, error) { fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0) if err != nil { return nil, err } return &sysConnFD{ fd: fd, }, nil }
go
func newConnFD() (*sysConnFD, error) { fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0) if err != nil { return nil, err } return &sysConnFD{ fd: fd, }, nil }
[ "func", "newConnFD", "(", ")", "(", "*", "sysConnFD", ",", "error", ")", "{", "fd", ",", "err", ":=", "unix", ".", "Socket", "(", "unix", ".", "AF_VSOCK", ",", "unix", ".", "SOCK_STREAM", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "sysConnFD", "{", "fd", ":", "fd", ",", "}", ",", "nil", "\n", "}" ]
// newConnFD creates a sysConnFD in its default blocking mode.
[ "newConnFD", "creates", "a", "sysConnFD", "in", "its", "default", "blocking", "mode", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/fd_linux.go#L110-L119
10,422
mdlayher/vsock
fd_linux.go
isErrno
func isErrno(err error, errno int) bool { switch errno { case ebadf: return err == unix.EBADF case enotconn: return err == unix.ENOTCONN default: panicf("vsock: isErrno called with unhandled error number parameter: %d", errno) return false } }
go
func isErrno(err error, errno int) bool { switch errno { case ebadf: return err == unix.EBADF case enotconn: return err == unix.ENOTCONN default: panicf("vsock: isErrno called with unhandled error number parameter: %d", errno) return false } }
[ "func", "isErrno", "(", "err", "error", ",", "errno", "int", ")", "bool", "{", "switch", "errno", "{", "case", "ebadf", ":", "return", "err", "==", "unix", ".", "EBADF", "\n", "case", "enotconn", ":", "return", "err", "==", "unix", ".", "ENOTCONN", "\n", "default", ":", "panicf", "(", "\"", "\"", ",", "errno", ")", "\n", "return", "false", "\n", "}", "\n", "}" ]
// isErrno determines if an error a matches UNIX error number.
[ "isErrno", "determines", "if", "an", "error", "a", "matches", "UNIX", "error", "number", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/fd_linux.go#L188-L198
10,423
mdlayher/vsock
conn_linux.go
newConn
func newConn(cfd connFD, local, remote *Addr) (*Conn, error) { // Note: if any calls fail after this point, cfd.Close should be invoked // for cleanup because the socket is now non-blocking. if err := cfd.SetNonblocking(local.fileName()); err != nil { return nil, err } return &Conn{ fd: cfd, local: local, remote: remote, }, nil }
go
func newConn(cfd connFD, local, remote *Addr) (*Conn, error) { // Note: if any calls fail after this point, cfd.Close should be invoked // for cleanup because the socket is now non-blocking. if err := cfd.SetNonblocking(local.fileName()); err != nil { return nil, err } return &Conn{ fd: cfd, local: local, remote: remote, }, nil }
[ "func", "newConn", "(", "cfd", "connFD", ",", "local", ",", "remote", "*", "Addr", ")", "(", "*", "Conn", ",", "error", ")", "{", "// Note: if any calls fail after this point, cfd.Close should be invoked", "// for cleanup because the socket is now non-blocking.", "if", "err", ":=", "cfd", ".", "SetNonblocking", "(", "local", ".", "fileName", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Conn", "{", "fd", ":", "cfd", ",", "local", ":", "local", ",", "remote", ":", "remote", ",", "}", ",", "nil", "\n", "}" ]
// newConn creates a Conn using a connFD, immediately setting the connFD to // non-blocking mode for use with the runtime network poller.
[ "newConn", "creates", "a", "Conn", "using", "a", "connFD", "immediately", "setting", "the", "connFD", "to", "non", "-", "blocking", "mode", "for", "use", "with", "the", "runtime", "network", "poller", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/conn_linux.go#L11-L23
10,424
mdlayher/vsock
conn_linux.go
dial
func dial(cid, port uint32) (*Conn, error) { cfd, err := newConnFD() if err != nil { return nil, err } return dialLinux(cfd, cid, port) }
go
func dial(cid, port uint32) (*Conn, error) { cfd, err := newConnFD() if err != nil { return nil, err } return dialLinux(cfd, cid, port) }
[ "func", "dial", "(", "cid", ",", "port", "uint32", ")", "(", "*", "Conn", ",", "error", ")", "{", "cfd", ",", "err", ":=", "newConnFD", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "dialLinux", "(", "cfd", ",", "cid", ",", "port", ")", "\n", "}" ]
// dial is the entry point for Dial on Linux.
[ "dial", "is", "the", "entry", "point", "for", "Dial", "on", "Linux", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/conn_linux.go#L26-L33
10,425
mdlayher/vsock
conn_linux.go
dialLinux
func dialLinux(cfd connFD, cid, port uint32) (c *Conn, err error) { defer func() { if err != nil { // If any system calls fail during setup, the socket must be closed // to avoid file descriptor leaks. _ = cfd.EarlyClose() } }() rsa := &unix.SockaddrVM{ CID: cid, Port: port, } if err := cfd.Connect(rsa); err != nil { return nil, err } lsa, err := cfd.Getsockname() if err != nil { return nil, err } lsavm := lsa.(*unix.SockaddrVM) local := &Addr{ ContextID: lsavm.CID, Port: lsavm.Port, } remote := &Addr{ ContextID: cid, Port: port, } return newConn(cfd, local, remote) }
go
func dialLinux(cfd connFD, cid, port uint32) (c *Conn, err error) { defer func() { if err != nil { // If any system calls fail during setup, the socket must be closed // to avoid file descriptor leaks. _ = cfd.EarlyClose() } }() rsa := &unix.SockaddrVM{ CID: cid, Port: port, } if err := cfd.Connect(rsa); err != nil { return nil, err } lsa, err := cfd.Getsockname() if err != nil { return nil, err } lsavm := lsa.(*unix.SockaddrVM) local := &Addr{ ContextID: lsavm.CID, Port: lsavm.Port, } remote := &Addr{ ContextID: cid, Port: port, } return newConn(cfd, local, remote) }
[ "func", "dialLinux", "(", "cfd", "connFD", ",", "cid", ",", "port", "uint32", ")", "(", "c", "*", "Conn", ",", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "// If any system calls fail during setup, the socket must be closed", "// to avoid file descriptor leaks.", "_", "=", "cfd", ".", "EarlyClose", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "rsa", ":=", "&", "unix", ".", "SockaddrVM", "{", "CID", ":", "cid", ",", "Port", ":", "port", ",", "}", "\n\n", "if", "err", ":=", "cfd", ".", "Connect", "(", "rsa", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "lsa", ",", "err", ":=", "cfd", ".", "Getsockname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "lsavm", ":=", "lsa", ".", "(", "*", "unix", ".", "SockaddrVM", ")", "\n\n", "local", ":=", "&", "Addr", "{", "ContextID", ":", "lsavm", ".", "CID", ",", "Port", ":", "lsavm", ".", "Port", ",", "}", "\n\n", "remote", ":=", "&", "Addr", "{", "ContextID", ":", "cid", ",", "Port", ":", "port", ",", "}", "\n\n", "return", "newConn", "(", "cfd", ",", "local", ",", "remote", ")", "\n", "}" ]
// dialLinux is the entry point for tests on Linux.
[ "dialLinux", "is", "the", "entry", "point", "for", "tests", "on", "Linux", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/conn_linux.go#L36-L72
10,426
mdlayher/vsock
cmd/vscp/main.go
receive
func receive(target string, port uint32, timeout time.Duration, checksum bool) { // Log helper functions. logf := func(format string, a ...interface{}) { logf("receive: "+format, a...) } fatalf := func(format string, a ...interface{}) { log.Fatalf("vscp: receive: "+format, a...) } // Determine if target is stdout or a file to be created. var w io.Writer switch target { case "": logf("empty target, file will be written to stdout") w = os.Stdout default: logf("creating file %q for output", target) f, err := os.Create(target) if err != nil { fatalf("failed to create output file: %q", err) } defer f.Close() w = f } // Optionally compute a checksum of the data. var h hash.Hash if checksum { h = sha256.New() w = io.MultiWriter(w, h) } logf("opening listener: %d", port) l, err := vsock.Listen(port) if err != nil { fatalf("failed to listen: %v", err) } defer l.Close() // Show server's address for setting up client flags. log.Printf("receive: listening: %s", l.Addr()) // Accept a single connection, and receive stream from that connection. c, err := vsutil.Accept(l, timeout) if err != nil { fatalf("failed to accept: %v", err) } _ = l.Close() defer c.Close() if timeout != 0 { if err := c.SetDeadline(time.Now().Add(timeout)); err != nil { fatalf("failed to set timeout: %v", err) } } logf("server: %s", c.LocalAddr()) logf("client: %s", c.RemoteAddr()) logf("receiving data") if _, err := io.Copy(w, c); err != nil { fatalf("failed to receive data: %v", err) } logf("transfer complete") if h != nil { log.Printf("sha256 checksum: %x", h.Sum(nil)) } }
go
func receive(target string, port uint32, timeout time.Duration, checksum bool) { // Log helper functions. logf := func(format string, a ...interface{}) { logf("receive: "+format, a...) } fatalf := func(format string, a ...interface{}) { log.Fatalf("vscp: receive: "+format, a...) } // Determine if target is stdout or a file to be created. var w io.Writer switch target { case "": logf("empty target, file will be written to stdout") w = os.Stdout default: logf("creating file %q for output", target) f, err := os.Create(target) if err != nil { fatalf("failed to create output file: %q", err) } defer f.Close() w = f } // Optionally compute a checksum of the data. var h hash.Hash if checksum { h = sha256.New() w = io.MultiWriter(w, h) } logf("opening listener: %d", port) l, err := vsock.Listen(port) if err != nil { fatalf("failed to listen: %v", err) } defer l.Close() // Show server's address for setting up client flags. log.Printf("receive: listening: %s", l.Addr()) // Accept a single connection, and receive stream from that connection. c, err := vsutil.Accept(l, timeout) if err != nil { fatalf("failed to accept: %v", err) } _ = l.Close() defer c.Close() if timeout != 0 { if err := c.SetDeadline(time.Now().Add(timeout)); err != nil { fatalf("failed to set timeout: %v", err) } } logf("server: %s", c.LocalAddr()) logf("client: %s", c.RemoteAddr()) logf("receiving data") if _, err := io.Copy(w, c); err != nil { fatalf("failed to receive data: %v", err) } logf("transfer complete") if h != nil { log.Printf("sha256 checksum: %x", h.Sum(nil)) } }
[ "func", "receive", "(", "target", "string", ",", "port", "uint32", ",", "timeout", "time", ".", "Duration", ",", "checksum", "bool", ")", "{", "// Log helper functions.", "logf", ":=", "func", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "logf", "(", "\"", "\"", "+", "format", ",", "a", "...", ")", "\n", "}", "\n\n", "fatalf", ":=", "func", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "log", ".", "Fatalf", "(", "\"", "\"", "+", "format", ",", "a", "...", ")", "\n", "}", "\n\n", "// Determine if target is stdout or a file to be created.", "var", "w", "io", ".", "Writer", "\n", "switch", "target", "{", "case", "\"", "\"", ":", "logf", "(", "\"", "\"", ")", "\n", "w", "=", "os", ".", "Stdout", "\n", "default", ":", "logf", "(", "\"", "\"", ",", "target", ")", "\n", "f", ",", "err", ":=", "os", ".", "Create", "(", "target", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "w", "=", "f", "\n", "}", "\n\n", "// Optionally compute a checksum of the data.", "var", "h", "hash", ".", "Hash", "\n", "if", "checksum", "{", "h", "=", "sha256", ".", "New", "(", ")", "\n", "w", "=", "io", ".", "MultiWriter", "(", "w", ",", "h", ")", "\n", "}", "\n\n", "logf", "(", "\"", "\"", ",", "port", ")", "\n\n", "l", ",", "err", ":=", "vsock", ".", "Listen", "(", "port", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "l", ".", "Close", "(", ")", "\n\n", "// Show server's address for setting up client flags.", "log", ".", "Printf", "(", "\"", "\"", ",", "l", ".", "Addr", "(", ")", ")", "\n\n", "// Accept a single connection, and receive stream from that connection.", "c", ",", "err", ":=", "vsutil", ".", "Accept", "(", "l", ",", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "_", "=", "l", ".", "Close", "(", ")", "\n", "defer", "c", ".", "Close", "(", ")", "\n\n", "if", "timeout", "!=", "0", "{", "if", "err", ":=", "c", ".", "SetDeadline", "(", "time", ".", "Now", "(", ")", ".", "Add", "(", "timeout", ")", ")", ";", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "logf", "(", "\"", "\"", ",", "c", ".", "LocalAddr", "(", ")", ")", "\n", "logf", "(", "\"", "\"", ",", "c", ".", "RemoteAddr", "(", ")", ")", "\n", "logf", "(", "\"", "\"", ")", "\n\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "w", ",", "c", ")", ";", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "logf", "(", "\"", "\"", ")", "\n\n", "if", "h", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "h", ".", "Sum", "(", "nil", ")", ")", "\n", "}", "\n", "}" ]
// receive starts a server and receives data from a remote client using // VM sockets. The data is written to target, which may be a file, // or stdout, if no file is specified.
[ "receive", "starts", "a", "server", "and", "receives", "data", "from", "a", "remote", "client", "using", "VM", "sockets", ".", "The", "data", "is", "written", "to", "target", "which", "may", "be", "a", "file", "or", "stdout", "if", "no", "file", "is", "specified", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/cmd/vscp/main.go#L64-L135
10,427
mdlayher/vsock
cmd/vscp/main.go
send
func send(target string, cid, port uint32, checksum bool) { // Log helper functions. logf := func(format string, a ...interface{}) { logf("send: "+format, a...) } fatalf := func(format string, a ...interface{}) { log.Fatalf("vscp: send: "+format, a...) } // Determine if target is stdin or a file to be read in. var r io.Reader switch target { case "", "-": logf("empty or stdin target, file will be read from stdin") r = os.Stdin default: logf("opening file %q for input", target) f, err := os.Open(target) if err != nil { fatalf("failed to open input file: %q", err) } defer f.Close() r = f } // Optionally compute a checksum of the data. var h hash.Hash if checksum { h = sha256.New() r = io.TeeReader(r, h) } logf("dialing: %d.%d", cid, port) // Dial a remote server and send a stream to that server. c, err := vsock.Dial(cid, port) if err != nil { fatalf("failed to dial: %v", err) } defer c.Close() logf("client: %s", c.LocalAddr()) logf("server: %s", c.RemoteAddr()) logf("sending data") if _, err := io.Copy(c, r); err != nil { fatalf("failed to send data: %v", err) } logf("transfer complete") if h != nil { log.Printf("sha256 checksum: %x", h.Sum(nil)) } }
go
func send(target string, cid, port uint32, checksum bool) { // Log helper functions. logf := func(format string, a ...interface{}) { logf("send: "+format, a...) } fatalf := func(format string, a ...interface{}) { log.Fatalf("vscp: send: "+format, a...) } // Determine if target is stdin or a file to be read in. var r io.Reader switch target { case "", "-": logf("empty or stdin target, file will be read from stdin") r = os.Stdin default: logf("opening file %q for input", target) f, err := os.Open(target) if err != nil { fatalf("failed to open input file: %q", err) } defer f.Close() r = f } // Optionally compute a checksum of the data. var h hash.Hash if checksum { h = sha256.New() r = io.TeeReader(r, h) } logf("dialing: %d.%d", cid, port) // Dial a remote server and send a stream to that server. c, err := vsock.Dial(cid, port) if err != nil { fatalf("failed to dial: %v", err) } defer c.Close() logf("client: %s", c.LocalAddr()) logf("server: %s", c.RemoteAddr()) logf("sending data") if _, err := io.Copy(c, r); err != nil { fatalf("failed to send data: %v", err) } logf("transfer complete") if h != nil { log.Printf("sha256 checksum: %x", h.Sum(nil)) } }
[ "func", "send", "(", "target", "string", ",", "cid", ",", "port", "uint32", ",", "checksum", "bool", ")", "{", "// Log helper functions.", "logf", ":=", "func", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "logf", "(", "\"", "\"", "+", "format", ",", "a", "...", ")", "\n", "}", "\n\n", "fatalf", ":=", "func", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "log", ".", "Fatalf", "(", "\"", "\"", "+", "format", ",", "a", "...", ")", "\n", "}", "\n\n", "// Determine if target is stdin or a file to be read in.", "var", "r", "io", ".", "Reader", "\n", "switch", "target", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "logf", "(", "\"", "\"", ")", "\n", "r", "=", "os", ".", "Stdin", "\n", "default", ":", "logf", "(", "\"", "\"", ",", "target", ")", "\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "target", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "r", "=", "f", "\n", "}", "\n\n", "// Optionally compute a checksum of the data.", "var", "h", "hash", ".", "Hash", "\n", "if", "checksum", "{", "h", "=", "sha256", ".", "New", "(", ")", "\n", "r", "=", "io", ".", "TeeReader", "(", "r", ",", "h", ")", "\n", "}", "\n\n", "logf", "(", "\"", "\"", ",", "cid", ",", "port", ")", "\n\n", "// Dial a remote server and send a stream to that server.", "c", ",", "err", ":=", "vsock", ".", "Dial", "(", "cid", ",", "port", ")", "\n", "if", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "c", ".", "Close", "(", ")", "\n\n", "logf", "(", "\"", "\"", ",", "c", ".", "LocalAddr", "(", ")", ")", "\n", "logf", "(", "\"", "\"", ",", "c", ".", "RemoteAddr", "(", ")", ")", "\n\n", "logf", "(", "\"", "\"", ")", "\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "c", ",", "r", ")", ";", "err", "!=", "nil", "{", "fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "logf", "(", "\"", "\"", ")", "\n\n", "if", "h", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "h", ".", "Sum", "(", "nil", ")", ")", "\n", "}", "\n", "}" ]
// send dials a server and sends data to it using VM sockets. The data // is read from target, which may be a file, or stdin if no file or "-" // is specified.
[ "send", "dials", "a", "server", "and", "sends", "data", "to", "it", "using", "VM", "sockets", ".", "The", "data", "is", "read", "from", "target", "which", "may", "be", "a", "file", "or", "stdin", "if", "no", "file", "or", "-", "is", "specified", "." ]
7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2
https://github.com/mdlayher/vsock/blob/7b7533a7ca4eba7dd23dab2de70e25ca6eecf7e2/cmd/vscp/main.go#L140-L195
10,428
yarpc/yarpc-go
internal/crossdock/client/tchserver/skip.go
skipOnConnRefused
func skipOnConnRefused(t crossdock.T, err error) bool { switch err.(type) { case *net.OpError: t.Skipf("tchannel server not implemented: %v", err) return true } return false }
go
func skipOnConnRefused(t crossdock.T, err error) bool { switch err.(type) { case *net.OpError: t.Skipf("tchannel server not implemented: %v", err) return true } return false }
[ "func", "skipOnConnRefused", "(", "t", "crossdock", ".", "T", ",", "err", "error", ")", "bool", "{", "switch", "err", ".", "(", "type", ")", "{", "case", "*", "net", ".", "OpError", ":", "t", ".", "Skipf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// skipOnConnRefused will mark the test as skipped if we get ECONNREFUSED. // This just means that the server we are hitting has not yet implemented a // pure TCH server at port 8083. This is OK, Go is the only one who has done it this.
[ "skipOnConnRefused", "will", "mark", "the", "test", "as", "skipped", "if", "we", "get", "ECONNREFUSED", ".", "This", "just", "means", "that", "the", "server", "we", "are", "hitting", "has", "not", "yet", "implemented", "a", "pure", "TCH", "server", "at", "port", "8083", ".", "This", "is", "OK", "Go", "is", "the", "only", "one", "who", "has", "done", "it", "this", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/client/tchserver/skip.go#L32-L39
10,429
yarpc/yarpc-go
internal/iopool/copy.go
Copy
func Copy(dst io.Writer, src io.Reader) (int64, error) { // To avoid unnecessary memory allocations we maintain our own pool of // buffers. buf := _pool.Get().(*buffer) written, err := io.CopyBuffer(dst, src, buf.b) _pool.Put(buf) return written, err }
go
func Copy(dst io.Writer, src io.Reader) (int64, error) { // To avoid unnecessary memory allocations we maintain our own pool of // buffers. buf := _pool.Get().(*buffer) written, err := io.CopyBuffer(dst, src, buf.b) _pool.Put(buf) return written, err }
[ "func", "Copy", "(", "dst", "io", ".", "Writer", ",", "src", "io", ".", "Reader", ")", "(", "int64", ",", "error", ")", "{", "// To avoid unnecessary memory allocations we maintain our own pool of", "// buffers.", "buf", ":=", "_pool", ".", "Get", "(", ")", ".", "(", "*", "buffer", ")", "\n", "written", ",", "err", ":=", "io", ".", "CopyBuffer", "(", "dst", ",", "src", ",", "buf", ".", "b", ")", "\n", "_pool", ".", "Put", "(", "buf", ")", "\n", "return", "written", ",", "err", "\n", "}" ]
// Copy copies bytes from the Reader to the Writer until the Reader is exhausted.
[ "Copy", "copies", "bytes", "from", "the", "Reader", "to", "the", "Writer", "until", "the", "Reader", "is", "exhausted", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/iopool/copy.go#L41-L48
10,430
yarpc/yarpc-go
api/transport/header.go
NewHeadersWithCapacity
func NewHeadersWithCapacity(capacity int) Headers { if capacity <= 0 { return Headers{} } return Headers{ items: make(map[string]string, capacity), originalItems: make(map[string]string, capacity), } }
go
func NewHeadersWithCapacity(capacity int) Headers { if capacity <= 0 { return Headers{} } return Headers{ items: make(map[string]string, capacity), originalItems: make(map[string]string, capacity), } }
[ "func", "NewHeadersWithCapacity", "(", "capacity", "int", ")", "Headers", "{", "if", "capacity", "<=", "0", "{", "return", "Headers", "{", "}", "\n", "}", "\n", "return", "Headers", "{", "items", ":", "make", "(", "map", "[", "string", "]", "string", ",", "capacity", ")", ",", "originalItems", ":", "make", "(", "map", "[", "string", "]", "string", ",", "capacity", ")", ",", "}", "\n", "}" ]
// NewHeadersWithCapacity allocates a new Headers object with the given // capacity. A capacity of zero or less is ignored.
[ "NewHeadersWithCapacity", "allocates", "a", "new", "Headers", "object", "with", "the", "given", "capacity", ".", "A", "capacity", "of", "zero", "or", "less", "is", "ignored", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/header.go#L52-L60
10,431
yarpc/yarpc-go
api/transport/header.go
Del
func (h Headers) Del(k string) { delete(h.items, CanonicalizeHeaderKey(k)) delete(h.originalItems, k) }
go
func (h Headers) Del(k string) { delete(h.items, CanonicalizeHeaderKey(k)) delete(h.originalItems, k) }
[ "func", "(", "h", "Headers", ")", "Del", "(", "k", "string", ")", "{", "delete", "(", "h", ".", "items", ",", "CanonicalizeHeaderKey", "(", "k", ")", ")", "\n", "delete", "(", "h", ".", "originalItems", ",", "k", ")", "\n", "}" ]
// Del deletes the header with the given name from the Headers map. // // This is a no-op if the key does not exist.
[ "Del", "deletes", "the", "header", "with", "the", "given", "name", "from", "the", "Headers", "map", ".", "This", "is", "a", "no", "-", "op", "if", "the", "key", "does", "not", "exist", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/header.go#L82-L85
10,432
yarpc/yarpc-go
api/transport/header.go
Get
func (h Headers) Get(k string) (string, bool) { v, ok := h.items[CanonicalizeHeaderKey(k)] return v, ok }
go
func (h Headers) Get(k string) (string, bool) { v, ok := h.items[CanonicalizeHeaderKey(k)] return v, ok }
[ "func", "(", "h", "Headers", ")", "Get", "(", "k", "string", ")", "(", "string", ",", "bool", ")", "{", "v", ",", "ok", ":=", "h", ".", "items", "[", "CanonicalizeHeaderKey", "(", "k", ")", "]", "\n", "return", "v", ",", "ok", "\n", "}" ]
// Get retrieves the value associated with the given header name.
[ "Get", "retrieves", "the", "value", "associated", "with", "the", "given", "header", "name", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/header.go#L88-L91
10,433
yarpc/yarpc-go
api/transport/header.go
HeadersFromMap
func HeadersFromMap(m map[string]string) Headers { if len(m) == 0 { return Headers{} } headers := NewHeadersWithCapacity(len(m)) for k, v := range m { headers = headers.With(k, v) } return headers }
go
func HeadersFromMap(m map[string]string) Headers { if len(m) == 0 { return Headers{} } headers := NewHeadersWithCapacity(len(m)) for k, v := range m { headers = headers.With(k, v) } return headers }
[ "func", "HeadersFromMap", "(", "m", "map", "[", "string", "]", "string", ")", "Headers", "{", "if", "len", "(", "m", ")", "==", "0", "{", "return", "Headers", "{", "}", "\n", "}", "\n", "headers", ":=", "NewHeadersWithCapacity", "(", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "headers", "=", "headers", ".", "With", "(", "k", ",", "v", ")", "\n", "}", "\n", "return", "headers", "\n", "}" ]
// HeadersFromMap builds a new Headers object from the given map of header // key-value pairs.
[ "HeadersFromMap", "builds", "a", "new", "Headers", "object", "from", "the", "given", "map", "of", "header", "key", "-", "value", "pairs", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/header.go#L115-L124
10,434
yarpc/yarpc-go
peer/peerlist/v2/list.go
Capacity
func Capacity(capacity int) ListOption { return listOptionFunc(func(options *listOptions) { options.capacity = capacity }) }
go
func Capacity(capacity int) ListOption { return listOptionFunc(func(options *listOptions) { options.capacity = capacity }) }
[ "func", "Capacity", "(", "capacity", "int", ")", "ListOption", "{", "return", "listOptionFunc", "(", "func", "(", "options", "*", "listOptions", ")", "{", "options", ".", "capacity", "=", "capacity", "\n", "}", ")", "\n", "}" ]
// Capacity specifies the default capacity of the underlying // data structures for this list // // Defaults to 10.
[ "Capacity", "specifies", "the", "default", "capacity", "of", "the", "underlying", "data", "structures", "for", "this", "list", "Defaults", "to", "10", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L91-L95
10,435
yarpc/yarpc-go
peer/peerlist/v2/list.go
Seed
func Seed(seed int64) ListOption { return listOptionFunc(func(options *listOptions) { options.seed = seed }) }
go
func Seed(seed int64) ListOption { return listOptionFunc(func(options *listOptions) { options.seed = seed }) }
[ "func", "Seed", "(", "seed", "int64", ")", "ListOption", "{", "return", "listOptionFunc", "(", "func", "(", "options", "*", "listOptions", ")", "{", "options", ".", "seed", "=", "seed", "\n", "}", ")", "\n", "}" ]
// Seed specifies the random seed to use for shuffling peers // // Defaults to approximately the process start time in nanoseconds.
[ "Seed", "specifies", "the", "random", "seed", "to", "use", "for", "shuffling", "peers", "Defaults", "to", "approximately", "the", "process", "start", "time", "in", "nanoseconds", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L107-L111
10,436
yarpc/yarpc-go
peer/peerlist/v2/list.go
Update
func (pl *List) Update(updates peer.ListUpdates) error { if len(updates.Additions) == 0 && len(updates.Removals) == 0 { return nil } pl.lock.Lock() defer pl.lock.Unlock() if pl.shouldRetainPeers.Load() { return pl.updateInitialized(updates) } return pl.updateUninitialized(updates) }
go
func (pl *List) Update(updates peer.ListUpdates) error { if len(updates.Additions) == 0 && len(updates.Removals) == 0 { return nil } pl.lock.Lock() defer pl.lock.Unlock() if pl.shouldRetainPeers.Load() { return pl.updateInitialized(updates) } return pl.updateUninitialized(updates) }
[ "func", "(", "pl", "*", "List", ")", "Update", "(", "updates", "peer", ".", "ListUpdates", ")", "error", "{", "if", "len", "(", "updates", ".", "Additions", ")", "==", "0", "&&", "len", "(", "updates", ".", "Removals", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "pl", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pl", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "pl", ".", "shouldRetainPeers", ".", "Load", "(", ")", "{", "return", "pl", ".", "updateInitialized", "(", "updates", ")", "\n", "}", "\n", "return", "pl", ".", "updateUninitialized", "(", "updates", ")", "\n", "}" ]
// Update applies the additions and removals of peer Identifiers to the list // it returns a multi-error result of every failure that happened without // circuit breaking due to failures.
[ "Update", "applies", "the", "additions", "and", "removals", "of", "peer", "Identifiers", "to", "the", "list", "it", "returns", "a", "multi", "-", "error", "result", "of", "every", "failure", "that", "happened", "without", "circuit", "breaking", "due", "to", "failures", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L166-L178
10,437
yarpc/yarpc-go
peer/peerlist/v2/list.go
stop
func (pl *List) stop() error { pl.lock.Lock() defer pl.lock.Unlock() var errs error if err := pl.availableChooser.Stop(); err != nil { errs = multierr.Append(errs, err) } availablePeers := pl.removeAllAvailablePeers(pl.availablePeers) errs = pl.releaseAll(errs, availablePeers) pl.addToUninitialized(availablePeers) unavailablePeers := pl.removeAllUnavailablePeers(pl.unavailablePeers) errs = pl.releaseAll(errs, unavailablePeers) pl.addToUninitialized(unavailablePeers) pl.shouldRetainPeers.Store(false) return errs }
go
func (pl *List) stop() error { pl.lock.Lock() defer pl.lock.Unlock() var errs error if err := pl.availableChooser.Stop(); err != nil { errs = multierr.Append(errs, err) } availablePeers := pl.removeAllAvailablePeers(pl.availablePeers) errs = pl.releaseAll(errs, availablePeers) pl.addToUninitialized(availablePeers) unavailablePeers := pl.removeAllUnavailablePeers(pl.unavailablePeers) errs = pl.releaseAll(errs, unavailablePeers) pl.addToUninitialized(unavailablePeers) pl.shouldRetainPeers.Store(false) return errs }
[ "func", "(", "pl", "*", "List", ")", "stop", "(", ")", "error", "{", "pl", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pl", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "var", "errs", "error", "\n\n", "if", "err", ":=", "pl", ".", "availableChooser", ".", "Stop", "(", ")", ";", "err", "!=", "nil", "{", "errs", "=", "multierr", ".", "Append", "(", "errs", ",", "err", ")", "\n", "}", "\n\n", "availablePeers", ":=", "pl", ".", "removeAllAvailablePeers", "(", "pl", ".", "availablePeers", ")", "\n", "errs", "=", "pl", ".", "releaseAll", "(", "errs", ",", "availablePeers", ")", "\n", "pl", ".", "addToUninitialized", "(", "availablePeers", ")", "\n\n", "unavailablePeers", ":=", "pl", ".", "removeAllUnavailablePeers", "(", "pl", ".", "unavailablePeers", ")", "\n", "errs", "=", "pl", ".", "releaseAll", "(", "errs", ",", "unavailablePeers", ")", "\n", "pl", ".", "addToUninitialized", "(", "unavailablePeers", ")", "\n\n", "pl", ".", "shouldRetainPeers", ".", "Store", "(", "false", ")", "\n\n", "return", "errs", "\n", "}" ]
// stop will release all the peers from the list
[ "stop", "will", "release", "all", "the", "peers", "from", "the", "list" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L301-L322
10,438
yarpc/yarpc-go
peer/peerlist/v2/list.go
releaseAll
func (pl *List) releaseAll(errs error, peers []*peerThunk) error { for _, t := range peers { if err := pl.transport.ReleasePeer(t.peer, t); err != nil { errs = multierr.Append(errs, err) } } return errs }
go
func (pl *List) releaseAll(errs error, peers []*peerThunk) error { for _, t := range peers { if err := pl.transport.ReleasePeer(t.peer, t); err != nil { errs = multierr.Append(errs, err) } } return errs }
[ "func", "(", "pl", "*", "List", ")", "releaseAll", "(", "errs", "error", ",", "peers", "[", "]", "*", "peerThunk", ")", "error", "{", "for", "_", ",", "t", ":=", "range", "peers", "{", "if", "err", ":=", "pl", ".", "transport", ".", "ReleasePeer", "(", "t", ".", "peer", ",", "t", ")", ";", "err", "!=", "nil", "{", "errs", "=", "multierr", ".", "Append", "(", "errs", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "errs", "\n", "}" ]
// releaseAll will iterate through a list of peers and call release // on the transport
[ "releaseAll", "will", "iterate", "through", "a", "list", "of", "peers", "and", "call", "release", "on", "the", "transport" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L357-L364
10,439
yarpc/yarpc-go
peer/peerlist/v2/list.go
Choose
func (pl *List) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error) { if err := pl.once.WaitUntilRunning(ctx); err != nil { return nil, nil, intyarpcerrors.AnnotateWithInfo(yarpcerrors.FromError(err), "%s peer list is not running", pl.name) } for { pl.lock.Lock() p := pl.availableChooser.Choose(ctx, req) pl.lock.Unlock() if p != nil { // A nil peer is an indication that there are no more peers // available for pending choices. // A non-nil peer indicates that we have drained the waiting // channel but there may be other peer lists waiting for a peer. // We re-fill the channel enabling those choices to proceed // concurrently. t := p.(*peerThunk) pl.notifyPeerAvailable() t.StartRequest() return t.peer, t.boundOnFinish, nil } if err := pl.waitForPeerAddedEvent(ctx); err != nil { return nil, nil, err } } }
go
func (pl *List) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error) { if err := pl.once.WaitUntilRunning(ctx); err != nil { return nil, nil, intyarpcerrors.AnnotateWithInfo(yarpcerrors.FromError(err), "%s peer list is not running", pl.name) } for { pl.lock.Lock() p := pl.availableChooser.Choose(ctx, req) pl.lock.Unlock() if p != nil { // A nil peer is an indication that there are no more peers // available for pending choices. // A non-nil peer indicates that we have drained the waiting // channel but there may be other peer lists waiting for a peer. // We re-fill the channel enabling those choices to proceed // concurrently. t := p.(*peerThunk) pl.notifyPeerAvailable() t.StartRequest() return t.peer, t.boundOnFinish, nil } if err := pl.waitForPeerAddedEvent(ctx); err != nil { return nil, nil, err } } }
[ "func", "(", "pl", "*", "List", ")", "Choose", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ")", "(", "peer", ".", "Peer", ",", "func", "(", "error", ")", ",", "error", ")", "{", "if", "err", ":=", "pl", ".", "once", ".", "WaitUntilRunning", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "intyarpcerrors", ".", "AnnotateWithInfo", "(", "yarpcerrors", ".", "FromError", "(", "err", ")", ",", "\"", "\"", ",", "pl", ".", "name", ")", "\n", "}", "\n\n", "for", "{", "pl", ".", "lock", ".", "Lock", "(", ")", "\n", "p", ":=", "pl", ".", "availableChooser", ".", "Choose", "(", "ctx", ",", "req", ")", "\n", "pl", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "p", "!=", "nil", "{", "// A nil peer is an indication that there are no more peers", "// available for pending choices.", "// A non-nil peer indicates that we have drained the waiting", "// channel but there may be other peer lists waiting for a peer.", "// We re-fill the channel enabling those choices to proceed", "// concurrently.", "t", ":=", "p", ".", "(", "*", "peerThunk", ")", "\n", "pl", ".", "notifyPeerAvailable", "(", ")", "\n", "t", ".", "StartRequest", "(", ")", "\n", "return", "t", ".", "peer", ",", "t", ".", "boundOnFinish", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "pl", ".", "waitForPeerAddedEvent", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "}" ]
// Choose selects the next available peer in the peer list
[ "Choose", "selects", "the", "next", "available", "peer", "in", "the", "peer", "list" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L413-L439
10,440
yarpc/yarpc-go
peer/peerlist/v2/list.go
NotifyStatusChanged
func (pl *List) NotifyStatusChanged(pid peer.Identifier) { pl.lock.RLock() t := pl.getThunk(pid) pl.lock.RUnlock() if t != nil { t.NotifyStatusChanged(t.id) } }
go
func (pl *List) NotifyStatusChanged(pid peer.Identifier) { pl.lock.RLock() t := pl.getThunk(pid) pl.lock.RUnlock() if t != nil { t.NotifyStatusChanged(t.id) } }
[ "func", "(", "pl", "*", "List", ")", "NotifyStatusChanged", "(", "pid", "peer", ".", "Identifier", ")", "{", "pl", ".", "lock", ".", "RLock", "(", ")", "\n", "t", ":=", "pl", ".", "getThunk", "(", "pid", ")", "\n", "pl", ".", "lock", ".", "RUnlock", "(", ")", "\n\n", "if", "t", "!=", "nil", "{", "t", ".", "NotifyStatusChanged", "(", "t", ".", "id", ")", "\n", "}", "\n", "}" ]
// NotifyStatusChanged receives status change notifications for peers in the // list.
[ "NotifyStatusChanged", "receives", "status", "change", "notifications", "for", "peers", "in", "the", "list", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L481-L489
10,441
yarpc/yarpc-go
peer/peerlist/v2/list.go
getThunk
func (pl *List) getThunk(pid peer.Identifier) *peerThunk { if t := pl.availablePeers[pid.Identifier()]; t != nil { return t } return pl.unavailablePeers[pid.Identifier()] }
go
func (pl *List) getThunk(pid peer.Identifier) *peerThunk { if t := pl.availablePeers[pid.Identifier()]; t != nil { return t } return pl.unavailablePeers[pid.Identifier()] }
[ "func", "(", "pl", "*", "List", ")", "getThunk", "(", "pid", "peer", ".", "Identifier", ")", "*", "peerThunk", "{", "if", "t", ":=", "pl", ".", "availablePeers", "[", "pid", ".", "Identifier", "(", ")", "]", ";", "t", "!=", "nil", "{", "return", "t", "\n", "}", "\n", "return", "pl", ".", "unavailablePeers", "[", "pid", ".", "Identifier", "(", ")", "]", "\n", "}" ]
// getThunk returns either the available or unavailable peer thunk. // Must be called under a lock.
[ "getThunk", "returns", "either", "the", "available", "or", "unavailable", "peer", "thunk", ".", "Must", "be", "called", "under", "a", "lock", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L493-L498
10,442
yarpc/yarpc-go
peer/peerlist/v2/list.go
notifyStatusChanged
func (pl *List) notifyStatusChanged(pid peer.Identifier) { pl.lock.Lock() defer pl.lock.Unlock() if t := pl.availablePeers[pid.Identifier()]; t != nil { // TODO: log error _ = pl.handleAvailablePeerStatusChange(t) return } if t := pl.unavailablePeers[pid.Identifier()]; t != nil { // TODO: log error _ = pl.handleUnavailablePeerStatusChange(t) } // No action required }
go
func (pl *List) notifyStatusChanged(pid peer.Identifier) { pl.lock.Lock() defer pl.lock.Unlock() if t := pl.availablePeers[pid.Identifier()]; t != nil { // TODO: log error _ = pl.handleAvailablePeerStatusChange(t) return } if t := pl.unavailablePeers[pid.Identifier()]; t != nil { // TODO: log error _ = pl.handleUnavailablePeerStatusChange(t) } // No action required }
[ "func", "(", "pl", "*", "List", ")", "notifyStatusChanged", "(", "pid", "peer", ".", "Identifier", ")", "{", "pl", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "pl", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "t", ":=", "pl", ".", "availablePeers", "[", "pid", ".", "Identifier", "(", ")", "]", ";", "t", "!=", "nil", "{", "// TODO: log error", "_", "=", "pl", ".", "handleAvailablePeerStatusChange", "(", "t", ")", "\n", "return", "\n", "}", "\n\n", "if", "t", ":=", "pl", ".", "unavailablePeers", "[", "pid", ".", "Identifier", "(", ")", "]", ";", "t", "!=", "nil", "{", "// TODO: log error", "_", "=", "pl", ".", "handleUnavailablePeerStatusChange", "(", "t", ")", "\n", "}", "\n", "// No action required", "}" ]
// notifyStatusChanged gets called by peer thunks
[ "notifyStatusChanged", "gets", "called", "by", "peer", "thunks" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L501-L516
10,443
yarpc/yarpc-go
peer/peerlist/v2/list.go
Available
func (pl *List) Available(p peer.Identifier) bool { _, ok := pl.availablePeers[p.Identifier()] return ok }
go
func (pl *List) Available(p peer.Identifier) bool { _, ok := pl.availablePeers[p.Identifier()] return ok }
[ "func", "(", "pl", "*", "List", ")", "Available", "(", "p", "peer", ".", "Identifier", ")", "bool", "{", "_", ",", "ok", ":=", "pl", ".", "availablePeers", "[", "p", ".", "Identifier", "(", ")", "]", "\n", "return", "ok", "\n", "}" ]
// Available returns whether the identifier peer is available for traffic.
[ "Available", "returns", "whether", "the", "identifier", "peer", "is", "available", "for", "traffic", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L550-L553
10,444
yarpc/yarpc-go
peer/peerlist/v2/list.go
Uninitialized
func (pl *List) Uninitialized(p peer.Identifier) bool { _, ok := pl.uninitializedPeers[p.Identifier()] return ok }
go
func (pl *List) Uninitialized(p peer.Identifier) bool { _, ok := pl.uninitializedPeers[p.Identifier()] return ok }
[ "func", "(", "pl", "*", "List", ")", "Uninitialized", "(", "p", "peer", ".", "Identifier", ")", "bool", "{", "_", ",", "ok", ":=", "pl", ".", "uninitializedPeers", "[", "p", ".", "Identifier", "(", ")", "]", "\n", "return", "ok", "\n", "}" ]
// Uninitialized returns whether a peer is waiting for the peer list to start.
[ "Uninitialized", "returns", "whether", "a", "peer", "is", "waiting", "for", "the", "peer", "list", "to", "start", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L556-L559
10,445
yarpc/yarpc-go
peer/peerlist/v2/list.go
Introspect
func (pl *List) Introspect() introspection.ChooserStatus { state := "Stopped" if pl.IsRunning() { state = "Running" } pl.lock.Lock() availables := make([]peer.Peer, 0, len(pl.availablePeers)) for _, t := range pl.availablePeers { availables = append(availables, t.peer) } unavailables := make([]peer.Peer, 0, len(pl.unavailablePeers)) for _, t := range pl.unavailablePeers { unavailables = append(unavailables, t.peer) } pl.lock.Unlock() peersStatus := make([]introspection.PeerStatus, 0, len(availables)+len(unavailables)) buildPeerStatus := func(peer peer.Peer) introspection.PeerStatus { ps := peer.Status() return introspection.PeerStatus{ Identifier: peer.Identifier(), State: fmt.Sprintf("%s, %d pending request(s)", ps.ConnectionStatus.String(), ps.PendingRequestCount), } } for _, peer := range availables { peersStatus = append(peersStatus, buildPeerStatus(peer)) } for _, peer := range unavailables { peersStatus = append(peersStatus, buildPeerStatus(peer)) } return introspection.ChooserStatus{ Name: "Single", State: fmt.Sprintf("%s (%d/%d available)", state, len(availables), len(availables)+len(unavailables)), Peers: peersStatus, } }
go
func (pl *List) Introspect() introspection.ChooserStatus { state := "Stopped" if pl.IsRunning() { state = "Running" } pl.lock.Lock() availables := make([]peer.Peer, 0, len(pl.availablePeers)) for _, t := range pl.availablePeers { availables = append(availables, t.peer) } unavailables := make([]peer.Peer, 0, len(pl.unavailablePeers)) for _, t := range pl.unavailablePeers { unavailables = append(unavailables, t.peer) } pl.lock.Unlock() peersStatus := make([]introspection.PeerStatus, 0, len(availables)+len(unavailables)) buildPeerStatus := func(peer peer.Peer) introspection.PeerStatus { ps := peer.Status() return introspection.PeerStatus{ Identifier: peer.Identifier(), State: fmt.Sprintf("%s, %d pending request(s)", ps.ConnectionStatus.String(), ps.PendingRequestCount), } } for _, peer := range availables { peersStatus = append(peersStatus, buildPeerStatus(peer)) } for _, peer := range unavailables { peersStatus = append(peersStatus, buildPeerStatus(peer)) } return introspection.ChooserStatus{ Name: "Single", State: fmt.Sprintf("%s (%d/%d available)", state, len(availables), len(availables)+len(unavailables)), Peers: peersStatus, } }
[ "func", "(", "pl", "*", "List", ")", "Introspect", "(", ")", "introspection", ".", "ChooserStatus", "{", "state", ":=", "\"", "\"", "\n", "if", "pl", ".", "IsRunning", "(", ")", "{", "state", "=", "\"", "\"", "\n", "}", "\n\n", "pl", ".", "lock", ".", "Lock", "(", ")", "\n", "availables", ":=", "make", "(", "[", "]", "peer", ".", "Peer", ",", "0", ",", "len", "(", "pl", ".", "availablePeers", ")", ")", "\n", "for", "_", ",", "t", ":=", "range", "pl", ".", "availablePeers", "{", "availables", "=", "append", "(", "availables", ",", "t", ".", "peer", ")", "\n", "}", "\n", "unavailables", ":=", "make", "(", "[", "]", "peer", ".", "Peer", ",", "0", ",", "len", "(", "pl", ".", "unavailablePeers", ")", ")", "\n", "for", "_", ",", "t", ":=", "range", "pl", ".", "unavailablePeers", "{", "unavailables", "=", "append", "(", "unavailables", ",", "t", ".", "peer", ")", "\n", "}", "\n", "pl", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "peersStatus", ":=", "make", "(", "[", "]", "introspection", ".", "PeerStatus", ",", "0", ",", "len", "(", "availables", ")", "+", "len", "(", "unavailables", ")", ")", "\n\n", "buildPeerStatus", ":=", "func", "(", "peer", "peer", ".", "Peer", ")", "introspection", ".", "PeerStatus", "{", "ps", ":=", "peer", ".", "Status", "(", ")", "\n", "return", "introspection", ".", "PeerStatus", "{", "Identifier", ":", "peer", ".", "Identifier", "(", ")", ",", "State", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ps", ".", "ConnectionStatus", ".", "String", "(", ")", ",", "ps", ".", "PendingRequestCount", ")", ",", "}", "\n", "}", "\n\n", "for", "_", ",", "peer", ":=", "range", "availables", "{", "peersStatus", "=", "append", "(", "peersStatus", ",", "buildPeerStatus", "(", "peer", ")", ")", "\n", "}", "\n\n", "for", "_", ",", "peer", ":=", "range", "unavailables", "{", "peersStatus", "=", "append", "(", "peersStatus", ",", "buildPeerStatus", "(", "peer", ")", ")", "\n", "}", "\n\n", "return", "introspection", ".", "ChooserStatus", "{", "Name", ":", "\"", "\"", ",", "State", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "state", ",", "len", "(", "availables", ")", ",", "len", "(", "availables", ")", "+", "len", "(", "unavailables", ")", ")", ",", "Peers", ":", "peersStatus", ",", "}", "\n", "}" ]
// Introspect returns a ChooserStatus with a summary of the Peers.
[ "Introspect", "returns", "a", "ChooserStatus", "with", "a", "summary", "of", "the", "Peers", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L592-L636
10,446
yarpc/yarpc-go
peer/peerlist/v2/list.go
values
func values(m map[string]peer.Identifier) []peer.Identifier { vs := make([]peer.Identifier, 0, len(m)) for _, v := range m { vs = append(vs, v) } return vs }
go
func values(m map[string]peer.Identifier) []peer.Identifier { vs := make([]peer.Identifier, 0, len(m)) for _, v := range m { vs = append(vs, v) } return vs }
[ "func", "values", "(", "m", "map", "[", "string", "]", "peer", ".", "Identifier", ")", "[", "]", "peer", ".", "Identifier", "{", "vs", ":=", "make", "(", "[", "]", "peer", ".", "Identifier", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "m", "{", "vs", "=", "append", "(", "vs", ",", "v", ")", "\n", "}", "\n", "return", "vs", "\n", "}" ]
// values returns a slice of the values contained in a map of peers.
[ "values", "returns", "a", "slice", "of", "the", "values", "contained", "in", "a", "map", "of", "peers", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/v2/list.go#L652-L658
10,447
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
String
func (v *KeyValue_GetValue_Args) String() string { if v == nil { return "<nil>" } var fields [1]string i := 0 if v.Key != nil { fields[i] = fmt.Sprintf("Key: %v", *(v.Key)) i++ } return fmt.Sprintf("KeyValue_GetValue_Args{%v}", strings.Join(fields[:i], ", ")) }
go
func (v *KeyValue_GetValue_Args) String() string { if v == nil { return "<nil>" } var fields [1]string i := 0 if v.Key != nil { fields[i] = fmt.Sprintf("Key: %v", *(v.Key)) i++ } return fmt.Sprintf("KeyValue_GetValue_Args{%v}", strings.Join(fields[:i], ", ")) }
[ "func", "(", "v", "*", "KeyValue_GetValue_Args", ")", "String", "(", ")", "string", "{", "if", "v", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "var", "fields", "[", "1", "]", "string", "\n", "i", ":=", "0", "\n", "if", "v", ".", "Key", "!=", "nil", "{", "fields", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "(", "v", ".", "Key", ")", ")", "\n", "i", "++", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "fields", "[", ":", "i", "]", ",", "\"", "\"", ")", ")", "\n", "}" ]
// String returns a readable string representation of a KeyValue_GetValue_Args // struct.
[ "String", "returns", "a", "readable", "string", "representation", "of", "a", "KeyValue_GetValue_Args", "struct", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L117-L130
10,448
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
Equals
func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Key, rhs.Key) { return false } return true }
go
func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Key, rhs.Key) { return false } return true }
[ "func", "(", "v", "*", "KeyValue_GetValue_Args", ")", "Equals", "(", "rhs", "*", "KeyValue_GetValue_Args", ")", "bool", "{", "if", "v", "==", "nil", "{", "return", "rhs", "==", "nil", "\n", "}", "else", "if", "rhs", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "_String_EqualsPtr", "(", "v", ".", "Key", ",", "rhs", ".", "Key", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Equals returns true if all the fields of this KeyValue_GetValue_Args match the // provided KeyValue_GetValue_Args. // // This function performs a deep comparison.
[ "Equals", "returns", "true", "if", "all", "the", "fields", "of", "this", "KeyValue_GetValue_Args", "match", "the", "provided", "KeyValue_GetValue_Args", ".", "This", "function", "performs", "a", "deep", "comparison", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L136-L147
10,449
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
MarshalLogObject
func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Key != nil { enc.AddString("key", *v.Key) } return err }
go
func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Key != nil { enc.AddString("key", *v.Key) } return err }
[ "func", "(", "v", "*", "KeyValue_GetValue_Args", ")", "MarshalLogObject", "(", "enc", "zapcore", ".", "ObjectEncoder", ")", "(", "err", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "v", ".", "Key", "!=", "nil", "{", "enc", ".", "AddString", "(", "\"", "\"", ",", "*", "v", ".", "Key", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Args.
[ "MarshalLogObject", "implements", "zapcore", ".", "ObjectMarshaler", "enabling", "fast", "logging", "of", "KeyValue_GetValue_Args", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L151-L159
10,450
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
String
func (v *KeyValue_GetValue_Result) String() string { if v == nil { return "<nil>" } var fields [2]string i := 0 if v.Success != nil { fields[i] = fmt.Sprintf("Success: %v", *(v.Success)) i++ } if v.DoesNotExist != nil { fields[i] = fmt.Sprintf("DoesNotExist: %v", v.DoesNotExist) i++ } return fmt.Sprintf("KeyValue_GetValue_Result{%v}", strings.Join(fields[:i], ", ")) }
go
func (v *KeyValue_GetValue_Result) String() string { if v == nil { return "<nil>" } var fields [2]string i := 0 if v.Success != nil { fields[i] = fmt.Sprintf("Success: %v", *(v.Success)) i++ } if v.DoesNotExist != nil { fields[i] = fmt.Sprintf("DoesNotExist: %v", v.DoesNotExist) i++ } return fmt.Sprintf("KeyValue_GetValue_Result{%v}", strings.Join(fields[:i], ", ")) }
[ "func", "(", "v", "*", "KeyValue_GetValue_Result", ")", "String", "(", ")", "string", "{", "if", "v", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "var", "fields", "[", "2", "]", "string", "\n", "i", ":=", "0", "\n", "if", "v", ".", "Success", "!=", "nil", "{", "fields", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "(", "v", ".", "Success", ")", ")", "\n", "i", "++", "\n", "}", "\n", "if", "v", ".", "DoesNotExist", "!=", "nil", "{", "fields", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "DoesNotExist", ")", "\n", "i", "++", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "fields", "[", ":", "i", "]", ",", "\"", "\"", ")", ")", "\n", "}" ]
// String returns a readable string representation of a KeyValue_GetValue_Result // struct.
[ "String", "returns", "a", "readable", "string", "representation", "of", "a", "KeyValue_GetValue_Result", "struct", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L409-L426
10,451
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
Equals
func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Success, rhs.Success) { return false } if !((v.DoesNotExist == nil && rhs.DoesNotExist == nil) || (v.DoesNotExist != nil && rhs.DoesNotExist != nil && v.DoesNotExist.Equals(rhs.DoesNotExist))) { return false } return true }
go
func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Success, rhs.Success) { return false } if !((v.DoesNotExist == nil && rhs.DoesNotExist == nil) || (v.DoesNotExist != nil && rhs.DoesNotExist != nil && v.DoesNotExist.Equals(rhs.DoesNotExist))) { return false } return true }
[ "func", "(", "v", "*", "KeyValue_GetValue_Result", ")", "Equals", "(", "rhs", "*", "KeyValue_GetValue_Result", ")", "bool", "{", "if", "v", "==", "nil", "{", "return", "rhs", "==", "nil", "\n", "}", "else", "if", "rhs", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "_String_EqualsPtr", "(", "v", ".", "Success", ",", "rhs", ".", "Success", ")", "{", "return", "false", "\n", "}", "\n", "if", "!", "(", "(", "v", ".", "DoesNotExist", "==", "nil", "&&", "rhs", ".", "DoesNotExist", "==", "nil", ")", "||", "(", "v", ".", "DoesNotExist", "!=", "nil", "&&", "rhs", ".", "DoesNotExist", "!=", "nil", "&&", "v", ".", "DoesNotExist", ".", "Equals", "(", "rhs", ".", "DoesNotExist", ")", ")", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Equals returns true if all the fields of this KeyValue_GetValue_Result match the // provided KeyValue_GetValue_Result. // // This function performs a deep comparison.
[ "Equals", "returns", "true", "if", "all", "the", "fields", "of", "this", "KeyValue_GetValue_Result", "match", "the", "provided", "KeyValue_GetValue_Result", ".", "This", "function", "performs", "a", "deep", "comparison", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L432-L446
10,452
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
MarshalLogObject
func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Success != nil { enc.AddString("success", *v.Success) } if v.DoesNotExist != nil { err = multierr.Append(err, enc.AddObject("doesNotExist", v.DoesNotExist)) } return err }
go
func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Success != nil { enc.AddString("success", *v.Success) } if v.DoesNotExist != nil { err = multierr.Append(err, enc.AddObject("doesNotExist", v.DoesNotExist)) } return err }
[ "func", "(", "v", "*", "KeyValue_GetValue_Result", ")", "MarshalLogObject", "(", "enc", "zapcore", ".", "ObjectEncoder", ")", "(", "err", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "v", ".", "Success", "!=", "nil", "{", "enc", ".", "AddString", "(", "\"", "\"", ",", "*", "v", ".", "Success", ")", "\n", "}", "\n", "if", "v", ".", "DoesNotExist", "!=", "nil", "{", "err", "=", "multierr", ".", "Append", "(", "err", ",", "enc", ".", "AddObject", "(", "\"", "\"", ",", "v", ".", "DoesNotExist", ")", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Result.
[ "MarshalLogObject", "implements", "zapcore", ".", "ObjectMarshaler", "enabling", "fast", "logging", "of", "KeyValue_GetValue_Result", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L450-L461
10,453
yarpc/yarpc-go
internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go
GetDoesNotExist
func (v *KeyValue_GetValue_Result) GetDoesNotExist() (o *ResourceDoesNotExist) { if v != nil && v.DoesNotExist != nil { return v.DoesNotExist } return }
go
func (v *KeyValue_GetValue_Result) GetDoesNotExist() (o *ResourceDoesNotExist) { if v != nil && v.DoesNotExist != nil { return v.DoesNotExist } return }
[ "func", "(", "v", "*", "KeyValue_GetValue_Result", ")", "GetDoesNotExist", "(", ")", "(", "o", "*", "ResourceDoesNotExist", ")", "{", "if", "v", "!=", "nil", "&&", "v", ".", "DoesNotExist", "!=", "nil", "{", "return", "v", ".", "DoesNotExist", "\n", "}", "\n\n", "return", "\n", "}" ]
// GetDoesNotExist returns the value of DoesNotExist if it is set or its // zero value if it is unset.
[ "GetDoesNotExist", "returns", "the", "value", "of", "DoesNotExist", "if", "it", "is", "set", "or", "its", "zero", "value", "if", "it", "is", "unset", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalue_getvalue.go#L480-L486
10,454
yarpc/yarpc-go
internal/crossdock/thrift/oneway/oneway_echo.go
String
func (v *Oneway_Echo_Args) String() string { if v == nil { return "<nil>" } var fields [1]string i := 0 if v.Token != nil { fields[i] = fmt.Sprintf("Token: %v", *(v.Token)) i++ } return fmt.Sprintf("Oneway_Echo_Args{%v}", strings.Join(fields[:i], ", ")) }
go
func (v *Oneway_Echo_Args) String() string { if v == nil { return "<nil>" } var fields [1]string i := 0 if v.Token != nil { fields[i] = fmt.Sprintf("Token: %v", *(v.Token)) i++ } return fmt.Sprintf("Oneway_Echo_Args{%v}", strings.Join(fields[:i], ", ")) }
[ "func", "(", "v", "*", "Oneway_Echo_Args", ")", "String", "(", ")", "string", "{", "if", "v", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "var", "fields", "[", "1", "]", "string", "\n", "i", ":=", "0", "\n", "if", "v", ".", "Token", "!=", "nil", "{", "fields", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "(", "v", ".", "Token", ")", ")", "\n", "i", "++", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "fields", "[", ":", "i", "]", ",", "\"", "\"", ")", ")", "\n", "}" ]
// String returns a readable string representation of a Oneway_Echo_Args // struct.
[ "String", "returns", "a", "readable", "string", "representation", "of", "a", "Oneway_Echo_Args", "struct", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/thrift/oneway/oneway_echo.go#L115-L128
10,455
yarpc/yarpc-go
internal/crossdock/thrift/oneway/oneway_echo.go
Equals
func (v *Oneway_Echo_Args) Equals(rhs *Oneway_Echo_Args) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Token, rhs.Token) { return false } return true }
go
func (v *Oneway_Echo_Args) Equals(rhs *Oneway_Echo_Args) bool { if v == nil { return rhs == nil } else if rhs == nil { return false } if !_String_EqualsPtr(v.Token, rhs.Token) { return false } return true }
[ "func", "(", "v", "*", "Oneway_Echo_Args", ")", "Equals", "(", "rhs", "*", "Oneway_Echo_Args", ")", "bool", "{", "if", "v", "==", "nil", "{", "return", "rhs", "==", "nil", "\n", "}", "else", "if", "rhs", "==", "nil", "{", "return", "false", "\n", "}", "\n", "if", "!", "_String_EqualsPtr", "(", "v", ".", "Token", ",", "rhs", ".", "Token", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Equals returns true if all the fields of this Oneway_Echo_Args match the // provided Oneway_Echo_Args. // // This function performs a deep comparison.
[ "Equals", "returns", "true", "if", "all", "the", "fields", "of", "this", "Oneway_Echo_Args", "match", "the", "provided", "Oneway_Echo_Args", ".", "This", "function", "performs", "a", "deep", "comparison", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/thrift/oneway/oneway_echo.go#L144-L155
10,456
yarpc/yarpc-go
internal/crossdock/thrift/oneway/oneway_echo.go
MarshalLogObject
func (v *Oneway_Echo_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Token != nil { enc.AddString("token", *v.Token) } return err }
go
func (v *Oneway_Echo_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { if v == nil { return nil } if v.Token != nil { enc.AddString("token", *v.Token) } return err }
[ "func", "(", "v", "*", "Oneway_Echo_Args", ")", "MarshalLogObject", "(", "enc", "zapcore", ".", "ObjectEncoder", ")", "(", "err", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "v", ".", "Token", "!=", "nil", "{", "enc", ".", "AddString", "(", "\"", "\"", ",", "*", "v", ".", "Token", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Oneway_Echo_Args.
[ "MarshalLogObject", "implements", "zapcore", ".", "ObjectMarshaler", "enabling", "fast", "logging", "of", "Oneway_Echo_Args", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/thrift/oneway/oneway_echo.go#L159-L167
10,457
yarpc/yarpc-go
internal/crossdock/thrift/oneway/oneway_echo.go
GetToken
func (v *Oneway_Echo_Args) GetToken() (o string) { if v != nil && v.Token != nil { return *v.Token } return }
go
func (v *Oneway_Echo_Args) GetToken() (o string) { if v != nil && v.Token != nil { return *v.Token } return }
[ "func", "(", "v", "*", "Oneway_Echo_Args", ")", "GetToken", "(", ")", "(", "o", "string", ")", "{", "if", "v", "!=", "nil", "&&", "v", ".", "Token", "!=", "nil", "{", "return", "*", "v", ".", "Token", "\n", "}", "\n\n", "return", "\n", "}" ]
// GetToken returns the value of Token if it is set or its // zero value if it is unset.
[ "GetToken", "returns", "the", "value", "of", "Token", "if", "it", "is", "set", "or", "its", "zero", "value", "if", "it", "is", "unset", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/thrift/oneway/oneway_echo.go#L171-L177
10,458
yarpc/yarpc-go
internal/examples/protobuf/exampleutil/exampleutil.go
WithClients
func WithClients( transportType testutils.TransportType, keyValueYARPCServer examplepb.KeyValueYARPCServer, sinkYARPCServer examplepb.SinkYARPCServer, fooYARPCServer examplepb.FooYARPCServer, logger *zap.Logger, f func(*Clients) error, ) error { var procedures []transport.Procedure if keyValueYARPCServer != nil { procedures = append(procedures, examplepb.BuildKeyValueYARPCProcedures(keyValueYARPCServer)...) } if sinkYARPCServer != nil { procedures = append(procedures, examplepb.BuildSinkYARPCProcedures(sinkYARPCServer)...) } if fooYARPCServer != nil { procedures = append(procedures, examplepb.BuildFooYARPCProcedures(fooYARPCServer)...) } return testutils.WithClientInfo( "example", procedures, transportType, logger, func(clientInfo *testutils.ClientInfo) error { return f( &Clients{ examplepb.NewKeyValueYARPCClient(clientInfo.ClientConfig), examplepb.NewSinkYARPCClient(clientInfo.ClientConfig), examplepb.NewFooYARPCClient(clientInfo.ClientConfig), examplepb.NewKeyValueYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewSinkYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewFooYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewKeyValueClient(clientInfo.GRPCClientConn), examplepb.NewSinkClient(clientInfo.GRPCClientConn), examplepb.NewFooClient(clientInfo.GRPCClientConn), clientInfo.ContextWrapper, }, ) }, ) }
go
func WithClients( transportType testutils.TransportType, keyValueYARPCServer examplepb.KeyValueYARPCServer, sinkYARPCServer examplepb.SinkYARPCServer, fooYARPCServer examplepb.FooYARPCServer, logger *zap.Logger, f func(*Clients) error, ) error { var procedures []transport.Procedure if keyValueYARPCServer != nil { procedures = append(procedures, examplepb.BuildKeyValueYARPCProcedures(keyValueYARPCServer)...) } if sinkYARPCServer != nil { procedures = append(procedures, examplepb.BuildSinkYARPCProcedures(sinkYARPCServer)...) } if fooYARPCServer != nil { procedures = append(procedures, examplepb.BuildFooYARPCProcedures(fooYARPCServer)...) } return testutils.WithClientInfo( "example", procedures, transportType, logger, func(clientInfo *testutils.ClientInfo) error { return f( &Clients{ examplepb.NewKeyValueYARPCClient(clientInfo.ClientConfig), examplepb.NewSinkYARPCClient(clientInfo.ClientConfig), examplepb.NewFooYARPCClient(clientInfo.ClientConfig), examplepb.NewKeyValueYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewSinkYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewFooYARPCClient(clientInfo.ClientConfig, protobuf.UseJSON), examplepb.NewKeyValueClient(clientInfo.GRPCClientConn), examplepb.NewSinkClient(clientInfo.GRPCClientConn), examplepb.NewFooClient(clientInfo.GRPCClientConn), clientInfo.ContextWrapper, }, ) }, ) }
[ "func", "WithClients", "(", "transportType", "testutils", ".", "TransportType", ",", "keyValueYARPCServer", "examplepb", ".", "KeyValueYARPCServer", ",", "sinkYARPCServer", "examplepb", ".", "SinkYARPCServer", ",", "fooYARPCServer", "examplepb", ".", "FooYARPCServer", ",", "logger", "*", "zap", ".", "Logger", ",", "f", "func", "(", "*", "Clients", ")", "error", ",", ")", "error", "{", "var", "procedures", "[", "]", "transport", ".", "Procedure", "\n", "if", "keyValueYARPCServer", "!=", "nil", "{", "procedures", "=", "append", "(", "procedures", ",", "examplepb", ".", "BuildKeyValueYARPCProcedures", "(", "keyValueYARPCServer", ")", "...", ")", "\n", "}", "\n", "if", "sinkYARPCServer", "!=", "nil", "{", "procedures", "=", "append", "(", "procedures", ",", "examplepb", ".", "BuildSinkYARPCProcedures", "(", "sinkYARPCServer", ")", "...", ")", "\n", "}", "\n", "if", "fooYARPCServer", "!=", "nil", "{", "procedures", "=", "append", "(", "procedures", ",", "examplepb", ".", "BuildFooYARPCProcedures", "(", "fooYARPCServer", ")", "...", ")", "\n", "}", "\n", "return", "testutils", ".", "WithClientInfo", "(", "\"", "\"", ",", "procedures", ",", "transportType", ",", "logger", ",", "func", "(", "clientInfo", "*", "testutils", ".", "ClientInfo", ")", "error", "{", "return", "f", "(", "&", "Clients", "{", "examplepb", ".", "NewKeyValueYARPCClient", "(", "clientInfo", ".", "ClientConfig", ")", ",", "examplepb", ".", "NewSinkYARPCClient", "(", "clientInfo", ".", "ClientConfig", ")", ",", "examplepb", ".", "NewFooYARPCClient", "(", "clientInfo", ".", "ClientConfig", ")", ",", "examplepb", ".", "NewKeyValueYARPCClient", "(", "clientInfo", ".", "ClientConfig", ",", "protobuf", ".", "UseJSON", ")", ",", "examplepb", ".", "NewSinkYARPCClient", "(", "clientInfo", ".", "ClientConfig", ",", "protobuf", ".", "UseJSON", ")", ",", "examplepb", ".", "NewFooYARPCClient", "(", "clientInfo", ".", "ClientConfig", ",", "protobuf", ".", "UseJSON", ")", ",", "examplepb", ".", "NewKeyValueClient", "(", "clientInfo", ".", "GRPCClientConn", ")", ",", "examplepb", ".", "NewSinkClient", "(", "clientInfo", ".", "GRPCClientConn", ")", ",", "examplepb", ".", "NewFooClient", "(", "clientInfo", ".", "GRPCClientConn", ")", ",", "clientInfo", ".", "ContextWrapper", ",", "}", ",", ")", "\n", "}", ",", ")", "\n", "}" ]
// WithClients calls f on the Clients.
[ "WithClients", "calls", "f", "on", "the", "Clients", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/protobuf/exampleutil/exampleutil.go#L47-L87
10,459
yarpc/yarpc-go
internal/yarpcerrors/yarpcerrors.go
NewWithNamef
func NewWithNamef(code yarpcerrors.Code, name string, format string, args ...interface{}) *yarpcerrors.Status { return yarpcerrors.Newf(code, format, args...).WithName(name) }
go
func NewWithNamef(code yarpcerrors.Code, name string, format string, args ...interface{}) *yarpcerrors.Status { return yarpcerrors.Newf(code, format, args...).WithName(name) }
[ "func", "NewWithNamef", "(", "code", "yarpcerrors", ".", "Code", ",", "name", "string", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "*", "yarpcerrors", ".", "Status", "{", "return", "yarpcerrors", ".", "Newf", "(", "code", ",", "format", ",", "args", "...", ")", ".", "WithName", "(", "name", ")", "\n", "}" ]
// NewWithNamef calls yarpcerrors.Newf and WithName on the resulting Status. // // This is put in a separate package so that we can ignore this specific file // with staticcheck and existing transports can still use this logic, as // WithName is deprecated but we still want to handle name behavior for // backwards compatibility.
[ "NewWithNamef", "calls", "yarpcerrors", ".", "Newf", "and", "WithName", "on", "the", "resulting", "Status", ".", "This", "is", "put", "in", "a", "separate", "package", "so", "that", "we", "can", "ignore", "this", "specific", "file", "with", "staticcheck", "and", "existing", "transports", "can", "still", "use", "this", "logic", "as", "WithName", "is", "deprecated", "but", "we", "still", "want", "to", "handle", "name", "behavior", "for", "backwards", "compatibility", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/yarpcerrors/yarpcerrors.go#L35-L37
10,460
yarpc/yarpc-go
internal/yarpcerrors/yarpcerrors.go
AnnotateWithInfo
func AnnotateWithInfo(status *yarpcerrors.Status, format string, args ...interface{}) *yarpcerrors.Status { return yarpcerrors.Newf(status.Code(), "%s: %s", fmt.Sprintf(format, args...), status.Message()) }
go
func AnnotateWithInfo(status *yarpcerrors.Status, format string, args ...interface{}) *yarpcerrors.Status { return yarpcerrors.Newf(status.Code(), "%s: %s", fmt.Sprintf(format, args...), status.Message()) }
[ "func", "AnnotateWithInfo", "(", "status", "*", "yarpcerrors", ".", "Status", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "*", "yarpcerrors", ".", "Status", "{", "return", "yarpcerrors", ".", "Newf", "(", "status", ".", "Code", "(", ")", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ",", "status", ".", "Message", "(", ")", ")", "\n", "}" ]
// AnnotateWithInfo will take an error and add info to it's error message while // keeping the same status code.
[ "AnnotateWithInfo", "will", "take", "an", "error", "and", "add", "info", "to", "it", "s", "error", "message", "while", "keeping", "the", "same", "status", "code", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/yarpcerrors/yarpcerrors.go#L41-L43
10,461
yarpc/yarpc-go
internal/crossdock/client/tchclient/behavior.go
Run
func Run(t crossdock.T) { fatals := crossdock.Fatals(t) encoding := t.Param(params.Encoding) server := t.Param(params.Server) serverHostPort := fmt.Sprintf("%v:%v", server, serverPort) ch, err := tchannel.NewChannel("tchannel-client", nil) fatals.NoError(err, "Could not create channel") call := call{Channel: ch, ServerHostPort: serverHostPort} switch encoding { case "raw": runRaw(t, call) case "json": runJSON(t, call) case "thrift": runThrift(t, call) default: fatals.Fail("", "unknown encoding %q", encoding) } }
go
func Run(t crossdock.T) { fatals := crossdock.Fatals(t) encoding := t.Param(params.Encoding) server := t.Param(params.Server) serverHostPort := fmt.Sprintf("%v:%v", server, serverPort) ch, err := tchannel.NewChannel("tchannel-client", nil) fatals.NoError(err, "Could not create channel") call := call{Channel: ch, ServerHostPort: serverHostPort} switch encoding { case "raw": runRaw(t, call) case "json": runJSON(t, call) case "thrift": runThrift(t, call) default: fatals.Fail("", "unknown encoding %q", encoding) } }
[ "func", "Run", "(", "t", "crossdock", ".", "T", ")", "{", "fatals", ":=", "crossdock", ".", "Fatals", "(", "t", ")", "\n\n", "encoding", ":=", "t", ".", "Param", "(", "params", ".", "Encoding", ")", "\n", "server", ":=", "t", ".", "Param", "(", "params", ".", "Server", ")", "\n", "serverHostPort", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "server", ",", "serverPort", ")", "\n\n", "ch", ",", "err", ":=", "tchannel", ".", "NewChannel", "(", "\"", "\"", ",", "nil", ")", "\n", "fatals", ".", "NoError", "(", "err", ",", "\"", "\"", ")", "\n\n", "call", ":=", "call", "{", "Channel", ":", "ch", ",", "ServerHostPort", ":", "serverHostPort", "}", "\n\n", "switch", "encoding", "{", "case", "\"", "\"", ":", "runRaw", "(", "t", ",", "call", ")", "\n", "case", "\"", "\"", ":", "runJSON", "(", "t", ",", "call", ")", "\n", "case", "\"", "\"", ":", "runThrift", "(", "t", ",", "call", ")", "\n", "default", ":", "fatals", ".", "Fail", "(", "\"", "\"", ",", "\"", "\"", ",", "encoding", ")", "\n", "}", "\n", "}" ]
// Run exercises a YARPC server from a tchannel client.
[ "Run", "exercises", "a", "YARPC", "server", "from", "a", "tchannel", "client", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/client/tchclient/behavior.go#L37-L59
10,462
yarpc/yarpc-go
internal/observability/middleware.go
NewMiddleware
func NewMiddleware(cfg Config) *Middleware { m := &Middleware{newGraph(cfg.Scope, cfg.Logger, cfg.ContextExtractor)} if lvl := cfg.SuccessLevel; lvl != nil { m.graph.succLevel = *lvl } if lvl := cfg.FailureLevel; lvl != nil { m.graph.failLevel = *lvl } if lvl := cfg.ApplicationErrorLevel; lvl != nil { m.graph.appErrLevel = *lvl } return m }
go
func NewMiddleware(cfg Config) *Middleware { m := &Middleware{newGraph(cfg.Scope, cfg.Logger, cfg.ContextExtractor)} if lvl := cfg.SuccessLevel; lvl != nil { m.graph.succLevel = *lvl } if lvl := cfg.FailureLevel; lvl != nil { m.graph.failLevel = *lvl } if lvl := cfg.ApplicationErrorLevel; lvl != nil { m.graph.appErrLevel = *lvl } return m }
[ "func", "NewMiddleware", "(", "cfg", "Config", ")", "*", "Middleware", "{", "m", ":=", "&", "Middleware", "{", "newGraph", "(", "cfg", ".", "Scope", ",", "cfg", ".", "Logger", ",", "cfg", ".", "ContextExtractor", ")", "}", "\n\n", "if", "lvl", ":=", "cfg", ".", "SuccessLevel", ";", "lvl", "!=", "nil", "{", "m", ".", "graph", ".", "succLevel", "=", "*", "lvl", "\n", "}", "\n", "if", "lvl", ":=", "cfg", ".", "FailureLevel", ";", "lvl", "!=", "nil", "{", "m", ".", "graph", ".", "failLevel", "=", "*", "lvl", "\n", "}", "\n", "if", "lvl", ":=", "cfg", ".", "ApplicationErrorLevel", ";", "lvl", "!=", "nil", "{", "m", ".", "graph", ".", "appErrLevel", "=", "*", "lvl", "\n", "}", "\n\n", "return", "m", "\n", "}" ]
// NewMiddleware constructs an observability middleware with the provided // configuration.
[ "NewMiddleware", "constructs", "an", "observability", "middleware", "with", "the", "provided", "configuration", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L97-L111
10,463
yarpc/yarpc-go
internal/observability/middleware.go
Handle
func (m *Middleware) Handle(ctx context.Context, req *transport.Request, w transport.ResponseWriter, h transport.UnaryHandler) error { call := m.graph.begin(ctx, transport.Unary, _directionInbound, req) wrappedWriter := newWriter(w) err := h.Handle(ctx, req, wrappedWriter) call.EndWithAppError(err, wrappedWriter.isApplicationError) wrappedWriter.free() return err }
go
func (m *Middleware) Handle(ctx context.Context, req *transport.Request, w transport.ResponseWriter, h transport.UnaryHandler) error { call := m.graph.begin(ctx, transport.Unary, _directionInbound, req) wrappedWriter := newWriter(w) err := h.Handle(ctx, req, wrappedWriter) call.EndWithAppError(err, wrappedWriter.isApplicationError) wrappedWriter.free() return err }
[ "func", "(", "m", "*", "Middleware", ")", "Handle", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "w", "transport", ".", "ResponseWriter", ",", "h", "transport", ".", "UnaryHandler", ")", "error", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "ctx", ",", "transport", ".", "Unary", ",", "_directionInbound", ",", "req", ")", "\n", "wrappedWriter", ":=", "newWriter", "(", "w", ")", "\n", "err", ":=", "h", ".", "Handle", "(", "ctx", ",", "req", ",", "wrappedWriter", ")", "\n", "call", ".", "EndWithAppError", "(", "err", ",", "wrappedWriter", ".", "isApplicationError", ")", "\n", "wrappedWriter", ".", "free", "(", ")", "\n", "return", "err", "\n", "}" ]
// Handle implements middleware.UnaryInbound.
[ "Handle", "implements", "middleware", ".", "UnaryInbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L114-L121
10,464
yarpc/yarpc-go
internal/observability/middleware.go
Call
func (m *Middleware) Call(ctx context.Context, req *transport.Request, out transport.UnaryOutbound) (*transport.Response, error) { call := m.graph.begin(ctx, transport.Unary, _directionOutbound, req) res, err := out.Call(ctx, req) isApplicationError := false if res != nil { isApplicationError = res.ApplicationError } call.EndWithAppError(err, isApplicationError) return res, err }
go
func (m *Middleware) Call(ctx context.Context, req *transport.Request, out transport.UnaryOutbound) (*transport.Response, error) { call := m.graph.begin(ctx, transport.Unary, _directionOutbound, req) res, err := out.Call(ctx, req) isApplicationError := false if res != nil { isApplicationError = res.ApplicationError } call.EndWithAppError(err, isApplicationError) return res, err }
[ "func", "(", "m", "*", "Middleware", ")", "Call", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "out", "transport", ".", "UnaryOutbound", ")", "(", "*", "transport", ".", "Response", ",", "error", ")", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "ctx", ",", "transport", ".", "Unary", ",", "_directionOutbound", ",", "req", ")", "\n", "res", ",", "err", ":=", "out", ".", "Call", "(", "ctx", ",", "req", ")", "\n\n", "isApplicationError", ":=", "false", "\n", "if", "res", "!=", "nil", "{", "isApplicationError", "=", "res", ".", "ApplicationError", "\n", "}", "\n", "call", ".", "EndWithAppError", "(", "err", ",", "isApplicationError", ")", "\n", "return", "res", ",", "err", "\n", "}" ]
// Call implements middleware.UnaryOutbound.
[ "Call", "implements", "middleware", ".", "UnaryOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L124-L134
10,465
yarpc/yarpc-go
internal/observability/middleware.go
HandleOneway
func (m *Middleware) HandleOneway(ctx context.Context, req *transport.Request, h transport.OnewayHandler) error { call := m.graph.begin(ctx, transport.Oneway, _directionInbound, req) err := h.HandleOneway(ctx, req) call.End(err) return err }
go
func (m *Middleware) HandleOneway(ctx context.Context, req *transport.Request, h transport.OnewayHandler) error { call := m.graph.begin(ctx, transport.Oneway, _directionInbound, req) err := h.HandleOneway(ctx, req) call.End(err) return err }
[ "func", "(", "m", "*", "Middleware", ")", "HandleOneway", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "h", "transport", ".", "OnewayHandler", ")", "error", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "ctx", ",", "transport", ".", "Oneway", ",", "_directionInbound", ",", "req", ")", "\n", "err", ":=", "h", ".", "HandleOneway", "(", "ctx", ",", "req", ")", "\n", "call", ".", "End", "(", "err", ")", "\n", "return", "err", "\n", "}" ]
// HandleOneway implements middleware.OnewayInbound.
[ "HandleOneway", "implements", "middleware", ".", "OnewayInbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L137-L142
10,466
yarpc/yarpc-go
internal/observability/middleware.go
CallOneway
func (m *Middleware) CallOneway(ctx context.Context, req *transport.Request, out transport.OnewayOutbound) (transport.Ack, error) { call := m.graph.begin(ctx, transport.Oneway, _directionOutbound, req) ack, err := out.CallOneway(ctx, req) call.End(err) return ack, err }
go
func (m *Middleware) CallOneway(ctx context.Context, req *transport.Request, out transport.OnewayOutbound) (transport.Ack, error) { call := m.graph.begin(ctx, transport.Oneway, _directionOutbound, req) ack, err := out.CallOneway(ctx, req) call.End(err) return ack, err }
[ "func", "(", "m", "*", "Middleware", ")", "CallOneway", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "out", "transport", ".", "OnewayOutbound", ")", "(", "transport", ".", "Ack", ",", "error", ")", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "ctx", ",", "transport", ".", "Oneway", ",", "_directionOutbound", ",", "req", ")", "\n", "ack", ",", "err", ":=", "out", ".", "CallOneway", "(", "ctx", ",", "req", ")", "\n", "call", ".", "End", "(", "err", ")", "\n", "return", "ack", ",", "err", "\n", "}" ]
// CallOneway implements middleware.OnewayOutbound.
[ "CallOneway", "implements", "middleware", ".", "OnewayOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L145-L150
10,467
yarpc/yarpc-go
internal/observability/middleware.go
HandleStream
func (m *Middleware) HandleStream(serverStream *transport.ServerStream, h transport.StreamHandler) error { call := m.graph.begin(serverStream.Context(), transport.Streaming, _directionInbound, serverStream.Request().Meta.ToRequest()) err := h.HandleStream(serverStream) // TODO(pedge): wrap the *transport.ServerStream? call.End(err) return err }
go
func (m *Middleware) HandleStream(serverStream *transport.ServerStream, h transport.StreamHandler) error { call := m.graph.begin(serverStream.Context(), transport.Streaming, _directionInbound, serverStream.Request().Meta.ToRequest()) err := h.HandleStream(serverStream) // TODO(pedge): wrap the *transport.ServerStream? call.End(err) return err }
[ "func", "(", "m", "*", "Middleware", ")", "HandleStream", "(", "serverStream", "*", "transport", ".", "ServerStream", ",", "h", "transport", ".", "StreamHandler", ")", "error", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "serverStream", ".", "Context", "(", ")", ",", "transport", ".", "Streaming", ",", "_directionInbound", ",", "serverStream", ".", "Request", "(", ")", ".", "Meta", ".", "ToRequest", "(", ")", ")", "\n", "err", ":=", "h", ".", "HandleStream", "(", "serverStream", ")", "\n", "// TODO(pedge): wrap the *transport.ServerStream?", "call", ".", "End", "(", "err", ")", "\n", "return", "err", "\n", "}" ]
// HandleStream implements middleware.StreamInbound.
[ "HandleStream", "implements", "middleware", ".", "StreamInbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L153-L159
10,468
yarpc/yarpc-go
internal/observability/middleware.go
CallStream
func (m *Middleware) CallStream(ctx context.Context, request *transport.StreamRequest, out transport.StreamOutbound) (*transport.ClientStream, error) { call := m.graph.begin(ctx, transport.Streaming, _directionOutbound, request.Meta.ToRequest()) clientStream, err := out.CallStream(ctx, request) // TODO(pedge): wrap the *transport.ClientStream? call.End(err) return clientStream, err }
go
func (m *Middleware) CallStream(ctx context.Context, request *transport.StreamRequest, out transport.StreamOutbound) (*transport.ClientStream, error) { call := m.graph.begin(ctx, transport.Streaming, _directionOutbound, request.Meta.ToRequest()) clientStream, err := out.CallStream(ctx, request) // TODO(pedge): wrap the *transport.ClientStream? call.End(err) return clientStream, err }
[ "func", "(", "m", "*", "Middleware", ")", "CallStream", "(", "ctx", "context", ".", "Context", ",", "request", "*", "transport", ".", "StreamRequest", ",", "out", "transport", ".", "StreamOutbound", ")", "(", "*", "transport", ".", "ClientStream", ",", "error", ")", "{", "call", ":=", "m", ".", "graph", ".", "begin", "(", "ctx", ",", "transport", ".", "Streaming", ",", "_directionOutbound", ",", "request", ".", "Meta", ".", "ToRequest", "(", ")", ")", "\n", "clientStream", ",", "err", ":=", "out", ".", "CallStream", "(", "ctx", ",", "request", ")", "\n", "// TODO(pedge): wrap the *transport.ClientStream?", "call", ".", "End", "(", "err", ")", "\n", "return", "clientStream", ",", "err", "\n", "}" ]
// CallStream implements middleware.StreamOutbound.
[ "CallStream", "implements", "middleware", ".", "StreamOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/observability/middleware.go#L162-L168
10,469
yarpc/yarpc-go
pkg/errors/server.go
RequestBodyDecodeError
func RequestBodyDecodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, false /*isResponse*/, false /*isHeader*/, err) }
go
func RequestBodyDecodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, false /*isResponse*/, false /*isHeader*/, err) }
[ "func", "RequestBodyDecodeError", "(", "req", "*", "transport", ".", "Request", ",", "err", "error", ")", "error", "{", "return", "newServerEncodingError", "(", "req", ",", "nil", ",", "false", "/*isResponse*/", ",", "false", "/*isHeader*/", ",", "err", ")", "\n", "}" ]
// RequestBodyDecodeError builds a YARPC error with code // yarpcerrors.CodeInvalidArgument that represents a failure to decode // the request body.
[ "RequestBodyDecodeError", "builds", "a", "YARPC", "error", "with", "code", "yarpcerrors", ".", "CodeInvalidArgument", "that", "represents", "a", "failure", "to", "decode", "the", "request", "body", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/pkg/errors/server.go#L34-L36
10,470
yarpc/yarpc-go
pkg/errors/server.go
ResponseBodyEncodeError
func ResponseBodyEncodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, true /*isResponse*/, false /*isHeader*/, err) }
go
func ResponseBodyEncodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, true /*isResponse*/, false /*isHeader*/, err) }
[ "func", "ResponseBodyEncodeError", "(", "req", "*", "transport", ".", "Request", ",", "err", "error", ")", "error", "{", "return", "newServerEncodingError", "(", "req", ",", "nil", ",", "true", "/*isResponse*/", ",", "false", "/*isHeader*/", ",", "err", ")", "\n", "}" ]
// ResponseBodyEncodeError builds a YARPC error with code // yarpcerrors.CodeInvalidArgument that represents a failure to encode // the response body.
[ "ResponseBodyEncodeError", "builds", "a", "YARPC", "error", "with", "code", "yarpcerrors", ".", "CodeInvalidArgument", "that", "represents", "a", "failure", "to", "encode", "the", "response", "body", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/pkg/errors/server.go#L41-L43
10,471
yarpc/yarpc-go
pkg/errors/server.go
ResponseHeadersEncodeError
func ResponseHeadersEncodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, true /*isResponse*/, true /*isHeader*/, err) }
go
func ResponseHeadersEncodeError(req *transport.Request, err error) error { return newServerEncodingError(req, nil, true /*isResponse*/, true /*isHeader*/, err) }
[ "func", "ResponseHeadersEncodeError", "(", "req", "*", "transport", ".", "Request", ",", "err", "error", ")", "error", "{", "return", "newServerEncodingError", "(", "req", ",", "nil", ",", "true", "/*isResponse*/", ",", "true", "/*isHeader*/", ",", "err", ")", "\n", "}" ]
// ResponseHeadersEncodeError builds a YARPC error with code // yarpcerrors.CodeInvalidArgument that represents a failure to // encode the response headers.
[ "ResponseHeadersEncodeError", "builds", "a", "YARPC", "error", "with", "code", "yarpcerrors", ".", "CodeInvalidArgument", "that", "represents", "a", "failure", "to", "encode", "the", "response", "headers", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/pkg/errors/server.go#L55-L57
10,472
yarpc/yarpc-go
pkg/errors/server.go
ExpectEncodings
func ExpectEncodings(req *transport.Request, want ...transport.Encoding) error { got := req.Encoding for _, w := range want { if w == got { return nil } } return newServerEncodingError(req, want, false /*isResponse*/, false /*isHeader*/, newEncodingMismatchError(want, got)) }
go
func ExpectEncodings(req *transport.Request, want ...transport.Encoding) error { got := req.Encoding for _, w := range want { if w == got { return nil } } return newServerEncodingError(req, want, false /*isResponse*/, false /*isHeader*/, newEncodingMismatchError(want, got)) }
[ "func", "ExpectEncodings", "(", "req", "*", "transport", ".", "Request", ",", "want", "...", "transport", ".", "Encoding", ")", "error", "{", "got", ":=", "req", ".", "Encoding", "\n", "for", "_", ",", "w", ":=", "range", "want", "{", "if", "w", "==", "got", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "return", "newServerEncodingError", "(", "req", ",", "want", ",", "false", "/*isResponse*/", ",", "false", "/*isHeader*/", ",", "newEncodingMismatchError", "(", "want", ",", "got", ")", ")", "\n", "}" ]
// ExpectEncodings verifies that the given request has one of the given // encodings, otherwise it returns a YARPC error with code // yarpcerrors.CodeInvalidArgument.
[ "ExpectEncodings", "verifies", "that", "the", "given", "request", "has", "one", "of", "the", "given", "encodings", "otherwise", "it", "returns", "a", "YARPC", "error", "with", "code", "yarpcerrors", ".", "CodeInvalidArgument", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/pkg/errors/server.go#L62-L71
10,473
yarpc/yarpc-go
api/middleware/inbound.go
ApplyUnaryInbound
func ApplyUnaryInbound(h transport.UnaryHandler, i UnaryInbound) transport.UnaryHandler { if i == nil { return h } return unaryHandlerWithMiddleware{h: h, i: i} }
go
func ApplyUnaryInbound(h transport.UnaryHandler, i UnaryInbound) transport.UnaryHandler { if i == nil { return h } return unaryHandlerWithMiddleware{h: h, i: i} }
[ "func", "ApplyUnaryInbound", "(", "h", "transport", ".", "UnaryHandler", ",", "i", "UnaryInbound", ")", "transport", ".", "UnaryHandler", "{", "if", "i", "==", "nil", "{", "return", "h", "\n", "}", "\n", "return", "unaryHandlerWithMiddleware", "{", "h", ":", "h", ",", "i", ":", "i", "}", "\n", "}" ]
// ApplyUnaryInbound applies the given InboundMiddleware to the given Handler.
[ "ApplyUnaryInbound", "applies", "the", "given", "InboundMiddleware", "to", "the", "given", "Handler", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L50-L55
10,474
yarpc/yarpc-go
api/middleware/inbound.go
Handle
func (f UnaryInboundFunc) Handle(ctx context.Context, req *transport.Request, resw transport.ResponseWriter, h transport.UnaryHandler) error { return f(ctx, req, resw, h) }
go
func (f UnaryInboundFunc) Handle(ctx context.Context, req *transport.Request, resw transport.ResponseWriter, h transport.UnaryHandler) error { return f(ctx, req, resw, h) }
[ "func", "(", "f", "UnaryInboundFunc", ")", "Handle", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "resw", "transport", ".", "ResponseWriter", ",", "h", "transport", ".", "UnaryHandler", ")", "error", "{", "return", "f", "(", "ctx", ",", "req", ",", "resw", ",", "h", ")", "\n", "}" ]
// Handle for UnaryInboundFunc
[ "Handle", "for", "UnaryInboundFunc" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L61-L63
10,475
yarpc/yarpc-go
api/middleware/inbound.go
ApplyOnewayInbound
func ApplyOnewayInbound(h transport.OnewayHandler, i OnewayInbound) transport.OnewayHandler { if i == nil { return h } return onewayHandlerWithMiddleware{h: h, i: i} }
go
func ApplyOnewayInbound(h transport.OnewayHandler, i OnewayInbound) transport.OnewayHandler { if i == nil { return h } return onewayHandlerWithMiddleware{h: h, i: i} }
[ "func", "ApplyOnewayInbound", "(", "h", "transport", ".", "OnewayHandler", ",", "i", "OnewayInbound", ")", "transport", ".", "OnewayHandler", "{", "if", "i", "==", "nil", "{", "return", "h", "\n", "}", "\n", "return", "onewayHandlerWithMiddleware", "{", "h", ":", "h", ",", "i", ":", "i", "}", "\n", "}" ]
// ApplyOnewayInbound applies the given OnewayInbound middleware to // the given OnewayHandler.
[ "ApplyOnewayInbound", "applies", "the", "given", "OnewayInbound", "middleware", "to", "the", "given", "OnewayHandler", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L101-L106
10,476
yarpc/yarpc-go
api/middleware/inbound.go
HandleOneway
func (f OnewayInboundFunc) HandleOneway(ctx context.Context, req *transport.Request, h transport.OnewayHandler) error { return f(ctx, req, h) }
go
func (f OnewayInboundFunc) HandleOneway(ctx context.Context, req *transport.Request, h transport.OnewayHandler) error { return f(ctx, req, h) }
[ "func", "(", "f", "OnewayInboundFunc", ")", "HandleOneway", "(", "ctx", "context", ".", "Context", ",", "req", "*", "transport", ".", "Request", ",", "h", "transport", ".", "OnewayHandler", ")", "error", "{", "return", "f", "(", "ctx", ",", "req", ",", "h", ")", "\n", "}" ]
// HandleOneway for OnewayInboundFunc
[ "HandleOneway", "for", "OnewayInboundFunc" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L112-L114
10,477
yarpc/yarpc-go
api/middleware/inbound.go
ApplyStreamInbound
func ApplyStreamInbound(h transport.StreamHandler, i StreamInbound) transport.StreamHandler { if i == nil { return h } return streamHandlerWithMiddleware{h: h, i: i} }
go
func ApplyStreamInbound(h transport.StreamHandler, i StreamInbound) transport.StreamHandler { if i == nil { return h } return streamHandlerWithMiddleware{h: h, i: i} }
[ "func", "ApplyStreamInbound", "(", "h", "transport", ".", "StreamHandler", ",", "i", "StreamInbound", ")", "transport", ".", "StreamHandler", "{", "if", "i", "==", "nil", "{", "return", "h", "\n", "}", "\n", "return", "streamHandlerWithMiddleware", "{", "h", ":", "h", ",", "i", ":", "i", "}", "\n", "}" ]
// ApplyStreamInbound applies the given StreamInbound middleware to // the given StreamHandler.
[ "ApplyStreamInbound", "applies", "the", "given", "StreamInbound", "middleware", "to", "the", "given", "StreamHandler", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L151-L156
10,478
yarpc/yarpc-go
api/middleware/inbound.go
HandleStream
func (f StreamInboundFunc) HandleStream(s *transport.ServerStream, h transport.StreamHandler) error { return f(s, h) }
go
func (f StreamInboundFunc) HandleStream(s *transport.ServerStream, h transport.StreamHandler) error { return f(s, h) }
[ "func", "(", "f", "StreamInboundFunc", ")", "HandleStream", "(", "s", "*", "transport", ".", "ServerStream", ",", "h", "transport", ".", "StreamHandler", ")", "error", "{", "return", "f", "(", "s", ",", "h", ")", "\n", "}" ]
// HandleStream for StreamInboundFunc
[ "HandleStream", "for", "StreamInboundFunc" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/middleware/inbound.go#L162-L164
10,479
yarpc/yarpc-go
encoding/thrift/outbound.go
New
func New(c Config, opts ...ClientOption) Client { // Code generated for Thrift client instantiation will probably be something // like this: // // func New(cc transport.ClientConfig, opts ...ClientOption) *MyServiceClient { // c := thrift.New(thrift.Config{ // Service: "MyService", // ClientConfig: cc, // Protocol: protocol.Binary, // }, opts...) // return &MyServiceClient{client: c} // } // // So Config is really the internal config as far as consumers of the // generated client are concerned. var cc clientConfig for _, opt := range opts { opt.applyClientOption(&cc) } p := protocol.Binary if cc.Protocol != nil { p = cc.Protocol } svc := c.Service if cc.ServiceName != "" { svc = cc.ServiceName } if cc.Multiplexed { p = multiplexedOutboundProtocol{ Protocol: p, Service: svc, } } return thriftClient{ p: p, cc: c.ClientConfig, thriftService: svc, Enveloping: cc.Enveloping, } }
go
func New(c Config, opts ...ClientOption) Client { // Code generated for Thrift client instantiation will probably be something // like this: // // func New(cc transport.ClientConfig, opts ...ClientOption) *MyServiceClient { // c := thrift.New(thrift.Config{ // Service: "MyService", // ClientConfig: cc, // Protocol: protocol.Binary, // }, opts...) // return &MyServiceClient{client: c} // } // // So Config is really the internal config as far as consumers of the // generated client are concerned. var cc clientConfig for _, opt := range opts { opt.applyClientOption(&cc) } p := protocol.Binary if cc.Protocol != nil { p = cc.Protocol } svc := c.Service if cc.ServiceName != "" { svc = cc.ServiceName } if cc.Multiplexed { p = multiplexedOutboundProtocol{ Protocol: p, Service: svc, } } return thriftClient{ p: p, cc: c.ClientConfig, thriftService: svc, Enveloping: cc.Enveloping, } }
[ "func", "New", "(", "c", "Config", ",", "opts", "...", "ClientOption", ")", "Client", "{", "// Code generated for Thrift client instantiation will probably be something", "// like this:", "//", "// \tfunc New(cc transport.ClientConfig, opts ...ClientOption) *MyServiceClient {", "// \t\tc := thrift.New(thrift.Config{", "// \t\t\tService: \"MyService\",", "// \t\t\tClientConfig: cc,", "// \t\t\tProtocol: protocol.Binary,", "// \t\t}, opts...)", "// \t\treturn &MyServiceClient{client: c}", "// \t}", "//", "// So Config is really the internal config as far as consumers of the", "// generated client are concerned.", "var", "cc", "clientConfig", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", ".", "applyClientOption", "(", "&", "cc", ")", "\n", "}", "\n\n", "p", ":=", "protocol", ".", "Binary", "\n", "if", "cc", ".", "Protocol", "!=", "nil", "{", "p", "=", "cc", ".", "Protocol", "\n", "}", "\n\n", "svc", ":=", "c", ".", "Service", "\n", "if", "cc", ".", "ServiceName", "!=", "\"", "\"", "{", "svc", "=", "cc", ".", "ServiceName", "\n", "}", "\n\n", "if", "cc", ".", "Multiplexed", "{", "p", "=", "multiplexedOutboundProtocol", "{", "Protocol", ":", "p", ",", "Service", ":", "svc", ",", "}", "\n", "}", "\n\n", "return", "thriftClient", "{", "p", ":", "p", ",", "cc", ":", "c", ".", "ClientConfig", ",", "thriftService", ":", "svc", ",", "Enveloping", ":", "cc", ".", "Enveloping", ",", "}", "\n", "}" ]
// New creates a new Thrift client.
[ "New", "creates", "a", "new", "Thrift", "client", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/encoding/thrift/outbound.go#L61-L105
10,480
yarpc/yarpc-go
api/transport/request.go
ValidateRequest
func ValidateRequest(req *Request) error { var missingParams []string if req.Service == "" { missingParams = append(missingParams, "service name") } if req.Procedure == "" { missingParams = append(missingParams, "procedure") } if req.Caller == "" { missingParams = append(missingParams, "caller name") } if req.Encoding == "" { missingParams = append(missingParams, "encoding") } if len(missingParams) > 0 { return yarpcerrors.Newf(yarpcerrors.CodeInvalidArgument, "missing %s", strings.Join(missingParams, ", ")) } return nil }
go
func ValidateRequest(req *Request) error { var missingParams []string if req.Service == "" { missingParams = append(missingParams, "service name") } if req.Procedure == "" { missingParams = append(missingParams, "procedure") } if req.Caller == "" { missingParams = append(missingParams, "caller name") } if req.Encoding == "" { missingParams = append(missingParams, "encoding") } if len(missingParams) > 0 { return yarpcerrors.Newf(yarpcerrors.CodeInvalidArgument, "missing %s", strings.Join(missingParams, ", ")) } return nil }
[ "func", "ValidateRequest", "(", "req", "*", "Request", ")", "error", "{", "var", "missingParams", "[", "]", "string", "\n", "if", "req", ".", "Service", "==", "\"", "\"", "{", "missingParams", "=", "append", "(", "missingParams", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "req", ".", "Procedure", "==", "\"", "\"", "{", "missingParams", "=", "append", "(", "missingParams", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "req", ".", "Caller", "==", "\"", "\"", "{", "missingParams", "=", "append", "(", "missingParams", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "req", ".", "Encoding", "==", "\"", "\"", "{", "missingParams", "=", "append", "(", "missingParams", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "missingParams", ")", ">", "0", "{", "return", "yarpcerrors", ".", "Newf", "(", "yarpcerrors", ".", "CodeInvalidArgument", ",", "\"", "\"", ",", "strings", ".", "Join", "(", "missingParams", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateRequest validates the given request. An error is returned if the // request is invalid. // // Inbound transport implementations may use this to validate requests before // handling them. Outbound implementations don't need to validate requests; // they are always validated before the outbound is called.
[ "ValidateRequest", "validates", "the", "given", "request", ".", "An", "error", "is", "returned", "if", "the", "request", "is", "invalid", ".", "Inbound", "transport", "implementations", "may", "use", "this", "to", "validate", "requests", "before", "handling", "them", ".", "Outbound", "implementations", "don", "t", "need", "to", "validate", "requests", ";", "they", "are", "always", "validated", "before", "the", "outbound", "is", "called", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/request.go#L109-L127
10,481
yarpc/yarpc-go
api/transport/request.go
ValidateRequestContext
func ValidateRequestContext(ctx context.Context) error { if _, hasDeadline := ctx.Deadline(); !hasDeadline { return yarpcerrors.Newf(yarpcerrors.CodeInvalidArgument, "missing TTL") } return nil }
go
func ValidateRequestContext(ctx context.Context) error { if _, hasDeadline := ctx.Deadline(); !hasDeadline { return yarpcerrors.Newf(yarpcerrors.CodeInvalidArgument, "missing TTL") } return nil }
[ "func", "ValidateRequestContext", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "_", ",", "hasDeadline", ":=", "ctx", ".", "Deadline", "(", ")", ";", "!", "hasDeadline", "{", "return", "yarpcerrors", ".", "Newf", "(", "yarpcerrors", ".", "CodeInvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateRequestContext validates that a context for a request is valid // and contains all required information, and returns a YARPC error with code // yarpcerrors.CodeInvalidArgument otherwise.
[ "ValidateRequestContext", "validates", "that", "a", "context", "for", "a", "request", "is", "valid", "and", "contains", "all", "required", "information", "and", "returns", "a", "YARPC", "error", "with", "code", "yarpcerrors", ".", "CodeInvalidArgument", "otherwise", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/request.go#L144-L149
10,482
yarpc/yarpc-go
api/transport/request.go
ToRequest
func (r *RequestMeta) ToRequest() *Request { if r == nil { return &Request{} } return &Request{ Caller: r.Caller, Service: r.Service, Transport: r.Transport, Encoding: r.Encoding, Procedure: r.Procedure, Headers: r.Headers, ShardKey: r.ShardKey, RoutingKey: r.RoutingKey, RoutingDelegate: r.RoutingDelegate, } }
go
func (r *RequestMeta) ToRequest() *Request { if r == nil { return &Request{} } return &Request{ Caller: r.Caller, Service: r.Service, Transport: r.Transport, Encoding: r.Encoding, Procedure: r.Procedure, Headers: r.Headers, ShardKey: r.ShardKey, RoutingKey: r.RoutingKey, RoutingDelegate: r.RoutingDelegate, } }
[ "func", "(", "r", "*", "RequestMeta", ")", "ToRequest", "(", ")", "*", "Request", "{", "if", "r", "==", "nil", "{", "return", "&", "Request", "{", "}", "\n", "}", "\n", "return", "&", "Request", "{", "Caller", ":", "r", ".", "Caller", ",", "Service", ":", "r", ".", "Service", ",", "Transport", ":", "r", ".", "Transport", ",", "Encoding", ":", "r", ".", "Encoding", ",", "Procedure", ":", "r", ".", "Procedure", ",", "Headers", ":", "r", ".", "Headers", ",", "ShardKey", ":", "r", ".", "ShardKey", ",", "RoutingKey", ":", "r", ".", "RoutingKey", ",", "RoutingDelegate", ":", "r", ".", "RoutingDelegate", ",", "}", "\n", "}" ]
// ToRequest converts a RequestMeta into a Request.
[ "ToRequest", "converts", "a", "RequestMeta", "into", "a", "Request", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/api/transport/request.go#L190-L205
10,483
yarpc/yarpc-go
internal/crossdock/server/http/server.go
Start
func Start() { mux := &yarpcHTTPMux{ handlers: make(map[string]http.Handler), } mux.HandleFunc("handlertimeout/raw", handlerTimeoutRawHandler) server = net.NewHTTPServer( &http.Server{ Addr: addr, Handler: mux, ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, }) if err := server.ListenAndServe(); err != nil { log.Fatalf("failed to start HTTP server: %v", err) } }
go
func Start() { mux := &yarpcHTTPMux{ handlers: make(map[string]http.Handler), } mux.HandleFunc("handlertimeout/raw", handlerTimeoutRawHandler) server = net.NewHTTPServer( &http.Server{ Addr: addr, Handler: mux, ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, }) if err := server.ListenAndServe(); err != nil { log.Fatalf("failed to start HTTP server: %v", err) } }
[ "func", "Start", "(", ")", "{", "mux", ":=", "&", "yarpcHTTPMux", "{", "handlers", ":", "make", "(", "map", "[", "string", "]", "http", ".", "Handler", ")", ",", "}", "\n", "mux", ".", "HandleFunc", "(", "\"", "\"", ",", "handlerTimeoutRawHandler", ")", "\n\n", "server", "=", "net", ".", "NewHTTPServer", "(", "&", "http", ".", "Server", "{", "Addr", ":", "addr", ",", "Handler", ":", "mux", ",", "ReadTimeout", ":", "5", "*", "time", ".", "Second", ",", "WriteTimeout", ":", "5", "*", "time", ".", "Second", ",", "}", ")", "\n\n", "if", "err", ":=", "server", ".", "ListenAndServe", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// Start starts an http server that yarpc client will make requests to
[ "Start", "starts", "an", "http", "server", "that", "yarpc", "client", "will", "make", "requests", "to" ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/server/http/server.go#L39-L56
10,484
yarpc/yarpc-go
transport/grpc/handler.go
getBasicTransportRequest
func (h *handler) getBasicTransportRequest(ctx context.Context, streamMethod string) (*transport.Request, error) { md, ok := metadata.FromIncomingContext(ctx) if md == nil || !ok { return nil, yarpcerrors.Newf(yarpcerrors.CodeInternal, "cannot get metadata from ctx: %v", ctx) } transportRequest, err := metadataToTransportRequest(md) if err != nil { return nil, err } transportRequest.Transport = transportName procedure, err := procedureFromStreamMethod(streamMethod) if err != nil { return nil, err } transportRequest.Procedure = procedure if err := transport.ValidateRequest(transportRequest); err != nil { return nil, err } return transportRequest, nil }
go
func (h *handler) getBasicTransportRequest(ctx context.Context, streamMethod string) (*transport.Request, error) { md, ok := metadata.FromIncomingContext(ctx) if md == nil || !ok { return nil, yarpcerrors.Newf(yarpcerrors.CodeInternal, "cannot get metadata from ctx: %v", ctx) } transportRequest, err := metadataToTransportRequest(md) if err != nil { return nil, err } transportRequest.Transport = transportName procedure, err := procedureFromStreamMethod(streamMethod) if err != nil { return nil, err } transportRequest.Procedure = procedure if err := transport.ValidateRequest(transportRequest); err != nil { return nil, err } return transportRequest, nil }
[ "func", "(", "h", "*", "handler", ")", "getBasicTransportRequest", "(", "ctx", "context", ".", "Context", ",", "streamMethod", "string", ")", "(", "*", "transport", ".", "Request", ",", "error", ")", "{", "md", ",", "ok", ":=", "metadata", ".", "FromIncomingContext", "(", "ctx", ")", "\n", "if", "md", "==", "nil", "||", "!", "ok", "{", "return", "nil", ",", "yarpcerrors", ".", "Newf", "(", "yarpcerrors", ".", "CodeInternal", ",", "\"", "\"", ",", "ctx", ")", "\n", "}", "\n", "transportRequest", ",", "err", ":=", "metadataToTransportRequest", "(", "md", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "transportRequest", ".", "Transport", "=", "transportName", "\n\n", "procedure", ",", "err", ":=", "procedureFromStreamMethod", "(", "streamMethod", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "transportRequest", ".", "Procedure", "=", "procedure", "\n", "if", "err", ":=", "transport", ".", "ValidateRequest", "(", "transportRequest", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "transportRequest", ",", "nil", "\n", "}" ]
// getBasicTransportRequest converts the grpc request metadata into a // transport.Request without a body field.
[ "getBasicTransportRequest", "converts", "the", "grpc", "request", "metadata", "into", "a", "transport", ".", "Request", "without", "a", "body", "field", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/handler.go#L83-L104
10,485
yarpc/yarpc-go
transport/tchannel/config.go
TransportSpec
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) default: panic(fmt.Sprintf("unknown option of type %T: %v", o, o)) } } return ts.Spec() }
go
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) default: panic(fmt.Sprintf("unknown option of type %T: %v", o, o)) } } return ts.Spec() }
[ "func", "TransportSpec", "(", "opts", "...", "Option", ")", "yarpcconfig", ".", "TransportSpec", "{", "var", "ts", "transportSpec", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "switch", "opt", ":=", "o", ".", "(", "type", ")", "{", "case", "TransportOption", ":", "ts", ".", "transportOptions", "=", "append", "(", "ts", ".", "transportOptions", ",", "opt", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "o", ",", "o", ")", ")", "\n", "}", "\n", "}", "\n", "return", "ts", ".", "Spec", "(", ")", "\n", "}" ]
// TransportSpec returns a TransportSpec for the TChannel unary transport.
[ "TransportSpec", "returns", "a", "TransportSpec", "for", "the", "TChannel", "unary", "transport", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/tchannel/config.go#L71-L82
10,486
yarpc/yarpc-go
encoding/thrift/register.go
BuildProcedures
func BuildProcedures(s Service, opts ...RegisterOption) []transport.Procedure { var rc registerConfig for _, opt := range opts { opt.applyRegisterOption(&rc) } proto := protocol.Binary if rc.Protocol != nil { proto = rc.Protocol } svc := s.Name if rc.ServiceName != "" { svc = rc.ServiceName } rs := make([]transport.Procedure, 0, len(s.Methods)) for _, method := range s.Methods { var spec transport.HandlerSpec switch method.HandlerSpec.Type { case transport.Unary: spec = transport.NewUnaryHandlerSpec(thriftUnaryHandler{ UnaryHandler: method.HandlerSpec.Unary, Protocol: proto, Enveloping: rc.Enveloping, }) case transport.Oneway: spec = transport.NewOnewayHandlerSpec(thriftOnewayHandler{ OnewayHandler: method.HandlerSpec.Oneway, Protocol: proto, Enveloping: rc.Enveloping, }) default: panic(fmt.Sprintf("Invalid handler type for %T", method)) } rs = append(rs, transport.Procedure{ Name: procedure.ToName(svc, method.Name), HandlerSpec: spec, Encoding: Encoding, Signature: method.Signature, }) } return rs }
go
func BuildProcedures(s Service, opts ...RegisterOption) []transport.Procedure { var rc registerConfig for _, opt := range opts { opt.applyRegisterOption(&rc) } proto := protocol.Binary if rc.Protocol != nil { proto = rc.Protocol } svc := s.Name if rc.ServiceName != "" { svc = rc.ServiceName } rs := make([]transport.Procedure, 0, len(s.Methods)) for _, method := range s.Methods { var spec transport.HandlerSpec switch method.HandlerSpec.Type { case transport.Unary: spec = transport.NewUnaryHandlerSpec(thriftUnaryHandler{ UnaryHandler: method.HandlerSpec.Unary, Protocol: proto, Enveloping: rc.Enveloping, }) case transport.Oneway: spec = transport.NewOnewayHandlerSpec(thriftOnewayHandler{ OnewayHandler: method.HandlerSpec.Oneway, Protocol: proto, Enveloping: rc.Enveloping, }) default: panic(fmt.Sprintf("Invalid handler type for %T", method)) } rs = append(rs, transport.Procedure{ Name: procedure.ToName(svc, method.Name), HandlerSpec: spec, Encoding: Encoding, Signature: method.Signature, }) } return rs }
[ "func", "BuildProcedures", "(", "s", "Service", ",", "opts", "...", "RegisterOption", ")", "[", "]", "transport", ".", "Procedure", "{", "var", "rc", "registerConfig", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", ".", "applyRegisterOption", "(", "&", "rc", ")", "\n", "}", "\n\n", "proto", ":=", "protocol", ".", "Binary", "\n", "if", "rc", ".", "Protocol", "!=", "nil", "{", "proto", "=", "rc", ".", "Protocol", "\n", "}", "\n\n", "svc", ":=", "s", ".", "Name", "\n", "if", "rc", ".", "ServiceName", "!=", "\"", "\"", "{", "svc", "=", "rc", ".", "ServiceName", "\n", "}", "\n\n", "rs", ":=", "make", "(", "[", "]", "transport", ".", "Procedure", ",", "0", ",", "len", "(", "s", ".", "Methods", ")", ")", "\n\n", "for", "_", ",", "method", ":=", "range", "s", ".", "Methods", "{", "var", "spec", "transport", ".", "HandlerSpec", "\n", "switch", "method", ".", "HandlerSpec", ".", "Type", "{", "case", "transport", ".", "Unary", ":", "spec", "=", "transport", ".", "NewUnaryHandlerSpec", "(", "thriftUnaryHandler", "{", "UnaryHandler", ":", "method", ".", "HandlerSpec", ".", "Unary", ",", "Protocol", ":", "proto", ",", "Enveloping", ":", "rc", ".", "Enveloping", ",", "}", ")", "\n", "case", "transport", ".", "Oneway", ":", "spec", "=", "transport", ".", "NewOnewayHandlerSpec", "(", "thriftOnewayHandler", "{", "OnewayHandler", ":", "method", ".", "HandlerSpec", ".", "Oneway", ",", "Protocol", ":", "proto", ",", "Enveloping", ":", "rc", ".", "Enveloping", ",", "}", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "method", ")", ")", "\n", "}", "\n\n", "rs", "=", "append", "(", "rs", ",", "transport", ".", "Procedure", "{", "Name", ":", "procedure", ".", "ToName", "(", "svc", ",", "method", ".", "Name", ")", ",", "HandlerSpec", ":", "spec", ",", "Encoding", ":", "Encoding", ",", "Signature", ":", "method", ".", "Signature", ",", "}", ")", "\n", "}", "\n", "return", "rs", "\n", "}" ]
// BuildProcedures builds a list of Procedures from a Thrift service // specification.
[ "BuildProcedures", "builds", "a", "list", "of", "Procedures", "from", "a", "Thrift", "service", "specification", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/encoding/thrift/register.go#L84-L129
10,487
yarpc/yarpc-go
yarpcconfig/builder.go
buildTransport
func buildTransport(cv *buildable, k *Kit) (transport.Transport, error) { result, err := cv.Build(k) if err != nil { return nil, err } return result.(transport.Transport), nil }
go
func buildTransport(cv *buildable, k *Kit) (transport.Transport, error) { result, err := cv.Build(k) if err != nil { return nil, err } return result.(transport.Transport), nil }
[ "func", "buildTransport", "(", "cv", "*", "buildable", ",", "k", "*", "Kit", ")", "(", "transport", ".", "Transport", ",", "error", ")", "{", "result", ",", "err", ":=", "cv", ".", "Build", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ".", "(", "transport", ".", "Transport", ")", ",", "nil", "\n", "}" ]
// buildTransport builds a Transport from the given value. This will panic if // the output type is not a Transport.
[ "buildTransport", "builds", "a", "Transport", "from", "the", "given", "value", ".", "This", "will", "panic", "if", "the", "output", "type", "is", "not", "a", "Transport", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/yarpcconfig/builder.go#L148-L154
10,488
yarpc/yarpc-go
yarpcconfig/builder.go
buildInbound
func buildInbound(cv *buildable, t transport.Transport, k *Kit) (transport.Inbound, error) { result, err := cv.Build(t, k) if err != nil { return nil, err } return result.(transport.Inbound), nil }
go
func buildInbound(cv *buildable, t transport.Transport, k *Kit) (transport.Inbound, error) { result, err := cv.Build(t, k) if err != nil { return nil, err } return result.(transport.Inbound), nil }
[ "func", "buildInbound", "(", "cv", "*", "buildable", ",", "t", "transport", ".", "Transport", ",", "k", "*", "Kit", ")", "(", "transport", ".", "Inbound", ",", "error", ")", "{", "result", ",", "err", ":=", "cv", ".", "Build", "(", "t", ",", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ".", "(", "transport", ".", "Inbound", ")", ",", "nil", "\n", "}" ]
// buildInbound builds an Inbound from the given value. This will panic if the // output type for this is not transport.Inbound.
[ "buildInbound", "builds", "an", "Inbound", "from", "the", "given", "value", ".", "This", "will", "panic", "if", "the", "output", "type", "for", "this", "is", "not", "transport", ".", "Inbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/yarpcconfig/builder.go#L158-L164
10,489
yarpc/yarpc-go
yarpcconfig/builder.go
buildUnaryOutbound
func buildUnaryOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.UnaryOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.UnaryOutbound), nil }
go
func buildUnaryOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.UnaryOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.UnaryOutbound), nil }
[ "func", "buildUnaryOutbound", "(", "o", "*", "buildableOutbound", ",", "t", "transport", ".", "Transport", ",", "k", "*", "Kit", ")", "(", "transport", ".", "UnaryOutbound", ",", "error", ")", "{", "result", ",", "err", ":=", "o", ".", "Value", ".", "Build", "(", "t", ",", "k", ".", "withTransportSpec", "(", "o", ".", "TransportSpec", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ".", "(", "transport", ".", "UnaryOutbound", ")", ",", "nil", "\n", "}" ]
// buildUnaryOutbound builds an UnaryOutbound from the given value. This will panic // if the output type for this is not transport.UnaryOutbound.
[ "buildUnaryOutbound", "builds", "an", "UnaryOutbound", "from", "the", "given", "value", ".", "This", "will", "panic", "if", "the", "output", "type", "for", "this", "is", "not", "transport", ".", "UnaryOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/yarpcconfig/builder.go#L168-L174
10,490
yarpc/yarpc-go
yarpcconfig/builder.go
buildOnewayOutbound
func buildOnewayOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.OnewayOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.OnewayOutbound), nil }
go
func buildOnewayOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.OnewayOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.OnewayOutbound), nil }
[ "func", "buildOnewayOutbound", "(", "o", "*", "buildableOutbound", ",", "t", "transport", ".", "Transport", ",", "k", "*", "Kit", ")", "(", "transport", ".", "OnewayOutbound", ",", "error", ")", "{", "result", ",", "err", ":=", "o", ".", "Value", ".", "Build", "(", "t", ",", "k", ".", "withTransportSpec", "(", "o", ".", "TransportSpec", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ".", "(", "transport", ".", "OnewayOutbound", ")", ",", "nil", "\n", "}" ]
// buildOnewayOutbound builds an OnewayOutbound from the given value. This will // panic if the output type for this is not transport.OnewayOutbound.
[ "buildOnewayOutbound", "builds", "an", "OnewayOutbound", "from", "the", "given", "value", ".", "This", "will", "panic", "if", "the", "output", "type", "for", "this", "is", "not", "transport", ".", "OnewayOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/yarpcconfig/builder.go#L178-L184
10,491
yarpc/yarpc-go
yarpcconfig/builder.go
buildStreamOutbound
func buildStreamOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.StreamOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.StreamOutbound), nil }
go
func buildStreamOutbound(o *buildableOutbound, t transport.Transport, k *Kit) (transport.StreamOutbound, error) { result, err := o.Value.Build(t, k.withTransportSpec(o.TransportSpec)) if err != nil { return nil, err } return result.(transport.StreamOutbound), nil }
[ "func", "buildStreamOutbound", "(", "o", "*", "buildableOutbound", ",", "t", "transport", ".", "Transport", ",", "k", "*", "Kit", ")", "(", "transport", ".", "StreamOutbound", ",", "error", ")", "{", "result", ",", "err", ":=", "o", ".", "Value", ".", "Build", "(", "t", ",", "k", ".", "withTransportSpec", "(", "o", ".", "TransportSpec", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ".", "(", "transport", ".", "StreamOutbound", ")", ",", "nil", "\n", "}" ]
// buildStreamOutbound builds an StreamOutbound from the given value. This will // panic if the output type for this is not transport.StreamOutbound.
[ "buildStreamOutbound", "builds", "an", "StreamOutbound", "from", "the", "given", "value", ".", "This", "will", "panic", "if", "the", "output", "type", "for", "this", "is", "not", "transport", ".", "StreamOutbound", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/yarpcconfig/builder.go#L188-L194
10,492
yarpc/yarpc-go
peer/peerlist/list.go
New
func New(name string, transport peer.Transport, availableChooser peer.ListImplementation, opts ...ListOption) *List { options := defaultListOptions for _, o := range opts { o.apply(&options) } return &List{ once: lifecycle.NewOnce(), name: name, uninitializedPeers: make(map[string]peer.Identifier, options.capacity), unavailablePeers: make(map[string]*peerThunk, options.capacity), availablePeers: make(map[string]*peerThunk, options.capacity), availableChooser: availableChooser, transport: transport, noShuffle: options.noShuffle, randSrc: rand.NewSource(options.seed), peerAvailableEvent: make(chan struct{}, 1), } }
go
func New(name string, transport peer.Transport, availableChooser peer.ListImplementation, opts ...ListOption) *List { options := defaultListOptions for _, o := range opts { o.apply(&options) } return &List{ once: lifecycle.NewOnce(), name: name, uninitializedPeers: make(map[string]peer.Identifier, options.capacity), unavailablePeers: make(map[string]*peerThunk, options.capacity), availablePeers: make(map[string]*peerThunk, options.capacity), availableChooser: availableChooser, transport: transport, noShuffle: options.noShuffle, randSrc: rand.NewSource(options.seed), peerAvailableEvent: make(chan struct{}, 1), } }
[ "func", "New", "(", "name", "string", ",", "transport", "peer", ".", "Transport", ",", "availableChooser", "peer", ".", "ListImplementation", ",", "opts", "...", "ListOption", ")", "*", "List", "{", "options", ":=", "defaultListOptions", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "o", ".", "apply", "(", "&", "options", ")", "\n", "}", "\n\n", "return", "&", "List", "{", "once", ":", "lifecycle", ".", "NewOnce", "(", ")", ",", "name", ":", "name", ",", "uninitializedPeers", ":", "make", "(", "map", "[", "string", "]", "peer", ".", "Identifier", ",", "options", ".", "capacity", ")", ",", "unavailablePeers", ":", "make", "(", "map", "[", "string", "]", "*", "peerThunk", ",", "options", ".", "capacity", ")", ",", "availablePeers", ":", "make", "(", "map", "[", "string", "]", "*", "peerThunk", ",", "options", ".", "capacity", ")", ",", "availableChooser", ":", "availableChooser", ",", "transport", ":", "transport", ",", "noShuffle", ":", "options", ".", "noShuffle", ",", "randSrc", ":", "rand", ".", "NewSource", "(", "options", ".", "seed", ")", ",", "peerAvailableEvent", ":", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", ",", "}", "\n", "}" ]
// New creates a new peer list with an identifier chooser for available peers.
[ "New", "creates", "a", "new", "peer", "list", "with", "an", "identifier", "chooser", "for", "available", "peers", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/list.go#L91-L109
10,493
yarpc/yarpc-go
internal/crossdock/server/yarpc/echo.go
EchoJSON
func EchoJSON(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error) { call := yarpc.CallFromContext(ctx) for _, k := range call.HeaderNames() { if err := call.WriteResponseHeader(k, call.Header(k)); err != nil { return nil, err } } return body, nil }
go
func EchoJSON(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error) { call := yarpc.CallFromContext(ctx) for _, k := range call.HeaderNames() { if err := call.WriteResponseHeader(k, call.Header(k)); err != nil { return nil, err } } return body, nil }
[ "func", "EchoJSON", "(", "ctx", "context", ".", "Context", ",", "body", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "call", ":=", "yarpc", ".", "CallFromContext", "(", "ctx", ")", "\n", "for", "_", ",", "k", ":=", "range", "call", ".", "HeaderNames", "(", ")", "{", "if", "err", ":=", "call", ".", "WriteResponseHeader", "(", "k", ",", "call", ".", "Header", "(", "k", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "body", ",", "nil", "\n", "}" ]
// EchoJSON implements the echo procedure.
[ "EchoJSON", "implements", "the", "echo", "procedure", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/server/yarpc/echo.go#L43-L51
10,494
yarpc/yarpc-go
internal/crossdock/server/yarpc/echo.go
Echo
func (EchoThrift) Echo(ctx context.Context, ping *echo.Ping) (*echo.Pong, error) { call := yarpc.CallFromContext(ctx) for _, k := range call.HeaderNames() { if err := call.WriteResponseHeader(k, call.Header(k)); err != nil { return nil, err } } return &echo.Pong{Boop: ping.Beep}, nil }
go
func (EchoThrift) Echo(ctx context.Context, ping *echo.Ping) (*echo.Pong, error) { call := yarpc.CallFromContext(ctx) for _, k := range call.HeaderNames() { if err := call.WriteResponseHeader(k, call.Header(k)); err != nil { return nil, err } } return &echo.Pong{Boop: ping.Beep}, nil }
[ "func", "(", "EchoThrift", ")", "Echo", "(", "ctx", "context", ".", "Context", ",", "ping", "*", "echo", ".", "Ping", ")", "(", "*", "echo", ".", "Pong", ",", "error", ")", "{", "call", ":=", "yarpc", ".", "CallFromContext", "(", "ctx", ")", "\n", "for", "_", ",", "k", ":=", "range", "call", ".", "HeaderNames", "(", ")", "{", "if", "err", ":=", "call", ".", "WriteResponseHeader", "(", "k", ",", "call", ".", "Header", "(", "k", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "echo", ".", "Pong", "{", "Boop", ":", "ping", ".", "Beep", "}", ",", "nil", "\n", "}" ]
// Echo endpoint for the Echo service.
[ "Echo", "endpoint", "for", "the", "Echo", "service", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/server/yarpc/echo.go#L57-L65
10,495
yarpc/yarpc-go
internal/crossdock/server/yarpc/echo.go
Echo
func (EchoProtobuf) Echo(_ context.Context, request *crossdockpb.Ping) (*crossdockpb.Pong, error) { if request == nil { return nil, nil } return &crossdockpb.Pong{Boop: request.Beep}, nil }
go
func (EchoProtobuf) Echo(_ context.Context, request *crossdockpb.Ping) (*crossdockpb.Pong, error) { if request == nil { return nil, nil } return &crossdockpb.Pong{Boop: request.Beep}, nil }
[ "func", "(", "EchoProtobuf", ")", "Echo", "(", "_", "context", ".", "Context", ",", "request", "*", "crossdockpb", ".", "Ping", ")", "(", "*", "crossdockpb", ".", "Pong", ",", "error", ")", "{", "if", "request", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "crossdockpb", ".", "Pong", "{", "Boop", ":", "request", ".", "Beep", "}", ",", "nil", "\n", "}" ]
// Echo implements the Echo function for the Protobuf Echo service.
[ "Echo", "implements", "the", "Echo", "function", "for", "the", "Protobuf", "Echo", "service", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/server/yarpc/echo.go#L71-L76
10,496
yarpc/yarpc-go
transport/grpc/options.go
BackoffStrategy
func BackoffStrategy(backoffStrategy backoff.Strategy) TransportOption { return func(transportOptions *transportOptions) { transportOptions.backoffStrategy = backoffStrategy } }
go
func BackoffStrategy(backoffStrategy backoff.Strategy) TransportOption { return func(transportOptions *transportOptions) { transportOptions.backoffStrategy = backoffStrategy } }
[ "func", "BackoffStrategy", "(", "backoffStrategy", "backoff", ".", "Strategy", ")", "TransportOption", "{", "return", "func", "(", "transportOptions", "*", "transportOptions", ")", "{", "transportOptions", ".", "backoffStrategy", "=", "backoffStrategy", "\n", "}", "\n", "}" ]
// BackoffStrategy specifies the backoff strategy for delays between // connection attempts for each peer. // // The default is exponential backoff starting with 10ms fully jittered, // doubling each attempt, with a maximum interval of 30s.
[ "BackoffStrategy", "specifies", "the", "backoff", "strategy", "for", "delays", "between", "connection", "attempts", "for", "each", "peer", ".", "The", "default", "is", "exponential", "backoff", "starting", "with", "10ms", "fully", "jittered", "doubling", "each", "attempt", "with", "a", "maximum", "interval", "of", "30s", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/options.go#L66-L70
10,497
yarpc/yarpc-go
transport/grpc/options.go
InboundCredentials
func InboundCredentials(creds credentials.TransportCredentials) InboundOption { return func(inboundOptions *inboundOptions) { inboundOptions.creds = creds } }
go
func InboundCredentials(creds credentials.TransportCredentials) InboundOption { return func(inboundOptions *inboundOptions) { inboundOptions.creds = creds } }
[ "func", "InboundCredentials", "(", "creds", "credentials", ".", "TransportCredentials", ")", "InboundOption", "{", "return", "func", "(", "inboundOptions", "*", "inboundOptions", ")", "{", "inboundOptions", ".", "creds", "=", "creds", "\n", "}", "\n", "}" ]
// InboundCredentials returns an InboundOption that sets credentials for incoming // connections.
[ "InboundCredentials", "returns", "an", "InboundOption", "that", "sets", "credentials", "for", "incoming", "connections", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/options.go#L133-L137
10,498
yarpc/yarpc-go
peer/peerlist/peer.go
NotifyStatusChanged
func (t *peerThunk) NotifyStatusChanged(pid peer.Identifier) { t.list.notifyStatusChanged(pid) s := t.Subscriber() if s != nil { s.NotifyStatusChanged(pid) } }
go
func (t *peerThunk) NotifyStatusChanged(pid peer.Identifier) { t.list.notifyStatusChanged(pid) s := t.Subscriber() if s != nil { s.NotifyStatusChanged(pid) } }
[ "func", "(", "t", "*", "peerThunk", ")", "NotifyStatusChanged", "(", "pid", "peer", ".", "Identifier", ")", "{", "t", ".", "list", ".", "notifyStatusChanged", "(", "pid", ")", "\n\n", "s", ":=", "t", ".", "Subscriber", "(", ")", "\n", "if", "s", "!=", "nil", "{", "s", ".", "NotifyStatusChanged", "(", "pid", ")", "\n", "}", "\n", "}" ]
// NotifyStatusChanged forwards a status notification to the peer list and to // the underlying identifier chooser list.
[ "NotifyStatusChanged", "forwards", "a", "status", "notification", "to", "the", "peer", "list", "and", "to", "the", "underlying", "identifier", "chooser", "list", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/peer.go#L66-L73
10,499
yarpc/yarpc-go
peer/peerlist/peer.go
SetSubscriber
func (t *peerThunk) SetSubscriber(s peer.Subscriber) { t.lock.Lock() t.subscriber = s t.lock.Unlock() }
go
func (t *peerThunk) SetSubscriber(s peer.Subscriber) { t.lock.Lock() t.subscriber = s t.lock.Unlock() }
[ "func", "(", "t", "*", "peerThunk", ")", "SetSubscriber", "(", "s", "peer", ".", "Subscriber", ")", "{", "t", ".", "lock", ".", "Lock", "(", ")", "\n", "t", ".", "subscriber", "=", "s", "\n", "t", ".", "lock", ".", "Unlock", "(", ")", "\n", "}" ]
// SetSubscriber assigns a subscriber to the subscriber thunk.
[ "SetSubscriber", "assigns", "a", "subscriber", "to", "the", "subscriber", "thunk", "." ]
bd70ffbd17e635243988ba62be97eebff738204d
https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/peerlist/peer.go#L76-L80