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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
xtaci/kcp-go
crypt.go
encrypt
func encrypt(block cipher.Block, dst, src, buf []byte) { switch block.BlockSize() { case 8: encrypt8(block, dst, src, buf) case 16: encrypt16(block, dst, src, buf) default: encryptVariant(block, dst, src, buf) } }
go
func encrypt(block cipher.Block, dst, src, buf []byte) { switch block.BlockSize() { case 8: encrypt8(block, dst, src, buf) case 16: encrypt16(block, dst, src, buf) default: encryptVariant(block, dst, src, buf) } }
[ "func", "encrypt", "(", "block", "cipher", ".", "Block", ",", "dst", ",", "src", ",", "buf", "[", "]", "byte", ")", "{", "switch", "block", ".", "BlockSize", "(", ")", "{", "case", "8", ":", "encrypt8", "(", "block", ",", "dst", ",", "src", ",", ...
// packet encryption with local CFB mode
[ "packet", "encryption", "with", "local", "CFB", "mode" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/crypt.go#L244-L253
train
hashicorp/yamux
addr.go
LocalAddr
func (s *Session) LocalAddr() net.Addr { addr, ok := s.conn.(hasAddr) if !ok { return &yamuxAddr{"local"} } return addr.LocalAddr() }
go
func (s *Session) LocalAddr() net.Addr { addr, ok := s.conn.(hasAddr) if !ok { return &yamuxAddr{"local"} } return addr.LocalAddr() }
[ "func", "(", "s", "*", "Session", ")", "LocalAddr", "(", ")", "net", ".", "Addr", "{", "addr", ",", "ok", ":=", "s", ".", "conn", ".", "(", "hasAddr", ")", "\n", "if", "!", "ok", "{", "return", "&", "yamuxAddr", "{", "\"", "\"", "}", "\n", "}...
// LocalAddr is used to get the local address of the // underlying connection.
[ "LocalAddr", "is", "used", "to", "get", "the", "local", "address", "of", "the", "underlying", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/addr.go#L34-L40
train
hashicorp/yamux
stream.go
newStream
func newStream(session *Session, id uint32, state streamState) *Stream { s := &Stream{ id: id, session: session, state: state, controlHdr: header(make([]byte, headerSize)), controlErr: make(chan error, 1), sendHdr: header(make([]byte, headerSize)), sendErr: make(chan e...
go
func newStream(session *Session, id uint32, state streamState) *Stream { s := &Stream{ id: id, session: session, state: state, controlHdr: header(make([]byte, headerSize)), controlErr: make(chan error, 1), sendHdr: header(make([]byte, headerSize)), sendErr: make(chan e...
[ "func", "newStream", "(", "session", "*", "Session", ",", "id", "uint32", ",", "state", "streamState", ")", "*", "Stream", "{", "s", ":=", "&", "Stream", "{", "id", ":", "id", ",", "session", ":", "session", ",", "state", ":", "state", ",", "controlH...
// newStream is used to construct a new stream within // a given session for an ID
[ "newStream", "is", "used", "to", "construct", "a", "new", "stream", "within", "a", "given", "session", "for", "an", "ID" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L56-L73
train
hashicorp/yamux
stream.go
Read
func (s *Stream) Read(b []byte) (n int, err error) { defer asyncNotify(s.recvNotifyCh) START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamRemoteClose: fallthrough case streamClosed: s.recvLock.Lock() if s.recvBuf == nil || s.recvBuf.Len() == 0 { s.recvLock.Unlock()...
go
func (s *Stream) Read(b []byte) (n int, err error) { defer asyncNotify(s.recvNotifyCh) START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamRemoteClose: fallthrough case streamClosed: s.recvLock.Lock() if s.recvBuf == nil || s.recvBuf.Len() == 0 { s.recvLock.Unlock()...
[ "func", "(", "s", "*", "Stream", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "defer", "asyncNotify", "(", "s", ".", "recvNotifyCh", ")", "\n", "START", ":", "s", ".", "stateLock", ".", "Lock", "...
// Read is used to read from the stream
[ "Read", "is", "used", "to", "read", "from", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L86-L142
train
hashicorp/yamux
stream.go
Write
func (s *Stream) Write(b []byte) (n int, err error) { s.sendLock.Lock() defer s.sendLock.Unlock() total := 0 for total < len(b) { n, err := s.write(b[total:]) total += n if err != nil { return total, err } } return total, nil }
go
func (s *Stream) Write(b []byte) (n int, err error) { s.sendLock.Lock() defer s.sendLock.Unlock() total := 0 for total < len(b) { n, err := s.write(b[total:]) total += n if err != nil { return total, err } } return total, nil }
[ "func", "(", "s", "*", "Stream", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "s", ".", "sendLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "sendLock", ".", "Unlock", "(", ")", "\n", ...
// Write is used to write to the stream
[ "Write", "is", "used", "to", "write", "to", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L145-L157
train
hashicorp/yamux
stream.go
write
func (s *Stream) write(b []byte) (n int, err error) { var flags uint16 var max uint32 var body io.Reader START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamClosed: s.stateLock.Unlock() return 0, ErrStreamClosed case streamReset: s.stateLock.Unlock() return 0, ErrC...
go
func (s *Stream) write(b []byte) (n int, err error) { var flags uint16 var max uint32 var body io.Reader START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamClosed: s.stateLock.Unlock() return 0, ErrStreamClosed case streamReset: s.stateLock.Unlock() return 0, ErrC...
[ "func", "(", "s", "*", "Stream", ")", "write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "flags", "uint16", "\n", "var", "max", "uint32", "\n", "var", "body", "io", ".", "Reader", "\n", "START", ":"...
// write is used to write to the stream, may return on // a short write.
[ "write", "is", "used", "to", "write", "to", "the", "stream", "may", "return", "on", "a", "short", "write", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L161-L218
train
hashicorp/yamux
stream.go
sendFlags
func (s *Stream) sendFlags() uint16 { s.stateLock.Lock() defer s.stateLock.Unlock() var flags uint16 switch s.state { case streamInit: flags |= flagSYN s.state = streamSYNSent case streamSYNReceived: flags |= flagACK s.state = streamEstablished } return flags }
go
func (s *Stream) sendFlags() uint16 { s.stateLock.Lock() defer s.stateLock.Unlock() var flags uint16 switch s.state { case streamInit: flags |= flagSYN s.state = streamSYNSent case streamSYNReceived: flags |= flagACK s.state = streamEstablished } return flags }
[ "func", "(", "s", "*", "Stream", ")", "sendFlags", "(", ")", "uint16", "{", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "var", "flags", "uint16", "\n", "switch", "s", ".", "st...
// sendFlags determines any flags that are appropriate // based on the current stream state
[ "sendFlags", "determines", "any", "flags", "that", "are", "appropriate", "based", "on", "the", "current", "stream", "state" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L222-L235
train
hashicorp/yamux
stream.go
sendWindowUpdate
func (s *Stream) sendWindowUpdate() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() // Determine the delta update max := s.session.config.MaxStreamWindowSize var bufLen uint32 s.recvLock.Lock() if s.recvBuf != nil { bufLen = uint32(s.recvBuf.Len()) } delta := (max - bufLen) - s.recvWindow ...
go
func (s *Stream) sendWindowUpdate() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() // Determine the delta update max := s.session.config.MaxStreamWindowSize var bufLen uint32 s.recvLock.Lock() if s.recvBuf != nil { bufLen = uint32(s.recvBuf.Len()) } delta := (max - bufLen) - s.recvWindow ...
[ "func", "(", "s", "*", "Stream", ")", "sendWindowUpdate", "(", ")", "error", "{", "s", ".", "controlHdrLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "controlHdrLock", ".", "Unlock", "(", ")", "\n\n", "// Determine the delta update", "max", ":=", ...
// sendWindowUpdate potentially sends a window update enabling // further writes to take place. Must be invoked with the lock.
[ "sendWindowUpdate", "potentially", "sends", "a", "window", "update", "enabling", "further", "writes", "to", "take", "place", ".", "Must", "be", "invoked", "with", "the", "lock", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L239-L271
train
hashicorp/yamux
stream.go
sendClose
func (s *Stream) sendClose() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() flags := s.sendFlags() flags |= flagFIN s.controlHdr.encode(typeWindowUpdate, flags, s.id, 0) if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil { return err } return nil }
go
func (s *Stream) sendClose() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() flags := s.sendFlags() flags |= flagFIN s.controlHdr.encode(typeWindowUpdate, flags, s.id, 0) if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Stream", ")", "sendClose", "(", ")", "error", "{", "s", ".", "controlHdrLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "controlHdrLock", ".", "Unlock", "(", ")", "\n\n", "flags", ":=", "s", ".", "sendFlags", "(", ")"...
// sendClose is used to send a FIN
[ "sendClose", "is", "used", "to", "send", "a", "FIN" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L274-L285
train
hashicorp/yamux
stream.go
Close
func (s *Stream) Close() error { closeStream := false s.stateLock.Lock() switch s.state { // Opened means we need to signal a close case streamSYNSent: fallthrough case streamSYNReceived: fallthrough case streamEstablished: s.state = streamLocalClose goto SEND_CLOSE case streamLocalClose: case streamR...
go
func (s *Stream) Close() error { closeStream := false s.stateLock.Lock() switch s.state { // Opened means we need to signal a close case streamSYNSent: fallthrough case streamSYNReceived: fallthrough case streamEstablished: s.state = streamLocalClose goto SEND_CLOSE case streamLocalClose: case streamR...
[ "func", "(", "s", "*", "Stream", ")", "Close", "(", ")", "error", "{", "closeStream", ":=", "false", "\n", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "switch", "s", ".", "state", "{", "// Opened means we need to signal a close", "case", "streamSYN...
// Close is used to close the stream
[ "Close", "is", "used", "to", "close", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L288-L322
train
hashicorp/yamux
stream.go
forceClose
func (s *Stream) forceClose() { s.stateLock.Lock() s.state = streamClosed s.stateLock.Unlock() s.notifyWaiting() }
go
func (s *Stream) forceClose() { s.stateLock.Lock() s.state = streamClosed s.stateLock.Unlock() s.notifyWaiting() }
[ "func", "(", "s", "*", "Stream", ")", "forceClose", "(", ")", "{", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "s", ".", "state", "=", "streamClosed", "\n", "s", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "s", ".", "notifyWaiting", ...
// forceClose is used for when the session is exiting
[ "forceClose", "is", "used", "for", "when", "the", "session", "is", "exiting" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L325-L330
train
hashicorp/yamux
stream.go
processFlags
func (s *Stream) processFlags(flags uint16) error { // Close the stream without holding the state lock closeStream := false defer func() { if closeStream { s.session.closeStream(s.id) } }() s.stateLock.Lock() defer s.stateLock.Unlock() if flags&flagACK == flagACK { if s.state == streamSYNSent { s.st...
go
func (s *Stream) processFlags(flags uint16) error { // Close the stream without holding the state lock closeStream := false defer func() { if closeStream { s.session.closeStream(s.id) } }() s.stateLock.Lock() defer s.stateLock.Unlock() if flags&flagACK == flagACK { if s.state == streamSYNSent { s.st...
[ "func", "(", "s", "*", "Stream", ")", "processFlags", "(", "flags", "uint16", ")", "error", "{", "// Close the stream without holding the state lock", "closeStream", ":=", "false", "\n", "defer", "func", "(", ")", "{", "if", "closeStream", "{", "s", ".", "sess...
// processFlags is used to update the state of the stream // based on set flags, if any. Lock must be held
[ "processFlags", "is", "used", "to", "update", "the", "state", "of", "the", "stream", "based", "on", "set", "flags", "if", "any", ".", "Lock", "must", "be", "held" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L334-L375
train
hashicorp/yamux
stream.go
incrSendWindow
func (s *Stream) incrSendWindow(hdr header, flags uint16) error { if err := s.processFlags(flags); err != nil { return err } // Increase window, unblock a sender atomic.AddUint32(&s.sendWindow, hdr.Length()) asyncNotify(s.sendNotifyCh) return nil }
go
func (s *Stream) incrSendWindow(hdr header, flags uint16) error { if err := s.processFlags(flags); err != nil { return err } // Increase window, unblock a sender atomic.AddUint32(&s.sendWindow, hdr.Length()) asyncNotify(s.sendNotifyCh) return nil }
[ "func", "(", "s", "*", "Stream", ")", "incrSendWindow", "(", "hdr", "header", ",", "flags", "uint16", ")", "error", "{", "if", "err", ":=", "s", ".", "processFlags", "(", "flags", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n...
// incrSendWindow updates the size of our send window
[ "incrSendWindow", "updates", "the", "size", "of", "our", "send", "window" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L384-L393
train
hashicorp/yamux
stream.go
readData
func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { if err := s.processFlags(flags); err != nil { return err } // Check that our recv window is not exceeded length := hdr.Length() if length == 0 { return nil } // Wrap in a limited reader conn = &io.LimitedReader{R: conn, N: int64(l...
go
func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { if err := s.processFlags(flags); err != nil { return err } // Check that our recv window is not exceeded length := hdr.Length() if length == 0 { return nil } // Wrap in a limited reader conn = &io.LimitedReader{R: conn, N: int64(l...
[ "func", "(", "s", "*", "Stream", ")", "readData", "(", "hdr", "header", ",", "flags", "uint16", ",", "conn", "io", ".", "Reader", ")", "error", "{", "if", "err", ":=", "s", ".", "processFlags", "(", "flags", ")", ";", "err", "!=", "nil", "{", "re...
// readData is used to handle a data frame
[ "readData", "is", "used", "to", "handle", "a", "data", "frame" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L396-L436
train
hashicorp/yamux
stream.go
SetDeadline
func (s *Stream) SetDeadline(t time.Time) error { if err := s.SetReadDeadline(t); err != nil { return err } if err := s.SetWriteDeadline(t); err != nil { return err } return nil }
go
func (s *Stream) SetDeadline(t time.Time) error { if err := s.SetReadDeadline(t); err != nil { return err } if err := s.SetWriteDeadline(t); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Stream", ")", "SetDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "if", "err", ":=", "s", ".", "SetReadDeadline", "(", "t", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "...
// SetDeadline sets the read and write deadlines
[ "SetDeadline", "sets", "the", "read", "and", "write", "deadlines" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L439-L447
train
hashicorp/yamux
stream.go
SetWriteDeadline
func (s *Stream) SetWriteDeadline(t time.Time) error { s.writeDeadline.Store(t) return nil }
go
func (s *Stream) SetWriteDeadline(t time.Time) error { s.writeDeadline.Store(t) return nil }
[ "func", "(", "s", "*", "Stream", ")", "SetWriteDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "s", ".", "writeDeadline", ".", "Store", "(", "t", ")", "\n", "return", "nil", "\n", "}" ]
// SetWriteDeadline sets the deadline for future Write calls
[ "SetWriteDeadline", "sets", "the", "deadline", "for", "future", "Write", "calls" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L456-L459
train
hashicorp/yamux
stream.go
Shrink
func (s *Stream) Shrink() { s.recvLock.Lock() if s.recvBuf != nil && s.recvBuf.Len() == 0 { s.recvBuf = nil } s.recvLock.Unlock() }
go
func (s *Stream) Shrink() { s.recvLock.Lock() if s.recvBuf != nil && s.recvBuf.Len() == 0 { s.recvBuf = nil } s.recvLock.Unlock() }
[ "func", "(", "s", "*", "Stream", ")", "Shrink", "(", ")", "{", "s", ".", "recvLock", ".", "Lock", "(", ")", "\n", "if", "s", ".", "recvBuf", "!=", "nil", "&&", "s", ".", "recvBuf", ".", "Len", "(", ")", "==", "0", "{", "s", ".", "recvBuf", ...
// Shrink is used to compact the amount of buffers utilized // This is useful when using Yamux in a connection pool to reduce // the idle memory utilization.
[ "Shrink", "is", "used", "to", "compact", "the", "amount", "of", "buffers", "utilized", "This", "is", "useful", "when", "using", "Yamux", "in", "a", "connection", "pool", "to", "reduce", "the", "idle", "memory", "utilization", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L464-L470
train
hashicorp/yamux
mux.go
Server
func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, false), nil }
go
func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, false), nil }
[ "func", "Server", "(", "conn", "io", ".", "ReadWriteCloser", ",", "config", "*", "Config", ")", "(", "*", "Session", ",", "error", ")", "{", "if", "config", "==", "nil", "{", "config", "=", "DefaultConfig", "(", ")", "\n", "}", "\n", "if", "err", "...
// Server is used to initialize a new server-side connection. // There must be at most one server-side connection. If a nil config is // provided, the DefaultConfiguration will be used.
[ "Server", "is", "used", "to", "initialize", "a", "new", "server", "-", "side", "connection", ".", "There", "must", "be", "at", "most", "one", "server", "-", "side", "connection", ".", "If", "a", "nil", "config", "is", "provided", "the", "DefaultConfigurati...
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/mux.go#L77-L85
train
hashicorp/yamux
mux.go
Client
func Client(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, true), nil }
go
func Client(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, true), nil }
[ "func", "Client", "(", "conn", "io", ".", "ReadWriteCloser", ",", "config", "*", "Config", ")", "(", "*", "Session", ",", "error", ")", "{", "if", "config", "==", "nil", "{", "config", "=", "DefaultConfig", "(", ")", "\n", "}", "\n\n", "if", "err", ...
// Client is used to initialize a new client-side connection. // There must be at most one client-side connection.
[ "Client", "is", "used", "to", "initialize", "a", "new", "client", "-", "side", "connection", ".", "There", "must", "be", "at", "most", "one", "client", "-", "side", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/mux.go#L89-L98
train
hashicorp/yamux
session.go
newSession
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session { logger := config.Logger if logger == nil { logger = log.New(config.LogOutput, "", log.LstdFlags) } s := &Session{ config: config, logger: logger, conn: conn, bufRead: bufio.NewReader(conn), pings: mak...
go
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session { logger := config.Logger if logger == nil { logger = log.New(config.LogOutput, "", log.LstdFlags) } s := &Session{ config: config, logger: logger, conn: conn, bufRead: bufio.NewReader(conn), pings: mak...
[ "func", "newSession", "(", "config", "*", "Config", ",", "conn", "io", ".", "ReadWriteCloser", ",", "client", "bool", ")", "*", "Session", "{", "logger", ":=", "config", ".", "Logger", "\n", "if", "logger", "==", "nil", "{", "logger", "=", "log", ".", ...
// newSession is used to construct a new session
[ "newSession", "is", "used", "to", "construct", "a", "new", "session" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L88-L119
train
hashicorp/yamux
session.go
NumStreams
func (s *Session) NumStreams() int { s.streamLock.Lock() num := len(s.streams) s.streamLock.Unlock() return num }
go
func (s *Session) NumStreams() int { s.streamLock.Lock() num := len(s.streams) s.streamLock.Unlock() return num }
[ "func", "(", "s", "*", "Session", ")", "NumStreams", "(", ")", "int", "{", "s", ".", "streamLock", ".", "Lock", "(", ")", "\n", "num", ":=", "len", "(", "s", ".", "streams", ")", "\n", "s", ".", "streamLock", ".", "Unlock", "(", ")", "\n", "ret...
// NumStreams returns the number of currently open streams
[ "NumStreams", "returns", "the", "number", "of", "currently", "open", "streams" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L138-L143
train
hashicorp/yamux
session.go
Open
func (s *Session) Open() (net.Conn, error) { conn, err := s.OpenStream() if err != nil { return nil, err } return conn, nil }
go
func (s *Session) Open() (net.Conn, error) { conn, err := s.OpenStream() if err != nil { return nil, err } return conn, nil }
[ "func", "(", "s", "*", "Session", ")", "Open", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "s", ".", "OpenStream", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}",...
// Open is used to create a new stream as a net.Conn
[ "Open", "is", "used", "to", "create", "a", "new", "stream", "as", "a", "net", ".", "Conn" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L146-L152
train
hashicorp/yamux
session.go
Accept
func (s *Session) Accept() (net.Conn, error) { conn, err := s.AcceptStream() if err != nil { return nil, err } return conn, err }
go
func (s *Session) Accept() (net.Conn, error) { conn, err := s.AcceptStream() if err != nil { return nil, err } return conn, err }
[ "func", "(", "s", "*", "Session", ")", "Accept", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "s", ".", "AcceptStream", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", ...
// Accept is used to block until the next available stream // is ready to be accepted.
[ "Accept", "is", "used", "to", "block", "until", "the", "next", "available", "stream", "is", "ready", "to", "be", "accepted", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L201-L207
train
hashicorp/yamux
session.go
Close
func (s *Session) Close() error { s.shutdownLock.Lock() defer s.shutdownLock.Unlock() if s.shutdown { return nil } s.shutdown = true if s.shutdownErr == nil { s.shutdownErr = ErrSessionShutdown } close(s.shutdownCh) s.conn.Close() <-s.recvDoneCh s.streamLock.Lock() defer s.streamLock.Unlock() for _, ...
go
func (s *Session) Close() error { s.shutdownLock.Lock() defer s.shutdownLock.Unlock() if s.shutdown { return nil } s.shutdown = true if s.shutdownErr == nil { s.shutdownErr = ErrSessionShutdown } close(s.shutdownCh) s.conn.Close() <-s.recvDoneCh s.streamLock.Lock() defer s.streamLock.Unlock() for _, ...
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "error", "{", "s", ".", "shutdownLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "shutdownLock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "shutdown", "{", "return", "nil", "...
// Close is used to close the session and all streams. // Attempts to send a GoAway before closing the connection.
[ "Close", "is", "used", "to", "close", "the", "session", "and", "all", "streams", ".", "Attempts", "to", "send", "a", "GoAway", "before", "closing", "the", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L225-L246
train
hashicorp/yamux
session.go
exitErr
func (s *Session) exitErr(err error) { s.shutdownLock.Lock() if s.shutdownErr == nil { s.shutdownErr = err } s.shutdownLock.Unlock() s.Close() }
go
func (s *Session) exitErr(err error) { s.shutdownLock.Lock() if s.shutdownErr == nil { s.shutdownErr = err } s.shutdownLock.Unlock() s.Close() }
[ "func", "(", "s", "*", "Session", ")", "exitErr", "(", "err", "error", ")", "{", "s", ".", "shutdownLock", ".", "Lock", "(", ")", "\n", "if", "s", ".", "shutdownErr", "==", "nil", "{", "s", ".", "shutdownErr", "=", "err", "\n", "}", "\n", "s", ...
// exitErr is used to handle an error that is causing the // session to terminate.
[ "exitErr", "is", "used", "to", "handle", "an", "error", "that", "is", "causing", "the", "session", "to", "terminate", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L250-L257
train
hashicorp/yamux
session.go
GoAway
func (s *Session) GoAway() error { return s.waitForSend(s.goAway(goAwayNormal), nil) }
go
func (s *Session) GoAway() error { return s.waitForSend(s.goAway(goAwayNormal), nil) }
[ "func", "(", "s", "*", "Session", ")", "GoAway", "(", ")", "error", "{", "return", "s", ".", "waitForSend", "(", "s", ".", "goAway", "(", "goAwayNormal", ")", ",", "nil", ")", "\n", "}" ]
// GoAway can be used to prevent accepting further // connections. It does not close the underlying conn.
[ "GoAway", "can", "be", "used", "to", "prevent", "accepting", "further", "connections", ".", "It", "does", "not", "close", "the", "underlying", "conn", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L261-L263
train
hashicorp/yamux
session.go
goAway
func (s *Session) goAway(reason uint32) header { atomic.SwapInt32(&s.localGoAway, 1) hdr := header(make([]byte, headerSize)) hdr.encode(typeGoAway, 0, 0, reason) return hdr }
go
func (s *Session) goAway(reason uint32) header { atomic.SwapInt32(&s.localGoAway, 1) hdr := header(make([]byte, headerSize)) hdr.encode(typeGoAway, 0, 0, reason) return hdr }
[ "func", "(", "s", "*", "Session", ")", "goAway", "(", "reason", "uint32", ")", "header", "{", "atomic", ".", "SwapInt32", "(", "&", "s", ".", "localGoAway", ",", "1", ")", "\n", "hdr", ":=", "header", "(", "make", "(", "[", "]", "byte", ",", "hea...
// goAway is used to send a goAway message
[ "goAway", "is", "used", "to", "send", "a", "goAway", "message" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L266-L271
train
hashicorp/yamux
session.go
Ping
func (s *Session) Ping() (time.Duration, error) { // Get a channel for the ping ch := make(chan struct{}) // Get a new ping id, mark as pending s.pingLock.Lock() id := s.pingID s.pingID++ s.pings[id] = ch s.pingLock.Unlock() // Send the ping request hdr := header(make([]byte, headerSize)) hdr.encode(typePi...
go
func (s *Session) Ping() (time.Duration, error) { // Get a channel for the ping ch := make(chan struct{}) // Get a new ping id, mark as pending s.pingLock.Lock() id := s.pingID s.pingID++ s.pings[id] = ch s.pingLock.Unlock() // Send the ping request hdr := header(make([]byte, headerSize)) hdr.encode(typePi...
[ "func", "(", "s", "*", "Session", ")", "Ping", "(", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "// Get a channel for the ping", "ch", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n\n", "// Get a new ping id, mark as pending", "s", ...
// Ping is used to measure the RTT response time
[ "Ping", "is", "used", "to", "measure", "the", "RTT", "response", "time" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L274-L307
train
hashicorp/yamux
session.go
keepalive
func (s *Session) keepalive() { for { select { case <-time.After(s.config.KeepAliveInterval): _, err := s.Ping() if err != nil { if err != ErrSessionShutdown { s.logger.Printf("[ERR] yamux: keepalive failed: %v", err) s.exitErr(ErrKeepAliveTimeout) } return } case <-s.shutdownCh: ...
go
func (s *Session) keepalive() { for { select { case <-time.After(s.config.KeepAliveInterval): _, err := s.Ping() if err != nil { if err != ErrSessionShutdown { s.logger.Printf("[ERR] yamux: keepalive failed: %v", err) s.exitErr(ErrKeepAliveTimeout) } return } case <-s.shutdownCh: ...
[ "func", "(", "s", "*", "Session", ")", "keepalive", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "time", ".", "After", "(", "s", ".", "config", ".", "KeepAliveInterval", ")", ":", "_", ",", "err", ":=", "s", ".", "Ping", "(", ")", "\...
// keepalive is a long running goroutine that periodically does // a ping to keep the connection alive.
[ "keepalive", "is", "a", "long", "running", "goroutine", "that", "periodically", "does", "a", "ping", "to", "keep", "the", "connection", "alive", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L311-L327
train
hashicorp/yamux
session.go
waitForSend
func (s *Session) waitForSend(hdr header, body io.Reader) error { errCh := make(chan error, 1) return s.waitForSendErr(hdr, body, errCh) }
go
func (s *Session) waitForSend(hdr header, body io.Reader) error { errCh := make(chan error, 1) return s.waitForSendErr(hdr, body, errCh) }
[ "func", "(", "s", "*", "Session", ")", "waitForSend", "(", "hdr", "header", ",", "body", "io", ".", "Reader", ")", "error", "{", "errCh", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n", "return", "s", ".", "waitForSendErr", "(", "hdr", ","...
// waitForSendErr waits to send a header, checking for a potential shutdown
[ "waitForSendErr", "waits", "to", "send", "a", "header", "checking", "for", "a", "potential", "shutdown" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L330-L333
train
hashicorp/yamux
session.go
waitForSendErr
func (s *Session) waitForSendErr(hdr header, body io.Reader, errCh chan error) error { t := timerPool.Get() timer := t.(*time.Timer) timer.Reset(s.config.ConnectionWriteTimeout) defer func() { timer.Stop() select { case <-timer.C: default: } timerPool.Put(t) }() ready := sendReady{Hdr: hdr, Body: bod...
go
func (s *Session) waitForSendErr(hdr header, body io.Reader, errCh chan error) error { t := timerPool.Get() timer := t.(*time.Timer) timer.Reset(s.config.ConnectionWriteTimeout) defer func() { timer.Stop() select { case <-timer.C: default: } timerPool.Put(t) }() ready := sendReady{Hdr: hdr, Body: bod...
[ "func", "(", "s", "*", "Session", ")", "waitForSendErr", "(", "hdr", "header", ",", "body", "io", ".", "Reader", ",", "errCh", "chan", "error", ")", "error", "{", "t", ":=", "timerPool", ".", "Get", "(", ")", "\n", "timer", ":=", "t", ".", "(", "...
// waitForSendErr waits to send a header with optional data, checking for a // potential shutdown. Since there's the expectation that sends can happen // in a timely manner, we enforce the connection write timeout here.
[ "waitForSendErr", "waits", "to", "send", "a", "header", "with", "optional", "data", "checking", "for", "a", "potential", "shutdown", ".", "Since", "there", "s", "the", "expectation", "that", "sends", "can", "happen", "in", "a", "timely", "manner", "we", "enf...
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L338-L368
train
hashicorp/yamux
session.go
sendNoWait
func (s *Session) sendNoWait(hdr header) error { t := timerPool.Get() timer := t.(*time.Timer) timer.Reset(s.config.ConnectionWriteTimeout) defer func() { timer.Stop() select { case <-timer.C: default: } timerPool.Put(t) }() select { case s.sendCh <- sendReady{Hdr: hdr}: return nil case <-s.shutd...
go
func (s *Session) sendNoWait(hdr header) error { t := timerPool.Get() timer := t.(*time.Timer) timer.Reset(s.config.ConnectionWriteTimeout) defer func() { timer.Stop() select { case <-timer.C: default: } timerPool.Put(t) }() select { case s.sendCh <- sendReady{Hdr: hdr}: return nil case <-s.shutd...
[ "func", "(", "s", "*", "Session", ")", "sendNoWait", "(", "hdr", "header", ")", "error", "{", "t", ":=", "timerPool", ".", "Get", "(", ")", "\n", "timer", ":=", "t", ".", "(", "*", "time", ".", "Timer", ")", "\n", "timer", ".", "Reset", "(", "s...
// sendNoWait does a send without waiting. Since there's the expectation that // the send happens right here, we enforce the connection write timeout if we // can't queue the header to be sent.
[ "sendNoWait", "does", "a", "send", "without", "waiting", ".", "Since", "there", "s", "the", "expectation", "that", "the", "send", "happens", "right", "here", "we", "enforce", "the", "connection", "write", "timeout", "if", "we", "can", "t", "queue", "the", ...
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L373-L394
train
hashicorp/yamux
session.go
send
func (s *Session) send() { for { select { case ready := <-s.sendCh: // Send a header if ready if ready.Hdr != nil { sent := 0 for sent < len(ready.Hdr) { n, err := s.conn.Write(ready.Hdr[sent:]) if err != nil { s.logger.Printf("[ERR] yamux: Failed to write header: %v", err) asyn...
go
func (s *Session) send() { for { select { case ready := <-s.sendCh: // Send a header if ready if ready.Hdr != nil { sent := 0 for sent < len(ready.Hdr) { n, err := s.conn.Write(ready.Hdr[sent:]) if err != nil { s.logger.Printf("[ERR] yamux: Failed to write header: %v", err) asyn...
[ "func", "(", "s", "*", "Session", ")", "send", "(", ")", "{", "for", "{", "select", "{", "case", "ready", ":=", "<-", "s", ".", "sendCh", ":", "// Send a header if ready", "if", "ready", ".", "Hdr", "!=", "nil", "{", "sent", ":=", "0", "\n", "for",...
// send is a long running goroutine that sends data
[ "send", "is", "a", "long", "running", "goroutine", "that", "sends", "data" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L397-L433
train
hashicorp/yamux
session.go
recv
func (s *Session) recv() { if err := s.recvLoop(); err != nil { s.exitErr(err) } }
go
func (s *Session) recv() { if err := s.recvLoop(); err != nil { s.exitErr(err) } }
[ "func", "(", "s", "*", "Session", ")", "recv", "(", ")", "{", "if", "err", ":=", "s", ".", "recvLoop", "(", ")", ";", "err", "!=", "nil", "{", "s", ".", "exitErr", "(", "err", ")", "\n", "}", "\n", "}" ]
// recv is a long running goroutine that accepts new data
[ "recv", "is", "a", "long", "running", "goroutine", "that", "accepts", "new", "data" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L436-L440
train
hashicorp/yamux
session.go
recvLoop
func (s *Session) recvLoop() error { defer close(s.recvDoneCh) hdr := header(make([]byte, headerSize)) for { // Read the header if _, err := io.ReadFull(s.bufRead, hdr); err != nil { if err != io.EOF && !strings.Contains(err.Error(), "closed") && !strings.Contains(err.Error(), "reset by peer") { s.logger....
go
func (s *Session) recvLoop() error { defer close(s.recvDoneCh) hdr := header(make([]byte, headerSize)) for { // Read the header if _, err := io.ReadFull(s.bufRead, hdr); err != nil { if err != io.EOF && !strings.Contains(err.Error(), "closed") && !strings.Contains(err.Error(), "reset by peer") { s.logger....
[ "func", "(", "s", "*", "Session", ")", "recvLoop", "(", ")", "error", "{", "defer", "close", "(", "s", ".", "recvDoneCh", ")", "\n", "hdr", ":=", "header", "(", "make", "(", "[", "]", "byte", ",", "headerSize", ")", ")", "\n", "for", "{", "// Rea...
// recvLoop continues to receive data until a fatal error is encountered
[ "recvLoop", "continues", "to", "receive", "data", "until", "a", "fatal", "error", "is", "encountered" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L453-L480
train
hashicorp/yamux
session.go
handleStreamMessage
func (s *Session) handleStreamMessage(hdr header) error { // Check for a new stream creation id := hdr.StreamID() flags := hdr.Flags() if flags&flagSYN == flagSYN { if err := s.incomingStream(id); err != nil { return err } } // Get the stream s.streamLock.Lock() stream := s.streams[id] s.streamLock.Unl...
go
func (s *Session) handleStreamMessage(hdr header) error { // Check for a new stream creation id := hdr.StreamID() flags := hdr.Flags() if flags&flagSYN == flagSYN { if err := s.incomingStream(id); err != nil { return err } } // Get the stream s.streamLock.Lock() stream := s.streams[id] s.streamLock.Unl...
[ "func", "(", "s", "*", "Session", ")", "handleStreamMessage", "(", "hdr", "header", ")", "error", "{", "// Check for a new stream creation", "id", ":=", "hdr", ".", "StreamID", "(", ")", "\n", "flags", ":=", "hdr", ".", "Flags", "(", ")", "\n", "if", "fl...
// handleStreamMessage handles either a data or window update frame
[ "handleStreamMessage", "handles", "either", "a", "data", "or", "window", "update", "frame" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L483-L532
train
hashicorp/yamux
session.go
handlePing
func (s *Session) handlePing(hdr header) error { flags := hdr.Flags() pingID := hdr.Length() // Check if this is a query, respond back in a separate context so we // don't interfere with the receiving thread blocking for the write. if flags&flagSYN == flagSYN { go func() { hdr := header(make([]byte, headerSi...
go
func (s *Session) handlePing(hdr header) error { flags := hdr.Flags() pingID := hdr.Length() // Check if this is a query, respond back in a separate context so we // don't interfere with the receiving thread blocking for the write. if flags&flagSYN == flagSYN { go func() { hdr := header(make([]byte, headerSi...
[ "func", "(", "s", "*", "Session", ")", "handlePing", "(", "hdr", "header", ")", "error", "{", "flags", ":=", "hdr", ".", "Flags", "(", ")", "\n", "pingID", ":=", "hdr", ".", "Length", "(", ")", "\n\n", "// Check if this is a query, respond back in a separate...
// handlePing is invokde for a typePing frame
[ "handlePing", "is", "invokde", "for", "a", "typePing", "frame" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L535-L561
train
hashicorp/yamux
session.go
handleGoAway
func (s *Session) handleGoAway(hdr header) error { code := hdr.Length() switch code { case goAwayNormal: atomic.SwapInt32(&s.remoteGoAway, 1) case goAwayProtoErr: s.logger.Printf("[ERR] yamux: received protocol error go away") return fmt.Errorf("yamux protocol error") case goAwayInternalErr: s.logger.Print...
go
func (s *Session) handleGoAway(hdr header) error { code := hdr.Length() switch code { case goAwayNormal: atomic.SwapInt32(&s.remoteGoAway, 1) case goAwayProtoErr: s.logger.Printf("[ERR] yamux: received protocol error go away") return fmt.Errorf("yamux protocol error") case goAwayInternalErr: s.logger.Print...
[ "func", "(", "s", "*", "Session", ")", "handleGoAway", "(", "hdr", "header", ")", "error", "{", "code", ":=", "hdr", ".", "Length", "(", ")", "\n", "switch", "code", "{", "case", "goAwayNormal", ":", "atomic", ".", "SwapInt32", "(", "&", "s", ".", ...
// handleGoAway is invokde for a typeGoAway frame
[ "handleGoAway", "is", "invokde", "for", "a", "typeGoAway", "frame" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L564-L580
train
hashicorp/yamux
session.go
incomingStream
func (s *Session) incomingStream(id uint32) error { // Reject immediately if we are doing a go away if atomic.LoadInt32(&s.localGoAway) == 1 { hdr := header(make([]byte, headerSize)) hdr.encode(typeWindowUpdate, flagRST, id, 0) return s.sendNoWait(hdr) } // Allocate a new stream stream := newStream(s, id, s...
go
func (s *Session) incomingStream(id uint32) error { // Reject immediately if we are doing a go away if atomic.LoadInt32(&s.localGoAway) == 1 { hdr := header(make([]byte, headerSize)) hdr.encode(typeWindowUpdate, flagRST, id, 0) return s.sendNoWait(hdr) } // Allocate a new stream stream := newStream(s, id, s...
[ "func", "(", "s", "*", "Session", ")", "incomingStream", "(", "id", "uint32", ")", "error", "{", "// Reject immediately if we are doing a go away", "if", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "localGoAway", ")", "==", "1", "{", "hdr", ":=", "header...
// incomingStream is used to create a new incoming stream
[ "incomingStream", "is", "used", "to", "create", "a", "new", "incoming", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L583-L620
train
hashicorp/yamux
session.go
closeStream
func (s *Session) closeStream(id uint32) { s.streamLock.Lock() if _, ok := s.inflight[id]; ok { select { case <-s.synCh: default: s.logger.Printf("[ERR] yamux: SYN tracking out of sync") } } delete(s.streams, id) s.streamLock.Unlock() }
go
func (s *Session) closeStream(id uint32) { s.streamLock.Lock() if _, ok := s.inflight[id]; ok { select { case <-s.synCh: default: s.logger.Printf("[ERR] yamux: SYN tracking out of sync") } } delete(s.streams, id) s.streamLock.Unlock() }
[ "func", "(", "s", "*", "Session", ")", "closeStream", "(", "id", "uint32", ")", "{", "s", ".", "streamLock", ".", "Lock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "s", ".", "inflight", "[", "id", "]", ";", "ok", "{", "select", "{", "case", ...
// closeStream is used to close a stream once both sides have // issued a close. If there was an in-flight SYN and the stream // was not yet established, then this will give the credit back.
[ "closeStream", "is", "used", "to", "close", "a", "stream", "once", "both", "sides", "have", "issued", "a", "close", ".", "If", "there", "was", "an", "in", "-", "flight", "SYN", "and", "the", "stream", "was", "not", "yet", "established", "then", "this", ...
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L625-L636
train
afex/hystrix-go
plugins/graphite_aggregator.go
InitializeGraphiteCollector
func InitializeGraphiteCollector(config *GraphiteCollectorConfig) { go metrics.Graphite(metrics.DefaultRegistry, config.TickInterval, config.Prefix, config.GraphiteAddr) }
go
func InitializeGraphiteCollector(config *GraphiteCollectorConfig) { go metrics.Graphite(metrics.DefaultRegistry, config.TickInterval, config.Prefix, config.GraphiteAddr) }
[ "func", "InitializeGraphiteCollector", "(", "config", "*", "GraphiteCollectorConfig", ")", "{", "go", "metrics", ".", "Graphite", "(", "metrics", ".", "DefaultRegistry", ",", "config", ".", "TickInterval", ",", "config", ".", "Prefix", ",", "config", ".", "Graph...
// InitializeGraphiteCollector creates the connection to the graphite server // and should be called before any metrics are recorded.
[ "InitializeGraphiteCollector", "creates", "the", "connection", "to", "the", "graphite", "server", "and", "should", "be", "called", "before", "any", "metrics", "are", "recorded", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/plugins/graphite_aggregator.go#L49-L51
train
afex/hystrix-go
hystrix/circuit.go
GetCircuit
func GetCircuit(name string) (*CircuitBreaker, bool, error) { circuitBreakersMutex.RLock() _, ok := circuitBreakers[name] if !ok { circuitBreakersMutex.RUnlock() circuitBreakersMutex.Lock() defer circuitBreakersMutex.Unlock() // because we released the rlock before we obtained the exclusive lock, // we nee...
go
func GetCircuit(name string) (*CircuitBreaker, bool, error) { circuitBreakersMutex.RLock() _, ok := circuitBreakers[name] if !ok { circuitBreakersMutex.RUnlock() circuitBreakersMutex.Lock() defer circuitBreakersMutex.Unlock() // because we released the rlock before we obtained the exclusive lock, // we nee...
[ "func", "GetCircuit", "(", "name", "string", ")", "(", "*", "CircuitBreaker", ",", "bool", ",", "error", ")", "{", "circuitBreakersMutex", ".", "RLock", "(", ")", "\n", "_", ",", "ok", ":=", "circuitBreakers", "[", "name", "]", "\n", "if", "!", "ok", ...
// GetCircuit returns the circuit for the given command and whether this call created it.
[ "GetCircuit", "returns", "the", "circuit", "for", "the", "given", "command", "and", "whether", "this", "call", "created", "it", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L34-L53
train
afex/hystrix-go
hystrix/circuit.go
Flush
func Flush() { circuitBreakersMutex.Lock() defer circuitBreakersMutex.Unlock() for name, cb := range circuitBreakers { cb.metrics.Reset() cb.executorPool.Metrics.Reset() delete(circuitBreakers, name) } }
go
func Flush() { circuitBreakersMutex.Lock() defer circuitBreakersMutex.Unlock() for name, cb := range circuitBreakers { cb.metrics.Reset() cb.executorPool.Metrics.Reset() delete(circuitBreakers, name) } }
[ "func", "Flush", "(", ")", "{", "circuitBreakersMutex", ".", "Lock", "(", ")", "\n", "defer", "circuitBreakersMutex", ".", "Unlock", "(", ")", "\n\n", "for", "name", ",", "cb", ":=", "range", "circuitBreakers", "{", "cb", ".", "metrics", ".", "Reset", "(...
// Flush purges all circuit and metric information from memory.
[ "Flush", "purges", "all", "circuit", "and", "metric", "information", "from", "memory", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L56-L65
train
afex/hystrix-go
hystrix/circuit.go
newCircuitBreaker
func newCircuitBreaker(name string) *CircuitBreaker { c := &CircuitBreaker{} c.Name = name c.metrics = newMetricExchange(name) c.executorPool = newExecutorPool(name) c.mutex = &sync.RWMutex{} return c }
go
func newCircuitBreaker(name string) *CircuitBreaker { c := &CircuitBreaker{} c.Name = name c.metrics = newMetricExchange(name) c.executorPool = newExecutorPool(name) c.mutex = &sync.RWMutex{} return c }
[ "func", "newCircuitBreaker", "(", "name", "string", ")", "*", "CircuitBreaker", "{", "c", ":=", "&", "CircuitBreaker", "{", "}", "\n", "c", ".", "Name", "=", "name", "\n", "c", ".", "metrics", "=", "newMetricExchange", "(", "name", ")", "\n", "c", ".",...
// newCircuitBreaker creates a CircuitBreaker with associated Health
[ "newCircuitBreaker", "creates", "a", "CircuitBreaker", "with", "associated", "Health" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L68-L76
train
afex/hystrix-go
hystrix/circuit.go
toggleForceOpen
func (circuit *CircuitBreaker) toggleForceOpen(toggle bool) error { circuit, _, err := GetCircuit(circuit.Name) if err != nil { return err } circuit.forceOpen = toggle return nil }
go
func (circuit *CircuitBreaker) toggleForceOpen(toggle bool) error { circuit, _, err := GetCircuit(circuit.Name) if err != nil { return err } circuit.forceOpen = toggle return nil }
[ "func", "(", "circuit", "*", "CircuitBreaker", ")", "toggleForceOpen", "(", "toggle", "bool", ")", "error", "{", "circuit", ",", "_", ",", "err", ":=", "GetCircuit", "(", "circuit", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err"...
// toggleForceOpen allows manually causing the fallback logic for all instances // of a given command.
[ "toggleForceOpen", "allows", "manually", "causing", "the", "fallback", "logic", "for", "all", "instances", "of", "a", "given", "command", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L80-L88
train
afex/hystrix-go
hystrix/circuit.go
IsOpen
func (circuit *CircuitBreaker) IsOpen() bool { circuit.mutex.RLock() o := circuit.forceOpen || circuit.open circuit.mutex.RUnlock() if o { return true } if uint64(circuit.metrics.Requests().Sum(time.Now())) < getSettings(circuit.Name).RequestVolumeThreshold { return false } if !circuit.metrics.IsHealthy(...
go
func (circuit *CircuitBreaker) IsOpen() bool { circuit.mutex.RLock() o := circuit.forceOpen || circuit.open circuit.mutex.RUnlock() if o { return true } if uint64(circuit.metrics.Requests().Sum(time.Now())) < getSettings(circuit.Name).RequestVolumeThreshold { return false } if !circuit.metrics.IsHealthy(...
[ "func", "(", "circuit", "*", "CircuitBreaker", ")", "IsOpen", "(", ")", "bool", "{", "circuit", ".", "mutex", ".", "RLock", "(", ")", "\n", "o", ":=", "circuit", ".", "forceOpen", "||", "circuit", ".", "open", "\n", "circuit", ".", "mutex", ".", "RUn...
// IsOpen is called before any Command execution to check whether or // not it should be attempted. An "open" circuit means it is disabled.
[ "IsOpen", "is", "called", "before", "any", "Command", "execution", "to", "check", "whether", "or", "not", "it", "should", "be", "attempted", ".", "An", "open", "circuit", "means", "it", "is", "disabled", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L92-L112
train
afex/hystrix-go
hystrix/circuit.go
ReportEvent
func (circuit *CircuitBreaker) ReportEvent(eventTypes []string, start time.Time, runDuration time.Duration) error { if len(eventTypes) == 0 { return fmt.Errorf("no event types sent for metrics") } circuit.mutex.RLock() o := circuit.open circuit.mutex.RUnlock() if eventTypes[0] == "success" && o { circuit.set...
go
func (circuit *CircuitBreaker) ReportEvent(eventTypes []string, start time.Time, runDuration time.Duration) error { if len(eventTypes) == 0 { return fmt.Errorf("no event types sent for metrics") } circuit.mutex.RLock() o := circuit.open circuit.mutex.RUnlock() if eventTypes[0] == "success" && o { circuit.set...
[ "func", "(", "circuit", "*", "CircuitBreaker", ")", "ReportEvent", "(", "eventTypes", "[", "]", "string", ",", "start", "time", ".", "Time", ",", "runDuration", "time", ".", "Duration", ")", "error", "{", "if", "len", "(", "eventTypes", ")", "==", "0", ...
// ReportEvent records command metrics for tracking recent error rates and exposing data to the dashboard.
[ "ReportEvent", "records", "command", "metrics", "for", "tracking", "recent", "error", "rates", "and", "exposing", "data", "to", "the", "dashboard", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/circuit.go#L167-L196
train
afex/hystrix-go
hystrix/rolling/rolling.go
NewNumber
func NewNumber() *Number { r := &Number{ Buckets: make(map[int64]*numberBucket), Mutex: &sync.RWMutex{}, } return r }
go
func NewNumber() *Number { r := &Number{ Buckets: make(map[int64]*numberBucket), Mutex: &sync.RWMutex{}, } return r }
[ "func", "NewNumber", "(", ")", "*", "Number", "{", "r", ":=", "&", "Number", "{", "Buckets", ":", "make", "(", "map", "[", "int64", "]", "*", "numberBucket", ")", ",", "Mutex", ":", "&", "sync", ".", "RWMutex", "{", "}", ",", "}", "\n", "return",...
// NewNumber initializes a RollingNumber struct.
[ "NewNumber", "initializes", "a", "RollingNumber", "struct", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling.go#L20-L26
train
afex/hystrix-go
hystrix/rolling/rolling.go
Increment
func (r *Number) Increment(i float64) { if i == 0 { return } r.Mutex.Lock() defer r.Mutex.Unlock() b := r.getCurrentBucket() b.Value += i r.removeOldBuckets() }
go
func (r *Number) Increment(i float64) { if i == 0 { return } r.Mutex.Lock() defer r.Mutex.Unlock() b := r.getCurrentBucket() b.Value += i r.removeOldBuckets() }
[ "func", "(", "r", "*", "Number", ")", "Increment", "(", "i", "float64", ")", "{", "if", "i", "==", "0", "{", "return", "\n", "}", "\n\n", "r", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Mutex", ".", "Unlock", "(", ")", "\n...
// Increment increments the number in current timeBucket.
[ "Increment", "increments", "the", "number", "in", "current", "timeBucket", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling.go#L53-L64
train
afex/hystrix-go
hystrix/rolling/rolling.go
UpdateMax
func (r *Number) UpdateMax(n float64) { r.Mutex.Lock() defer r.Mutex.Unlock() b := r.getCurrentBucket() if n > b.Value { b.Value = n } r.removeOldBuckets() }
go
func (r *Number) UpdateMax(n float64) { r.Mutex.Lock() defer r.Mutex.Unlock() b := r.getCurrentBucket() if n > b.Value { b.Value = n } r.removeOldBuckets() }
[ "func", "(", "r", "*", "Number", ")", "UpdateMax", "(", "n", "float64", ")", "{", "r", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Mutex", ".", "Unlock", "(", ")", "\n\n", "b", ":=", "r", ".", "getCurrentBucket", "(", ")", "\...
// UpdateMax updates the maximum value in the current bucket.
[ "UpdateMax", "updates", "the", "maximum", "value", "in", "the", "current", "bucket", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling.go#L67-L76
train
afex/hystrix-go
hystrix/rolling/rolling.go
Sum
func (r *Number) Sum(now time.Time) float64 { sum := float64(0) r.Mutex.RLock() defer r.Mutex.RUnlock() for timestamp, bucket := range r.Buckets { // TODO: configurable rolling window if timestamp >= now.Unix()-10 { sum += bucket.Value } } return sum }
go
func (r *Number) Sum(now time.Time) float64 { sum := float64(0) r.Mutex.RLock() defer r.Mutex.RUnlock() for timestamp, bucket := range r.Buckets { // TODO: configurable rolling window if timestamp >= now.Unix()-10 { sum += bucket.Value } } return sum }
[ "func", "(", "r", "*", "Number", ")", "Sum", "(", "now", "time", ".", "Time", ")", "float64", "{", "sum", ":=", "float64", "(", "0", ")", "\n\n", "r", ".", "Mutex", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "Mutex", ".", "RUnlock", "(", ...
// Sum sums the values over the buckets in the last 10 seconds.
[ "Sum", "sums", "the", "values", "over", "the", "buckets", "in", "the", "last", "10", "seconds", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling.go#L79-L93
train
afex/hystrix-go
hystrix/rolling/rolling.go
Max
func (r *Number) Max(now time.Time) float64 { var max float64 r.Mutex.RLock() defer r.Mutex.RUnlock() for timestamp, bucket := range r.Buckets { // TODO: configurable rolling window if timestamp >= now.Unix()-10 { if bucket.Value > max { max = bucket.Value } } } return max }
go
func (r *Number) Max(now time.Time) float64 { var max float64 r.Mutex.RLock() defer r.Mutex.RUnlock() for timestamp, bucket := range r.Buckets { // TODO: configurable rolling window if timestamp >= now.Unix()-10 { if bucket.Value > max { max = bucket.Value } } } return max }
[ "func", "(", "r", "*", "Number", ")", "Max", "(", "now", "time", ".", "Time", ")", "float64", "{", "var", "max", "float64", "\n\n", "r", ".", "Mutex", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "Mutex", ".", "RUnlock", "(", ")", "\n\n", "...
// Max returns the maximum value seen in the last 10 seconds.
[ "Max", "returns", "the", "maximum", "value", "seen", "in", "the", "last", "10", "seconds", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling.go#L96-L112
train
afex/hystrix-go
hystrix/hystrix.go
Go
func Go(name string, run runFunc, fallback fallbackFunc) chan error { runC := func(ctx context.Context) error { return run() } var fallbackC fallbackFuncC if fallback != nil { fallbackC = func(ctx context.Context, err error) error { return fallback(err) } } return GoC(context.Background(), name, runC, fa...
go
func Go(name string, run runFunc, fallback fallbackFunc) chan error { runC := func(ctx context.Context) error { return run() } var fallbackC fallbackFuncC if fallback != nil { fallbackC = func(ctx context.Context, err error) error { return fallback(err) } } return GoC(context.Background(), name, runC, fa...
[ "func", "Go", "(", "name", "string", ",", "run", "runFunc", ",", "fallback", "fallbackFunc", ")", "chan", "error", "{", "runC", ":=", "func", "(", "ctx", "context", ".", "Context", ")", "error", "{", "return", "run", "(", ")", "\n", "}", "\n", "var",...
// Go runs your function while tracking the health of previous calls to it. // If your function begins slowing down or failing repeatedly, we will block // new calls to it for you to give the dependent service time to repair. // // Define a fallback function if you want to define some code to execute during outages.
[ "Go", "runs", "your", "function", "while", "tracking", "the", "health", "of", "previous", "calls", "to", "it", ".", "If", "your", "function", "begins", "slowing", "down", "or", "failing", "repeatedly", "we", "will", "block", "new", "calls", "to", "it", "fo...
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/hystrix.go#L55-L66
train
afex/hystrix-go
hystrix/hystrix.go
DoC
func DoC(ctx context.Context, name string, run runFuncC, fallback fallbackFuncC) error { done := make(chan struct{}, 1) r := func(ctx context.Context) error { err := run(ctx) if err != nil { return err } done <- struct{}{} return nil } f := func(ctx context.Context, e error) error { err := fallbac...
go
func DoC(ctx context.Context, name string, run runFuncC, fallback fallbackFuncC) error { done := make(chan struct{}, 1) r := func(ctx context.Context) error { err := run(ctx) if err != nil { return err } done <- struct{}{} return nil } f := func(ctx context.Context, e error) error { err := fallbac...
[ "func", "DoC", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "run", "runFuncC", ",", "fallback", "fallbackFuncC", ")", "error", "{", "done", ":=", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", "\n\n", "r", ":=", "func",...
// DoC runs your function in a synchronous manner, blocking until either your function succeeds // or an error is returned, including hystrix circuit errors
[ "DoC", "runs", "your", "function", "in", "a", "synchronous", "manner", "blocking", "until", "either", "your", "function", "succeeds", "or", "an", "error", "is", "returned", "including", "hystrix", "circuit", "errors" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/hystrix.go#L217-L253
train
afex/hystrix-go
hystrix/hystrix.go
errorWithFallback
func (c *command) errorWithFallback(ctx context.Context, err error) { eventType := "failure" if err == ErrCircuitOpen { eventType = "short-circuit" } else if err == ErrMaxConcurrency { eventType = "rejected" } else if err == ErrTimeout { eventType = "timeout" } else if err == context.Canceled { eventType =...
go
func (c *command) errorWithFallback(ctx context.Context, err error) { eventType := "failure" if err == ErrCircuitOpen { eventType = "short-circuit" } else if err == ErrMaxConcurrency { eventType = "rejected" } else if err == ErrTimeout { eventType = "timeout" } else if err == context.Canceled { eventType =...
[ "func", "(", "c", "*", "command", ")", "errorWithFallback", "(", "ctx", "context", ".", "Context", ",", "err", "error", ")", "{", "eventType", ":=", "\"", "\"", "\n", "if", "err", "==", "ErrCircuitOpen", "{", "eventType", "=", "\"", "\"", "\n", "}", ...
// errorWithFallback triggers the fallback while reporting the appropriate metric events.
[ "errorWithFallback", "triggers", "the", "fallback", "while", "reporting", "the", "appropriate", "metric", "events", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/hystrix.go#L263-L282
train
afex/hystrix-go
hystrix/settings.go
Configure
func Configure(cmds map[string]CommandConfig) { for k, v := range cmds { ConfigureCommand(k, v) } }
go
func Configure(cmds map[string]CommandConfig) { for k, v := range cmds { ConfigureCommand(k, v) } }
[ "func", "Configure", "(", "cmds", "map", "[", "string", "]", "CommandConfig", ")", "{", "for", "k", ",", "v", ":=", "range", "cmds", "{", "ConfigureCommand", "(", "k", ",", "v", ")", "\n", "}", "\n", "}" ]
// Configure applies settings for a set of circuits
[ "Configure", "applies", "settings", "for", "a", "set", "of", "circuits" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/settings.go#L51-L55
train
afex/hystrix-go
hystrix/settings.go
ConfigureCommand
func ConfigureCommand(name string, config CommandConfig) { settingsMutex.Lock() defer settingsMutex.Unlock() timeout := DefaultTimeout if config.Timeout != 0 { timeout = config.Timeout } max := DefaultMaxConcurrent if config.MaxConcurrentRequests != 0 { max = config.MaxConcurrentRequests } volume := Def...
go
func ConfigureCommand(name string, config CommandConfig) { settingsMutex.Lock() defer settingsMutex.Unlock() timeout := DefaultTimeout if config.Timeout != 0 { timeout = config.Timeout } max := DefaultMaxConcurrent if config.MaxConcurrentRequests != 0 { max = config.MaxConcurrentRequests } volume := Def...
[ "func", "ConfigureCommand", "(", "name", "string", ",", "config", "CommandConfig", ")", "{", "settingsMutex", ".", "Lock", "(", ")", "\n", "defer", "settingsMutex", ".", "Unlock", "(", ")", "\n\n", "timeout", ":=", "DefaultTimeout", "\n", "if", "config", "."...
// ConfigureCommand applies settings for a circuit
[ "ConfigureCommand", "applies", "settings", "for", "a", "circuit" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/settings.go#L58-L94
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
NumRequests
func (d *DefaultMetricCollector) NumRequests() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.numRequests }
go
func (d *DefaultMetricCollector) NumRequests() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.numRequests }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "NumRequests", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "num...
// NumRequests returns the rolling number of requests
[ "NumRequests", "returns", "the", "rolling", "number", "of", "requests" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L43-L47
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Errors
func (d *DefaultMetricCollector) Errors() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.errors }
go
func (d *DefaultMetricCollector) Errors() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.errors }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Errors", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "errors",...
// Errors returns the rolling number of errors
[ "Errors", "returns", "the", "rolling", "number", "of", "errors" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L50-L54
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Successes
func (d *DefaultMetricCollector) Successes() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.successes }
go
func (d *DefaultMetricCollector) Successes() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.successes }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Successes", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "succe...
// Successes returns the rolling number of successes
[ "Successes", "returns", "the", "rolling", "number", "of", "successes" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L57-L61
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Failures
func (d *DefaultMetricCollector) Failures() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.failures }
go
func (d *DefaultMetricCollector) Failures() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.failures }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Failures", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "failur...
// Failures returns the rolling number of failures
[ "Failures", "returns", "the", "rolling", "number", "of", "failures" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L64-L68
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Rejects
func (d *DefaultMetricCollector) Rejects() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.rejects }
go
func (d *DefaultMetricCollector) Rejects() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.rejects }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Rejects", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "rejects...
// Rejects returns the rolling number of rejects
[ "Rejects", "returns", "the", "rolling", "number", "of", "rejects" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L71-L75
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
ShortCircuits
func (d *DefaultMetricCollector) ShortCircuits() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.shortCircuits }
go
func (d *DefaultMetricCollector) ShortCircuits() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.shortCircuits }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "ShortCircuits", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "s...
// ShortCircuits returns the rolling number of short circuits
[ "ShortCircuits", "returns", "the", "rolling", "number", "of", "short", "circuits" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L78-L82
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Timeouts
func (d *DefaultMetricCollector) Timeouts() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.timeouts }
go
func (d *DefaultMetricCollector) Timeouts() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.timeouts }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Timeouts", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "timeou...
// Timeouts returns the rolling number of timeouts
[ "Timeouts", "returns", "the", "rolling", "number", "of", "timeouts" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L85-L89
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
FallbackSuccesses
func (d *DefaultMetricCollector) FallbackSuccesses() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.fallbackSuccesses }
go
func (d *DefaultMetricCollector) FallbackSuccesses() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.fallbackSuccesses }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "FallbackSuccesses", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", ...
// FallbackSuccesses returns the rolling number of fallback successes
[ "FallbackSuccesses", "returns", "the", "rolling", "number", "of", "fallback", "successes" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L92-L96
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
FallbackFailures
func (d *DefaultMetricCollector) FallbackFailures() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.fallbackFailures }
go
func (d *DefaultMetricCollector) FallbackFailures() *rolling.Number { d.mutex.RLock() defer d.mutex.RUnlock() return d.fallbackFailures }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "FallbackFailures", "(", ")", "*", "rolling", ".", "Number", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", ...
// FallbackFailures returns the rolling number of fallback failures
[ "FallbackFailures", "returns", "the", "rolling", "number", "of", "fallback", "failures" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L111-L115
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
TotalDuration
func (d *DefaultMetricCollector) TotalDuration() *rolling.Timing { d.mutex.RLock() defer d.mutex.RUnlock() return d.totalDuration }
go
func (d *DefaultMetricCollector) TotalDuration() *rolling.Timing { d.mutex.RLock() defer d.mutex.RUnlock() return d.totalDuration }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "TotalDuration", "(", ")", "*", "rolling", ".", "Timing", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "t...
// TotalDuration returns the rolling total duration
[ "TotalDuration", "returns", "the", "rolling", "total", "duration" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L118-L122
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
RunDuration
func (d *DefaultMetricCollector) RunDuration() *rolling.Timing { d.mutex.RLock() defer d.mutex.RUnlock() return d.runDuration }
go
func (d *DefaultMetricCollector) RunDuration() *rolling.Timing { d.mutex.RLock() defer d.mutex.RUnlock() return d.runDuration }
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "RunDuration", "(", ")", "*", "rolling", ".", "Timing", "{", "d", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "d", ".", "run...
// RunDuration returns the rolling run duration
[ "RunDuration", "returns", "the", "rolling", "run", "duration" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L125-L129
train
afex/hystrix-go
hystrix/metric_collector/default_metric_collector.go
Reset
func (d *DefaultMetricCollector) Reset() { d.mutex.Lock() defer d.mutex.Unlock() d.numRequests = rolling.NewNumber() d.errors = rolling.NewNumber() d.successes = rolling.NewNumber() d.rejects = rolling.NewNumber() d.shortCircuits = rolling.NewNumber() d.failures = rolling.NewNumber() d.timeouts = rolling.NewN...
go
func (d *DefaultMetricCollector) Reset() { d.mutex.Lock() defer d.mutex.Unlock() d.numRequests = rolling.NewNumber() d.errors = rolling.NewNumber() d.successes = rolling.NewNumber() d.rejects = rolling.NewNumber() d.shortCircuits = rolling.NewNumber() d.failures = rolling.NewNumber() d.timeouts = rolling.NewN...
[ "func", "(", "d", "*", "DefaultMetricCollector", ")", "Reset", "(", ")", "{", "d", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "d", ".", "numRequests", "=", "rolling", ".", "NewNumber", "(...
// Reset resets all metrics in this collector to 0.
[ "Reset", "resets", "all", "metrics", "in", "this", "collector", "to", "0", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/default_metric_collector.go#L152-L169
train
afex/hystrix-go
hystrix/rolling/rolling_timing.go
NewTiming
func NewTiming() *Timing { r := &Timing{ Buckets: make(map[int64]*timingBucket), Mutex: &sync.RWMutex{}, } return r }
go
func NewTiming() *Timing { r := &Timing{ Buckets: make(map[int64]*timingBucket), Mutex: &sync.RWMutex{}, } return r }
[ "func", "NewTiming", "(", ")", "*", "Timing", "{", "r", ":=", "&", "Timing", "{", "Buckets", ":", "make", "(", "map", "[", "int64", "]", "*", "timingBucket", ")", ",", "Mutex", ":", "&", "sync", ".", "RWMutex", "{", "}", ",", "}", "\n", "return",...
// NewTiming creates a RollingTiming struct.
[ "NewTiming", "creates", "a", "RollingTiming", "struct", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling_timing.go#L26-L32
train
afex/hystrix-go
hystrix/rolling/rolling_timing.go
SortedDurations
func (r *Timing) SortedDurations() []time.Duration { r.Mutex.RLock() t := r.LastCachedTime r.Mutex.RUnlock() if t+time.Duration(1*time.Second).Nanoseconds() > time.Now().UnixNano() { // don't recalculate if current cache is still fresh return r.CachedSortedDurations } var durations byDuration now := time.N...
go
func (r *Timing) SortedDurations() []time.Duration { r.Mutex.RLock() t := r.LastCachedTime r.Mutex.RUnlock() if t+time.Duration(1*time.Second).Nanoseconds() > time.Now().UnixNano() { // don't recalculate if current cache is still fresh return r.CachedSortedDurations } var durations byDuration now := time.N...
[ "func", "(", "r", "*", "Timing", ")", "SortedDurations", "(", ")", "[", "]", "time", ".", "Duration", "{", "r", ".", "Mutex", ".", "RLock", "(", ")", "\n", "t", ":=", "r", ".", "LastCachedTime", "\n", "r", ".", "Mutex", ".", "RUnlock", "(", ")", ...
// SortedDurations returns an array of time.Duration sorted from shortest // to longest that have occurred in the last 60 seconds.
[ "SortedDurations", "returns", "an", "array", "of", "time", ".", "Duration", "sorted", "from", "shortest", "to", "longest", "that", "have", "occurred", "in", "the", "last", "60", "seconds", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling_timing.go#L42-L73
train
afex/hystrix-go
hystrix/rolling/rolling_timing.go
Add
func (r *Timing) Add(duration time.Duration) { b := r.getCurrentBucket() r.Mutex.Lock() defer r.Mutex.Unlock() b.Durations = append(b.Durations, duration) r.removeOldBuckets() }
go
func (r *Timing) Add(duration time.Duration) { b := r.getCurrentBucket() r.Mutex.Lock() defer r.Mutex.Unlock() b.Durations = append(b.Durations, duration) r.removeOldBuckets() }
[ "func", "(", "r", "*", "Timing", ")", "Add", "(", "duration", "time", ".", "Duration", ")", "{", "b", ":=", "r", ".", "getCurrentBucket", "(", ")", "\n\n", "r", ".", "Mutex", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Mutex", ".", "Unlock",...
// Add appends the time.Duration given to the current time bucket.
[ "Add", "appends", "the", "time", ".", "Duration", "given", "to", "the", "current", "time", "bucket", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling_timing.go#L104-L112
train
afex/hystrix-go
hystrix/rolling/rolling_timing.go
Percentile
func (r *Timing) Percentile(p float64) uint32 { sortedDurations := r.SortedDurations() length := len(sortedDurations) if length <= 0 { return 0 } pos := r.ordinal(len(sortedDurations), p) - 1 return uint32(sortedDurations[pos].Nanoseconds() / 1000000) }
go
func (r *Timing) Percentile(p float64) uint32 { sortedDurations := r.SortedDurations() length := len(sortedDurations) if length <= 0 { return 0 } pos := r.ordinal(len(sortedDurations), p) - 1 return uint32(sortedDurations[pos].Nanoseconds() / 1000000) }
[ "func", "(", "r", "*", "Timing", ")", "Percentile", "(", "p", "float64", ")", "uint32", "{", "sortedDurations", ":=", "r", ".", "SortedDurations", "(", ")", "\n", "length", ":=", "len", "(", "sortedDurations", ")", "\n", "if", "length", "<=", "0", "{",...
// Percentile computes the percentile given with a linear interpolation.
[ "Percentile", "computes", "the", "percentile", "given", "with", "a", "linear", "interpolation", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling_timing.go#L115-L124
train
afex/hystrix-go
hystrix/rolling/rolling_timing.go
Mean
func (r *Timing) Mean() uint32 { sortedDurations := r.SortedDurations() var sum time.Duration for _, d := range sortedDurations { sum += d } length := int64(len(sortedDurations)) if length == 0 { return 0 } return uint32(sum.Nanoseconds()/length) / 1000000 }
go
func (r *Timing) Mean() uint32 { sortedDurations := r.SortedDurations() var sum time.Duration for _, d := range sortedDurations { sum += d } length := int64(len(sortedDurations)) if length == 0 { return 0 } return uint32(sum.Nanoseconds()/length) / 1000000 }
[ "func", "(", "r", "*", "Timing", ")", "Mean", "(", ")", "uint32", "{", "sortedDurations", ":=", "r", ".", "SortedDurations", "(", ")", "\n", "var", "sum", "time", ".", "Duration", "\n", "for", "_", ",", "d", ":=", "range", "sortedDurations", "{", "su...
// Mean computes the average timing in the last 60 seconds.
[ "Mean", "computes", "the", "average", "timing", "in", "the", "last", "60", "seconds", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/rolling/rolling_timing.go#L135-L148
train
afex/hystrix-go
hystrix/metrics.go
DefaultCollector
func (m *metricExchange) DefaultCollector() *metricCollector.DefaultMetricCollector { if len(m.metricCollectors) < 1 { panic("No Metric Collectors Registered.") } collection, ok := m.metricCollectors[0].(*metricCollector.DefaultMetricCollector) if !ok { panic("Default metric collector is not registered correctl...
go
func (m *metricExchange) DefaultCollector() *metricCollector.DefaultMetricCollector { if len(m.metricCollectors) < 1 { panic("No Metric Collectors Registered.") } collection, ok := m.metricCollectors[0].(*metricCollector.DefaultMetricCollector) if !ok { panic("Default metric collector is not registered correctl...
[ "func", "(", "m", "*", "metricExchange", ")", "DefaultCollector", "(", ")", "*", "metricCollector", ".", "DefaultMetricCollector", "{", "if", "len", "(", "m", ".", "metricCollectors", ")", "<", "1", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", ...
// The Default Collector function will panic if collectors are not setup to specification.
[ "The", "Default", "Collector", "function", "will", "panic", "if", "collectors", "are", "not", "setup", "to", "specification", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metrics.go#L41-L50
train
afex/hystrix-go
hystrix/eventstream.go
Start
func (sh *StreamHandler) Start() { sh.requests = make(map[*http.Request]chan []byte) sh.done = make(chan struct{}) go sh.loop() }
go
func (sh *StreamHandler) Start() { sh.requests = make(map[*http.Request]chan []byte) sh.done = make(chan struct{}) go sh.loop() }
[ "func", "(", "sh", "*", "StreamHandler", ")", "Start", "(", ")", "{", "sh", ".", "requests", "=", "make", "(", "map", "[", "*", "http", ".", "Request", "]", "chan", "[", "]", "byte", ")", "\n", "sh", ".", "done", "=", "make", "(", "chan", "stru...
// Start begins watching the in-memory circuit breakers for metrics
[ "Start", "begins", "watching", "the", "in", "-", "memory", "circuit", "breakers", "for", "metrics" ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/eventstream.go#L30-L34
train
afex/hystrix-go
hystrix/metric_collector/metric_collector.go
InitializeMetricCollectors
func (m *metricCollectorRegistry) InitializeMetricCollectors(name string) []MetricCollector { m.lock.RLock() defer m.lock.RUnlock() metrics := make([]MetricCollector, len(m.registry)) for i, metricCollectorInitializer := range m.registry { metrics[i] = metricCollectorInitializer(name) } return metrics }
go
func (m *metricCollectorRegistry) InitializeMetricCollectors(name string) []MetricCollector { m.lock.RLock() defer m.lock.RUnlock() metrics := make([]MetricCollector, len(m.registry)) for i, metricCollectorInitializer := range m.registry { metrics[i] = metricCollectorInitializer(name) } return metrics }
[ "func", "(", "m", "*", "metricCollectorRegistry", ")", "InitializeMetricCollectors", "(", "name", "string", ")", "[", "]", "MetricCollector", "{", "m", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "lock", ".", "RUnlock", "(", ")", "\n\n"...
// InitializeMetricCollectors runs the registried MetricCollector Initializers to create an array of MetricCollectors.
[ "InitializeMetricCollectors", "runs", "the", "registried", "MetricCollector", "Initializers", "to", "create", "an", "array", "of", "MetricCollectors", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/metric_collector.go#L23-L32
train
afex/hystrix-go
hystrix/metric_collector/metric_collector.go
Register
func (m *metricCollectorRegistry) Register(initMetricCollector func(string) MetricCollector) { m.lock.Lock() defer m.lock.Unlock() m.registry = append(m.registry, initMetricCollector) }
go
func (m *metricCollectorRegistry) Register(initMetricCollector func(string) MetricCollector) { m.lock.Lock() defer m.lock.Unlock() m.registry = append(m.registry, initMetricCollector) }
[ "func", "(", "m", "*", "metricCollectorRegistry", ")", "Register", "(", "initMetricCollector", "func", "(", "string", ")", "MetricCollector", ")", "{", "m", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "lock", ".", "Unlock", "(", ")", "...
// Register places a MetricCollector Initializer in the registry maintained by this metricCollectorRegistry.
[ "Register", "places", "a", "MetricCollector", "Initializer", "in", "the", "registry", "maintained", "by", "this", "metricCollectorRegistry", "." ]
fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a
https://github.com/afex/hystrix-go/blob/fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a/hystrix/metric_collector/metric_collector.go#L35-L40
train
kardianos/service
version.go
versionAtMost
func versionAtMost(version, max []int) (bool, error) { if comp, err := versionCompare(version, max); err != nil { return false, err } else if comp == 1 { return false, nil } return true, nil }
go
func versionAtMost(version, max []int) (bool, error) { if comp, err := versionCompare(version, max); err != nil { return false, err } else if comp == 1 { return false, nil } return true, nil }
[ "func", "versionAtMost", "(", "version", ",", "max", "[", "]", "int", ")", "(", "bool", ",", "error", ")", "{", "if", "comp", ",", "err", ":=", "versionCompare", "(", "version", ",", "max", ")", ";", "err", "!=", "nil", "{", "return", "false", ",",...
// versionAtMost will return true if the provided version is less than or equal to max
[ "versionAtMost", "will", "return", "true", "if", "the", "provided", "version", "is", "less", "than", "or", "equal", "to", "max" ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L10-L17
train
kardianos/service
version.go
versionCompare
func versionCompare(v1, v2 []int) (int, error) { if len(v1) != len(v2) { return 0, errors.New("version length mismatch") } for idx, v2S := range v2 { v1S := v1[idx] if v1S > v2S { return 1, nil } if v1S < v2S { return -1, nil } } return 0, nil }
go
func versionCompare(v1, v2 []int) (int, error) { if len(v1) != len(v2) { return 0, errors.New("version length mismatch") } for idx, v2S := range v2 { v1S := v1[idx] if v1S > v2S { return 1, nil } if v1S < v2S { return -1, nil } } return 0, nil }
[ "func", "versionCompare", "(", "v1", ",", "v2", "[", "]", "int", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "...
// versionCompare take to versions split into integer arrays and attempts to compare them // An error will be returned if there is an array length mismatch. // Return values are as follows // -1 - v1 is less than v2 // 0 - v1 is equal to v2 // 1 - v1 is greater than v2
[ "versionCompare", "take", "to", "versions", "split", "into", "integer", "arrays", "and", "attempts", "to", "compare", "them", "An", "error", "will", "be", "returned", "if", "there", "is", "an", "array", "length", "mismatch", ".", "Return", "values", "are", "...
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L25-L41
train
kardianos/service
version.go
parseVersion
func parseVersion(v string) []int { version := make([]int, 3) for idx, vStr := range strings.Split(v, ".") { vS, err := strconv.Atoi(vStr) if err != nil { return nil } version[idx] = vS } return version }
go
func parseVersion(v string) []int { version := make([]int, 3) for idx, vStr := range strings.Split(v, ".") { vS, err := strconv.Atoi(vStr) if err != nil { return nil } version[idx] = vS } return version }
[ "func", "parseVersion", "(", "v", "string", ")", "[", "]", "int", "{", "version", ":=", "make", "(", "[", "]", "int", ",", "3", ")", "\n\n", "for", "idx", ",", "vStr", ":=", "range", "strings", ".", "Split", "(", "v", ",", "\"", "\"", ")", "{",...
// parseVersion will parse any integer type version seperated by periods. // This does not fully support semver style versions.
[ "parseVersion", "will", "parse", "any", "integer", "type", "version", "seperated", "by", "periods", ".", "This", "does", "not", "fully", "support", "semver", "style", "versions", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/version.go#L45-L57
train
kardianos/service
service.go
New
func New(i Interface, c *Config) (Service, error) { if len(c.Name) == 0 { return nil, ErrNameFieldRequired } if system == nil { return nil, ErrNoServiceSystemDetected } return system.New(i, c) }
go
func New(i Interface, c *Config) (Service, error) { if len(c.Name) == 0 { return nil, ErrNameFieldRequired } if system == nil { return nil, ErrNoServiceSystemDetected } return system.New(i, c) }
[ "func", "New", "(", "i", "Interface", ",", "c", "*", "Config", ")", "(", "Service", ",", "error", ")", "{", "if", "len", "(", "c", ".", "Name", ")", "==", "0", "{", "return", "nil", ",", "ErrNameFieldRequired", "\n", "}", "\n", "if", "system", "=...
// New creates a new service based on a service interface and configuration.
[ "New", "creates", "a", "new", "service", "based", "on", "a", "service", "interface", "and", "configuration", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L160-L168
train
kardianos/service
service.go
bool
func (kv KeyValue) bool(name string, defaultValue bool) bool { if v, found := kv[name]; found { if castValue, is := v.(bool); is { return castValue } } return defaultValue }
go
func (kv KeyValue) bool(name string, defaultValue bool) bool { if v, found := kv[name]; found { if castValue, is := v.(bool); is { return castValue } } return defaultValue }
[ "func", "(", "kv", "KeyValue", ")", "bool", "(", "name", "string", ",", "defaultValue", "bool", ")", "bool", "{", "if", "v", ",", "found", ":=", "kv", "[", "name", "]", ";", "found", "{", "if", "castValue", ",", "is", ":=", "v", ".", "(", "bool",...
// bool returns the value of the given name, assuming the value is a boolean. // If the value isn't found or is not of the type, the defaultValue is returned.
[ "bool", "returns", "the", "value", "of", "the", "given", "name", "assuming", "the", "value", "is", "a", "boolean", ".", "If", "the", "value", "isn", "t", "found", "or", "is", "not", "of", "the", "type", "the", "defaultValue", "is", "returned", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L176-L183
train
kardianos/service
service.go
Control
func Control(s Service, action string) error { var err error switch action { case ControlAction[0]: err = s.Start() case ControlAction[1]: err = s.Stop() case ControlAction[2]: err = s.Restart() case ControlAction[3]: err = s.Install() case ControlAction[4]: err = s.Uninstall() default: err = fmt.Er...
go
func Control(s Service, action string) error { var err error switch action { case ControlAction[0]: err = s.Start() case ControlAction[1]: err = s.Stop() case ControlAction[2]: err = s.Restart() case ControlAction[3]: err = s.Install() case ControlAction[4]: err = s.Uninstall() default: err = fmt.Er...
[ "func", "Control", "(", "s", "Service", ",", "action", "string", ")", "error", "{", "var", "err", "error", "\n", "switch", "action", "{", "case", "ControlAction", "[", "0", "]", ":", "err", "=", "s", ".", "Start", "(", ")", "\n", "case", "ControlActi...
// Control issues control functions to the service from a given action string.
[ "Control", "issues", "control", "functions", "to", "the", "service", "from", "a", "given", "action", "string", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service.go#L368-L388
train
kardianos/service
service_windows.go
Errorf
func (l WindowsLogger) Errorf(format string, a ...interface{}) error { return l.send(l.ev.Error(3, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Errorf(format string, a ...interface{}) error { return l.send(l.ev.Error(3, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Errorf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "3", ",", "fmt", ".", "Sprintf", "(", "forma...
// Errorf logs an error message.
[ "Errorf", "logs", "an", "error", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L87-L89
train
kardianos/service
service_windows.go
Warningf
func (l WindowsLogger) Warningf(format string, a ...interface{}) error { return l.send(l.ev.Warning(2, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Warningf(format string, a ...interface{}) error { return l.send(l.ev.Warning(2, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Warningf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "2", ",", "fmt", ".", "Sprintf", "(", "f...
// Warningf logs an warning message.
[ "Warningf", "logs", "an", "warning", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L92-L94
train
kardianos/service
service_windows.go
Infof
func (l WindowsLogger) Infof(format string, a ...interface{}) error { return l.send(l.ev.Info(1, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) Infof(format string, a ...interface{}) error { return l.send(l.ev.Info(1, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "Infof", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "1", ",", "fmt", ".", "Sprintf", "(", "format"...
// Infof logs an info message.
[ "Infof", "logs", "an", "info", "message", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L97-L99
train
kardianos/service
service_windows.go
NError
func (l WindowsLogger) NError(eventID uint32, v ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NError(eventID uint32, v ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NError", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "eventID", ",", "fmt", ".", "Sprint", "(", ...
// NError logs an error message and an event ID.
[ "NError", "logs", "an", "error", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L102-L104
train
kardianos/service
service_windows.go
NWarning
func (l WindowsLogger) NWarning(eventID uint32, v ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NWarning(eventID uint32, v ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NWarning", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "eventID", ",", "fmt", ".", "Sprint", "("...
// NWarning logs an warning message and an event ID.
[ "NWarning", "logs", "an", "warning", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L107-L109
train
kardianos/service
service_windows.go
NInfo
func (l WindowsLogger) NInfo(eventID uint32, v ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprint(v...))) }
go
func (l WindowsLogger) NInfo(eventID uint32, v ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprint(v...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NInfo", "(", "eventID", "uint32", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "eventID", ",", "fmt", ".", "Sprint", "(", "v...
// NInfo logs an info message and an event ID.
[ "NInfo", "logs", "an", "info", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L112-L114
train
kardianos/service
service_windows.go
NErrorf
func (l WindowsLogger) NErrorf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NErrorf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Error(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NErrorf", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Error", "(", "eventID", ",", "fm...
// NErrorf logs an error message and an event ID.
[ "NErrorf", "logs", "an", "error", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L117-L119
train
kardianos/service
service_windows.go
NWarningf
func (l WindowsLogger) NWarningf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NWarningf(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Warning(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NWarningf", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Warning", "(", "eventID", ",", ...
// NWarningf logs an warning message and an event ID.
[ "NWarningf", "logs", "an", "warning", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L122-L124
train
kardianos/service
service_windows.go
NInfof
func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprintf(format, a...))) }
go
func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) error { return l.send(l.ev.Info(eventID, fmt.Sprintf(format, a...))) }
[ "func", "(", "l", "WindowsLogger", ")", "NInfof", "(", "eventID", "uint32", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "send", "(", "l", ".", "ev", ".", "Info", "(", "eventID", ",", "fmt"...
// NInfof logs an info message and an event ID.
[ "NInfof", "logs", "an", "info", "message", "and", "an", "event", "ID", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L127-L129
train
kardianos/service
service_windows.go
getStopTimeout
func getStopTimeout() time.Duration { // For default and paths see https://support.microsoft.com/en-us/kb/146092 defaultTimeout := time.Millisecond * 20000 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control`, registry.READ) if err != nil { return defaultTimeout } sv, _, err :...
go
func getStopTimeout() time.Duration { // For default and paths see https://support.microsoft.com/en-us/kb/146092 defaultTimeout := time.Millisecond * 20000 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control`, registry.READ) if err != nil { return defaultTimeout } sv, _, err :...
[ "func", "getStopTimeout", "(", ")", "time", ".", "Duration", "{", "// For default and paths see https://support.microsoft.com/en-us/kb/146092", "defaultTimeout", ":=", "time", ".", "Millisecond", "*", "20000", "\n", "key", ",", "err", ":=", "registry", ".", "OpenKey", ...
// getStopTimeout fetches the time before windows will kill the service.
[ "getStopTimeout", "fetches", "the", "time", "before", "windows", "will", "kill", "the", "service", "." ]
0e5bec1b9eec14f9070a6f49ad7e0242f1545d66
https://github.com/kardianos/service/blob/0e5bec1b9eec14f9070a6f49ad7e0242f1545d66/service_windows.go#L406-L422
train
jroimartin/gocui
edit.go
simpleEditor
func simpleEditor(v *View, key Key, ch rune, mod Modifier) { switch { case ch != 0 && mod == 0: v.EditWrite(ch) case key == KeySpace: v.EditWrite(' ') case key == KeyBackspace || key == KeyBackspace2: v.EditDelete(true) case key == KeyDelete: v.EditDelete(false) case key == KeyInsert: v.Overwrite = !v.O...
go
func simpleEditor(v *View, key Key, ch rune, mod Modifier) { switch { case ch != 0 && mod == 0: v.EditWrite(ch) case key == KeySpace: v.EditWrite(' ') case key == KeyBackspace || key == KeyBackspace2: v.EditDelete(true) case key == KeyDelete: v.EditDelete(false) case key == KeyInsert: v.Overwrite = !v.O...
[ "func", "simpleEditor", "(", "v", "*", "View", ",", "key", "Key", ",", "ch", "rune", ",", "mod", "Modifier", ")", "{", "switch", "{", "case", "ch", "!=", "0", "&&", "mod", "==", "0", ":", "v", ".", "EditWrite", "(", "ch", ")", "\n", "case", "ke...
// simpleEditor is used as the default gocui editor.
[ "simpleEditor", "is", "used", "as", "the", "default", "gocui", "editor", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L30-L53
train
jroimartin/gocui
edit.go
EditWrite
func (v *View) EditWrite(ch rune) { v.writeRune(v.cx, v.cy, ch) v.MoveCursor(1, 0, true) }
go
func (v *View) EditWrite(ch rune) { v.writeRune(v.cx, v.cy, ch) v.MoveCursor(1, 0, true) }
[ "func", "(", "v", "*", "View", ")", "EditWrite", "(", "ch", "rune", ")", "{", "v", ".", "writeRune", "(", "v", ".", "cx", ",", "v", ".", "cy", ",", "ch", ")", "\n", "v", ".", "MoveCursor", "(", "1", ",", "0", ",", "true", ")", "\n", "}" ]
// EditWrite writes a rune at the cursor position.
[ "EditWrite", "writes", "a", "rune", "at", "the", "cursor", "position", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L56-L59
train
jroimartin/gocui
edit.go
EditDelete
func (v *View) EditDelete(back bool) { x, y := v.ox+v.cx, v.oy+v.cy if y < 0 { return } else if y >= len(v.viewLines) { v.MoveCursor(-1, 0, true) return } maxX, _ := v.Size() if back { if x == 0 { // start of the line if y < 1 { return } var maxPrevWidth int if v.Wrap { maxPrevWidth ...
go
func (v *View) EditDelete(back bool) { x, y := v.ox+v.cx, v.oy+v.cy if y < 0 { return } else if y >= len(v.viewLines) { v.MoveCursor(-1, 0, true) return } maxX, _ := v.Size() if back { if x == 0 { // start of the line if y < 1 { return } var maxPrevWidth int if v.Wrap { maxPrevWidth ...
[ "func", "(", "v", "*", "View", ")", "EditDelete", "(", "back", "bool", ")", "{", "x", ",", "y", ":=", "v", ".", "ox", "+", "v", ".", "cx", ",", "v", ".", "oy", "+", "v", ".", "cy", "\n", "if", "y", "<", "0", "{", "return", "\n", "}", "e...
// EditDelete deletes a rune at the cursor position. back determines the // direction.
[ "EditDelete", "deletes", "a", "rune", "at", "the", "cursor", "position", ".", "back", "determines", "the", "direction", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L63-L106
train
jroimartin/gocui
edit.go
EditNewLine
func (v *View) EditNewLine() { v.breakLine(v.cx, v.cy) v.ox = 0 v.cx = 0 v.MoveCursor(0, 1, true) }
go
func (v *View) EditNewLine() { v.breakLine(v.cx, v.cy) v.ox = 0 v.cx = 0 v.MoveCursor(0, 1, true) }
[ "func", "(", "v", "*", "View", ")", "EditNewLine", "(", ")", "{", "v", ".", "breakLine", "(", "v", ".", "cx", ",", "v", ".", "cy", ")", "\n", "v", ".", "ox", "=", "0", "\n", "v", ".", "cx", "=", "0", "\n", "v", ".", "MoveCursor", "(", "0"...
// EditNewLine inserts a new line under the cursor.
[ "EditNewLine", "inserts", "a", "new", "line", "under", "the", "cursor", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L109-L114
train
jroimartin/gocui
edit.go
mergeLines
func (v *View) mergeLines(y int) error { v.tainted = true _, y, err := v.realPosition(0, y) if err != nil { return err } if y < 0 || y >= len(v.lines) { return errors.New("invalid point") } if y < len(v.lines)-1 { // otherwise we don't need to merge anything v.lines[y] = append(v.lines[y], v.lines[y+1]....
go
func (v *View) mergeLines(y int) error { v.tainted = true _, y, err := v.realPosition(0, y) if err != nil { return err } if y < 0 || y >= len(v.lines) { return errors.New("invalid point") } if y < len(v.lines)-1 { // otherwise we don't need to merge anything v.lines[y] = append(v.lines[y], v.lines[y+1]....
[ "func", "(", "v", "*", "View", ")", "mergeLines", "(", "y", "int", ")", "error", "{", "v", ".", "tainted", "=", "true", "\n\n", "_", ",", "y", ",", "err", ":=", "v", ".", "realPosition", "(", "0", ",", "y", ")", "\n", "if", "err", "!=", "nil"...
// mergeLines merges the lines "y" and "y+1" if possible.
[ "mergeLines", "merges", "the", "lines", "y", "and", "y", "+", "1", "if", "possible", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/edit.go#L294-L311
train
jroimartin/gocui
keybinding.go
newKeybinding
func newKeybinding(viewname string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { kb = &keybinding{ viewName: viewname, key: key, ch: ch, mod: mod, handler: handler, } return kb }
go
func newKeybinding(viewname string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { kb = &keybinding{ viewName: viewname, key: key, ch: ch, mod: mod, handler: handler, } return kb }
[ "func", "newKeybinding", "(", "viewname", "string", ",", "key", "Key", ",", "ch", "rune", ",", "mod", "Modifier", ",", "handler", "func", "(", "*", "Gui", ",", "*", "View", ")", "error", ")", "(", "kb", "*", "keybinding", ")", "{", "kb", "=", "&", ...
// newKeybinding returns a new Keybinding object.
[ "newKeybinding", "returns", "a", "new", "Keybinding", "object", "." ]
c055c87ae801372cd74a0839b972db4f7697ae5f
https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L19-L28
train