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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
nats-io/go-nats | nats.go | processExpectedInfo | func (nc *Conn) processExpectedInfo() error {
c := &control{}
// Read the protocol
err := nc.readOp(c)
if err != nil {
return err
}
// The nats protocol should send INFO first always.
if c.op != _INFO_OP_ {
return ErrNoInfoReceived
}
// Parse the protocol
if err := nc.processInfo(c.args); err != nil {... | go | func (nc *Conn) processExpectedInfo() error {
c := &control{}
// Read the protocol
err := nc.readOp(c)
if err != nil {
return err
}
// The nats protocol should send INFO first always.
if c.op != _INFO_OP_ {
return ErrNoInfoReceived
}
// Parse the protocol
if err := nc.processInfo(c.args); err != nil {... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processExpectedInfo",
"(",
")",
"error",
"{",
"c",
":=",
"&",
"control",
"{",
"}",
"\n\n",
"// Read the protocol",
"err",
":=",
"nc",
".",
"readOp",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // processExpectedInfo will look for the expected first INFO message
// sent when a connection is established. The lock should be held entering. | [
"processExpectedInfo",
"will",
"look",
"for",
"the",
"expected",
"first",
"INFO",
"message",
"sent",
"when",
"a",
"connection",
"is",
"established",
".",
"The",
"lock",
"should",
"be",
"held",
"entering",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1464-L1489 | train |
nats-io/go-nats | nats.go | sendProto | func (nc *Conn) sendProto(proto string) {
nc.mu.Lock()
nc.bw.WriteString(proto)
nc.kickFlusher()
nc.mu.Unlock()
} | go | func (nc *Conn) sendProto(proto string) {
nc.mu.Lock()
nc.bw.WriteString(proto)
nc.kickFlusher()
nc.mu.Unlock()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"sendProto",
"(",
"proto",
"string",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"nc",
".",
"bw",
".",
"WriteString",
"(",
"proto",
")",
"\n",
"nc",
".",
"kickFlusher",
"(",
")",
"\n",
"nc",
".",... | // Sends a protocol control message by queuing into the bufio writer
// and kicking the flush Go routine. These writes are protected. | [
"Sends",
"a",
"protocol",
"control",
"message",
"by",
"queuing",
"into",
"the",
"bufio",
"writer",
"and",
"kicking",
"the",
"flush",
"Go",
"routine",
".",
"These",
"writes",
"are",
"protected",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1493-L1498 | train |
nats-io/go-nats | nats.go | normalizeErr | func normalizeErr(line string) string {
s := strings.TrimSpace(strings.TrimPrefix(line, _ERR_OP_))
s = strings.TrimLeft(strings.TrimRight(s, "'"), "'")
return s
} | go | func normalizeErr(line string) string {
s := strings.TrimSpace(strings.TrimPrefix(line, _ERR_OP_))
s = strings.TrimLeft(strings.TrimRight(s, "'"), "'")
return s
} | [
"func",
"normalizeErr",
"(",
"line",
"string",
")",
"string",
"{",
"s",
":=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"TrimPrefix",
"(",
"line",
",",
"_ERR_OP_",
")",
")",
"\n",
"s",
"=",
"strings",
".",
"TrimLeft",
"(",
"strings",
".",
"Trim... | // normalizeErr removes the prefix -ERR, trim spaces and remove the quotes. | [
"normalizeErr",
"removes",
"the",
"prefix",
"-",
"ERR",
"trim",
"spaces",
"and",
"remove",
"the",
"quotes",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1572-L1576 | train |
nats-io/go-nats | nats.go | readProto | func (nc *Conn) readProto() (string, error) {
var (
_buf = [10]byte{}
buf = _buf[:0]
b = [1]byte{}
protoEnd = byte('\n')
)
for {
if _, err := nc.conn.Read(b[:1]); err != nil {
// Do not report EOF error
if err == io.EOF {
return string(buf), nil
}
return "", err
}
buf = ... | go | func (nc *Conn) readProto() (string, error) {
var (
_buf = [10]byte{}
buf = _buf[:0]
b = [1]byte{}
protoEnd = byte('\n')
)
for {
if _, err := nc.conn.Read(b[:1]); err != nil {
// Do not report EOF error
if err == io.EOF {
return string(buf), nil
}
return "", err
}
buf = ... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"readProto",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"(",
"_buf",
"=",
"[",
"10",
"]",
"byte",
"{",
"}",
"\n",
"buf",
"=",
"_buf",
"[",
":",
"0",
"]",
"\n",
"b",
"=",
"[",
"1",
"]",
"by... | // reads a protocol one byte at a time. | [
"reads",
"a",
"protocol",
"one",
"byte",
"at",
"a",
"time",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1650-L1670 | train |
nats-io/go-nats | nats.go | readOp | func (nc *Conn) readOp(c *control) error {
br := bufio.NewReaderSize(nc.conn, defaultBufSize)
line, err := br.ReadString('\n')
if err != nil {
return err
}
parseControl(line, c)
return nil
} | go | func (nc *Conn) readOp(c *control) error {
br := bufio.NewReaderSize(nc.conn, defaultBufSize)
line, err := br.ReadString('\n')
if err != nil {
return err
}
parseControl(line, c)
return nil
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"readOp",
"(",
"c",
"*",
"control",
")",
"error",
"{",
"br",
":=",
"bufio",
".",
"NewReaderSize",
"(",
"nc",
".",
"conn",
",",
"defaultBufSize",
")",
"\n",
"line",
",",
"err",
":=",
"br",
".",
"ReadString",
"(",... | // Read a control line and process the intended op. | [
"Read",
"a",
"control",
"line",
"and",
"process",
"the",
"intended",
"op",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1678-L1686 | train |
nats-io/go-nats | nats.go | parseControl | func parseControl(line string, c *control) {
toks := strings.SplitN(line, _SPC_, 2)
if len(toks) == 1 {
c.op = strings.TrimSpace(toks[0])
c.args = _EMPTY_
} else if len(toks) == 2 {
c.op, c.args = strings.TrimSpace(toks[0]), strings.TrimSpace(toks[1])
} else {
c.op = _EMPTY_
}
} | go | func parseControl(line string, c *control) {
toks := strings.SplitN(line, _SPC_, 2)
if len(toks) == 1 {
c.op = strings.TrimSpace(toks[0])
c.args = _EMPTY_
} else if len(toks) == 2 {
c.op, c.args = strings.TrimSpace(toks[0]), strings.TrimSpace(toks[1])
} else {
c.op = _EMPTY_
}
} | [
"func",
"parseControl",
"(",
"line",
"string",
",",
"c",
"*",
"control",
")",
"{",
"toks",
":=",
"strings",
".",
"SplitN",
"(",
"line",
",",
"_SPC_",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"toks",
")",
"==",
"1",
"{",
"c",
".",
"op",
"=",
"stri... | // Parse a control line from the server. | [
"Parse",
"a",
"control",
"line",
"from",
"the",
"server",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1689-L1699 | train |
nats-io/go-nats | nats.go | flushReconnectPendingItems | func (nc *Conn) flushReconnectPendingItems() {
if nc.pending == nil {
return
}
if nc.pending.Len() > 0 {
nc.bw.Write(nc.pending.Bytes())
}
} | go | func (nc *Conn) flushReconnectPendingItems() {
if nc.pending == nil {
return
}
if nc.pending.Len() > 0 {
nc.bw.Write(nc.pending.Bytes())
}
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"flushReconnectPendingItems",
"(",
")",
"{",
"if",
"nc",
".",
"pending",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"nc",
".",
"pending",
".",
"Len",
"(",
")",
">",
"0",
"{",
"nc",
".",
"bw",
".",
"W... | // flushReconnectPending will push the pending items that were
// gathered while we were in a RECONNECTING state to the socket. | [
"flushReconnectPending",
"will",
"push",
"the",
"pending",
"items",
"that",
"were",
"gathered",
"while",
"we",
"were",
"in",
"a",
"RECONNECTING",
"state",
"to",
"the",
"socket",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1703-L1710 | train |
nats-io/go-nats | nats.go | doReconnect | func (nc *Conn) doReconnect() {
// We want to make sure we have the other watchers shutdown properly
// here before we proceed past this point.
nc.waitForExits()
// FIXME(dlc) - We have an issue here if we have
// outstanding flush points (pongs) and they were not
// sent out, but are still in the pipe.
// Hol... | go | func (nc *Conn) doReconnect() {
// We want to make sure we have the other watchers shutdown properly
// here before we proceed past this point.
nc.waitForExits()
// FIXME(dlc) - We have an issue here if we have
// outstanding flush points (pongs) and they were not
// sent out, but are still in the pipe.
// Hol... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"doReconnect",
"(",
")",
"{",
"// We want to make sure we have the other watchers shutdown properly",
"// here before we proceed past this point.",
"nc",
".",
"waitForExits",
"(",
")",
"\n\n",
"// FIXME(dlc) - We have an issue here if we have"... | // Try to reconnect using the option parameters.
// This function assumes we are allowed to reconnect. | [
"Try",
"to",
"reconnect",
"using",
"the",
"option",
"parameters",
".",
"This",
"function",
"assumes",
"we",
"are",
"allowed",
"to",
"reconnect",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1722-L1863 | train |
nats-io/go-nats | nats.go | processOpErr | func (nc *Conn) processOpErr(err error) {
nc.mu.Lock()
if nc.isConnecting() || nc.isClosed() || nc.isReconnecting() {
nc.mu.Unlock()
return
}
if nc.Opts.AllowReconnect && nc.status == CONNECTED {
// Set our new status
nc.status = RECONNECTING
// Stop ping timer if set
nc.stopPingTimer()
if nc.conn !=... | go | func (nc *Conn) processOpErr(err error) {
nc.mu.Lock()
if nc.isConnecting() || nc.isClosed() || nc.isReconnecting() {
nc.mu.Unlock()
return
}
if nc.Opts.AllowReconnect && nc.status == CONNECTED {
// Set our new status
nc.status = RECONNECTING
// Stop ping timer if set
nc.stopPingTimer()
if nc.conn !=... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processOpErr",
"(",
"err",
"error",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"nc",
".",
"isConnecting",
"(",
")",
"||",
"nc",
".",
"isClosed",
"(",
")",
"||",
"nc",
".",
"isReconnecting",... | // processOpErr handles errors from reading or parsing the protocol.
// The lock should not be held entering this function. | [
"processOpErr",
"handles",
"errors",
"from",
"reading",
"or",
"parsing",
"the",
"protocol",
".",
"The",
"lock",
"should",
"not",
"be",
"held",
"entering",
"this",
"function",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1867-L1898 | train |
nats-io/go-nats | nats.go | asyncCBDispatcher | func (ac *asyncCallbacksHandler) asyncCBDispatcher() {
for {
ac.mu.Lock()
// Protect for spurious wakeups. We should get out of the
// wait only if there is an element to pop from the list.
for ac.head == nil {
ac.cond.Wait()
}
cur := ac.head
ac.head = cur.next
if cur == ac.tail {
ac.tail = nil
... | go | func (ac *asyncCallbacksHandler) asyncCBDispatcher() {
for {
ac.mu.Lock()
// Protect for spurious wakeups. We should get out of the
// wait only if there is an element to pop from the list.
for ac.head == nil {
ac.cond.Wait()
}
cur := ac.head
ac.head = cur.next
if cur == ac.tail {
ac.tail = nil
... | [
"func",
"(",
"ac",
"*",
"asyncCallbacksHandler",
")",
"asyncCBDispatcher",
"(",
")",
"{",
"for",
"{",
"ac",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"// Protect for spurious wakeups. We should get out of the",
"// wait only if there is an element to pop from the list.",
"f... | // dispatch is responsible for calling any async callbacks | [
"dispatch",
"is",
"responsible",
"for",
"calling",
"any",
"async",
"callbacks"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1901-L1924 | train |
nats-io/go-nats | nats.go | pushOrClose | func (ac *asyncCallbacksHandler) pushOrClose(f func(), close bool) {
ac.mu.Lock()
defer ac.mu.Unlock()
// Make sure that library is not calling push with nil function,
// since this is used to notify the dispatcher that it should stop.
if !close && f == nil {
panic("pushing a nil callback")
}
cb := &asyncCB{f:... | go | func (ac *asyncCallbacksHandler) pushOrClose(f func(), close bool) {
ac.mu.Lock()
defer ac.mu.Unlock()
// Make sure that library is not calling push with nil function,
// since this is used to notify the dispatcher that it should stop.
if !close && f == nil {
panic("pushing a nil callback")
}
cb := &asyncCB{f:... | [
"func",
"(",
"ac",
"*",
"asyncCallbacksHandler",
")",
"pushOrClose",
"(",
"f",
"func",
"(",
")",
",",
"close",
"bool",
")",
"{",
"ac",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ac",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"// Make sure th... | // Add the given function to the tail of the list and
// signals the dispatcher. | [
"Add",
"the",
"given",
"function",
"to",
"the",
"tail",
"of",
"the",
"list",
"and",
"signals",
"the",
"dispatcher",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L1939-L1959 | train |
nats-io/go-nats | nats.go | waitForMsgs | func (nc *Conn) waitForMsgs(s *Subscription) {
var closed bool
var delivered, max uint64
// Used to account for adjustments to sub.pBytes when we wrap back around.
msgLen := -1
for {
s.mu.Lock()
// Do accounting for last msg delivered here so we only lock once
// and drain state trips after callback has re... | go | func (nc *Conn) waitForMsgs(s *Subscription) {
var closed bool
var delivered, max uint64
// Used to account for adjustments to sub.pBytes when we wrap back around.
msgLen := -1
for {
s.mu.Lock()
// Do accounting for last msg delivered here so we only lock once
// and drain state trips after callback has re... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"waitForMsgs",
"(",
"s",
"*",
"Subscription",
")",
"{",
"var",
"closed",
"bool",
"\n",
"var",
"delivered",
",",
"max",
"uint64",
"\n\n",
"// Used to account for adjustments to sub.pBytes when we wrap back around.",
"msgLen",
":="... | // waitForMsgs waits on the conditional shared with readLoop and processMsg.
// It is used to deliver messages to asynchronous subscribers. | [
"waitForMsgs",
"waits",
"on",
"the",
"conditional",
"shared",
"with",
"readLoop",
"and",
"processMsg",
".",
"It",
"is",
"used",
"to",
"deliver",
"messages",
"to",
"asynchronous",
"subscribers",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2010-L2084 | train |
nats-io/go-nats | nats.go | processPermissionsViolation | func (nc *Conn) processPermissionsViolation(err string) {
nc.mu.Lock()
// create error here so we can pass it as a closure to the async cb dispatcher.
e := errors.New("nats: " + err)
nc.err = e
if nc.Opts.AsyncErrorCB != nil {
nc.ach.push(func() { nc.Opts.AsyncErrorCB(nc, nil, e) })
}
nc.mu.Unlock()
} | go | func (nc *Conn) processPermissionsViolation(err string) {
nc.mu.Lock()
// create error here so we can pass it as a closure to the async cb dispatcher.
e := errors.New("nats: " + err)
nc.err = e
if nc.Opts.AsyncErrorCB != nil {
nc.ach.push(func() { nc.Opts.AsyncErrorCB(nc, nil, e) })
}
nc.mu.Unlock()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processPermissionsViolation",
"(",
"err",
"string",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"// create error here so we can pass it as a closure to the async cb dispatcher.",
"e",
":=",
"errors",
".",
"New",
"(... | // processPermissionsViolation is called when the server signals a subject
// permissions violation on either publish or subscribe. | [
"processPermissionsViolation",
"is",
"called",
"when",
"the",
"server",
"signals",
"a",
"subject",
"permissions",
"violation",
"on",
"either",
"publish",
"or",
"subscribe",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2193-L2202 | train |
nats-io/go-nats | nats.go | processAuthorizationViolation | func (nc *Conn) processAuthorizationViolation(err string) {
nc.mu.Lock()
nc.err = ErrAuthorization
if nc.Opts.AsyncErrorCB != nil {
nc.ach.push(func() { nc.Opts.AsyncErrorCB(nc, nil, ErrAuthorization) })
}
nc.mu.Unlock()
} | go | func (nc *Conn) processAuthorizationViolation(err string) {
nc.mu.Lock()
nc.err = ErrAuthorization
if nc.Opts.AsyncErrorCB != nil {
nc.ach.push(func() { nc.Opts.AsyncErrorCB(nc, nil, ErrAuthorization) })
}
nc.mu.Unlock()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processAuthorizationViolation",
"(",
"err",
"string",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"nc",
".",
"err",
"=",
"ErrAuthorization",
"\n",
"if",
"nc",
".",
"Opts",
".",
"AsyncErrorCB",
"!=",
"... | // processAuthorizationViolation is called when the server signals a user
// authorization violation. | [
"processAuthorizationViolation",
"is",
"called",
"when",
"the",
"server",
"signals",
"a",
"user",
"authorization",
"violation",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2206-L2213 | train |
nats-io/go-nats | nats.go | flusher | func (nc *Conn) flusher() {
// Release the wait group
defer nc.wg.Done()
// snapshot the bw and conn since they can change from underneath of us.
nc.mu.Lock()
bw := nc.bw
conn := nc.conn
fch := nc.fch
nc.mu.Unlock()
if conn == nil || bw == nil {
return
}
for {
if _, ok := <-fch; !ok {
return
}
... | go | func (nc *Conn) flusher() {
// Release the wait group
defer nc.wg.Done()
// snapshot the bw and conn since they can change from underneath of us.
nc.mu.Lock()
bw := nc.bw
conn := nc.conn
fch := nc.fch
nc.mu.Unlock()
if conn == nil || bw == nil {
return
}
for {
if _, ok := <-fch; !ok {
return
}
... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"flusher",
"(",
")",
"{",
"// Release the wait group",
"defer",
"nc",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// snapshot the bw and conn since they can change from underneath of us.",
"nc",
".",
"mu",
".",
"Lock",
"(",
")... | // flusher is a separate Go routine that will process flush requests for the write
// bufio. This allows coalescing of writes to the underlying socket. | [
"flusher",
"is",
"a",
"separate",
"Go",
"routine",
"that",
"will",
"process",
"flush",
"requests",
"for",
"the",
"write",
"bufio",
".",
"This",
"allows",
"coalescing",
"of",
"writes",
"to",
"the",
"underlying",
"socket",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2217-L2252 | train |
nats-io/go-nats | nats.go | processPong | func (nc *Conn) processPong() {
var ch chan struct{}
nc.mu.Lock()
if len(nc.pongs) > 0 {
ch = nc.pongs[0]
nc.pongs = nc.pongs[1:]
}
nc.pout = 0
nc.mu.Unlock()
if ch != nil {
ch <- struct{}{}
}
} | go | func (nc *Conn) processPong() {
var ch chan struct{}
nc.mu.Lock()
if len(nc.pongs) > 0 {
ch = nc.pongs[0]
nc.pongs = nc.pongs[1:]
}
nc.pout = 0
nc.mu.Unlock()
if ch != nil {
ch <- struct{}{}
}
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processPong",
"(",
")",
"{",
"var",
"ch",
"chan",
"struct",
"{",
"}",
"\n\n",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"len",
"(",
"nc",
".",
"pongs",
")",
">",
"0",
"{",
"ch",
"=",
"nc",
"."... | // processPong is used to process responses to the client's ping
// messages. We use pings for the flush mechanism as well. | [
"processPong",
"is",
"used",
"to",
"process",
"responses",
"to",
"the",
"client",
"s",
"ping",
"messages",
".",
"We",
"use",
"pings",
"for",
"the",
"flush",
"mechanism",
"as",
"well",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2262-L2275 | train |
nats-io/go-nats | nats.go | processInfo | func (nc *Conn) processInfo(info string) error {
if info == _EMPTY_ {
return nil
}
ncInfo := serverInfo{}
if err := json.Unmarshal([]byte(info), &ncInfo); err != nil {
return err
}
// Copy content into connection's info structure.
nc.info = ncInfo
// The array could be empty/not present on initial connect,... | go | func (nc *Conn) processInfo(info string) error {
if info == _EMPTY_ {
return nil
}
ncInfo := serverInfo{}
if err := json.Unmarshal([]byte(info), &ncInfo); err != nil {
return err
}
// Copy content into connection's info structure.
nc.info = ncInfo
// The array could be empty/not present on initial connect,... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processInfo",
"(",
"info",
"string",
")",
"error",
"{",
"if",
"info",
"==",
"_EMPTY_",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"ncInfo",
":=",
"serverInfo",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmar... | // processInfo is used to parse the info messages sent
// from the server.
// This function may update the server pool. | [
"processInfo",
"is",
"used",
"to",
"parse",
"the",
"info",
"messages",
"sent",
"from",
"the",
"server",
".",
"This",
"function",
"may",
"update",
"the",
"server",
"pool",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2285-L2357 | train |
nats-io/go-nats | nats.go | processAsyncInfo | func (nc *Conn) processAsyncInfo(info []byte) {
nc.mu.Lock()
// Ignore errors, we will simply not update the server pool...
nc.processInfo(string(info))
nc.mu.Unlock()
} | go | func (nc *Conn) processAsyncInfo(info []byte) {
nc.mu.Lock()
// Ignore errors, we will simply not update the server pool...
nc.processInfo(string(info))
nc.mu.Unlock()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processAsyncInfo",
"(",
"info",
"[",
"]",
"byte",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"// Ignore errors, we will simply not update the server pool...",
"nc",
".",
"processInfo",
"(",
"string",
"(",
"i... | // processAsyncInfo does the same than processInfo, but is called
// from the parser. Calls processInfo under connection's lock
// protection. | [
"processAsyncInfo",
"does",
"the",
"same",
"than",
"processInfo",
"but",
"is",
"called",
"from",
"the",
"parser",
".",
"Calls",
"processInfo",
"under",
"connection",
"s",
"lock",
"protection",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2362-L2367 | train |
nats-io/go-nats | nats.go | LastError | func (nc *Conn) LastError() error {
if nc == nil {
return ErrInvalidConnection
}
nc.mu.RLock()
err := nc.err
nc.mu.RUnlock()
return err
} | go | func (nc *Conn) LastError() error {
if nc == nil {
return ErrInvalidConnection
}
nc.mu.RLock()
err := nc.err
nc.mu.RUnlock()
return err
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"LastError",
"(",
")",
"error",
"{",
"if",
"nc",
"==",
"nil",
"{",
"return",
"ErrInvalidConnection",
"\n",
"}",
"\n",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"err",
":=",
"nc",
".",
"err",
"\n",
"nc",
... | // LastError reports the last error encountered via the connection.
// It can be used reliably within ClosedCB in order to find out reason
// why connection was closed for example. | [
"LastError",
"reports",
"the",
"last",
"error",
"encountered",
"via",
"the",
"connection",
".",
"It",
"can",
"be",
"used",
"reliably",
"within",
"ClosedCB",
"in",
"order",
"to",
"find",
"out",
"reason",
"why",
"connection",
"was",
"closed",
"for",
"example",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2372-L2380 | train |
nats-io/go-nats | nats.go | processErr | func (nc *Conn) processErr(ie string) {
// Trim, remove quotes
ne := normalizeErr(ie)
// convert to lower case.
e := strings.ToLower(ne)
// FIXME(dlc) - process Slow Consumer signals special.
if e == STALE_CONNECTION {
nc.processOpErr(ErrStaleConnection)
} else if strings.HasPrefix(e, PERMISSIONS_ERR) {
nc.... | go | func (nc *Conn) processErr(ie string) {
// Trim, remove quotes
ne := normalizeErr(ie)
// convert to lower case.
e := strings.ToLower(ne)
// FIXME(dlc) - process Slow Consumer signals special.
if e == STALE_CONNECTION {
nc.processOpErr(ErrStaleConnection)
} else if strings.HasPrefix(e, PERMISSIONS_ERR) {
nc.... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processErr",
"(",
"ie",
"string",
")",
"{",
"// Trim, remove quotes",
"ne",
":=",
"normalizeErr",
"(",
"ie",
")",
"\n",
"// convert to lower case.",
"e",
":=",
"strings",
".",
"ToLower",
"(",
"ne",
")",
"\n\n",
"// FIX... | // processErr processes any error messages from the server and
// sets the connection's lastError. | [
"processErr",
"processes",
"any",
"error",
"messages",
"from",
"the",
"server",
"and",
"sets",
"the",
"connection",
"s",
"lastError",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2384-L2403 | train |
nats-io/go-nats | nats.go | Publish | func (nc *Conn) Publish(subj string, data []byte) error {
return nc.publish(subj, _EMPTY_, data)
} | go | func (nc *Conn) Publish(subj string, data []byte) error {
return nc.publish(subj, _EMPTY_, data)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"Publish",
"(",
"subj",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"nc",
".",
"publish",
"(",
"subj",
",",
"_EMPTY_",
",",
"data",
")",
"\n",
"}"
] | // Publish publishes the data argument to the given subject. The data
// argument is left untouched and needs to be correctly interpreted on
// the receiver. | [
"Publish",
"publishes",
"the",
"data",
"argument",
"to",
"the",
"given",
"subject",
".",
"The",
"data",
"argument",
"is",
"left",
"untouched",
"and",
"needs",
"to",
"be",
"correctly",
"interpreted",
"on",
"the",
"receiver",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2419-L2421 | train |
nats-io/go-nats | nats.go | PublishMsg | func (nc *Conn) PublishMsg(m *Msg) error {
if m == nil {
return ErrInvalidMsg
}
return nc.publish(m.Subject, m.Reply, m.Data)
} | go | func (nc *Conn) PublishMsg(m *Msg) error {
if m == nil {
return ErrInvalidMsg
}
return nc.publish(m.Subject, m.Reply, m.Data)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"PublishMsg",
"(",
"m",
"*",
"Msg",
")",
"error",
"{",
"if",
"m",
"==",
"nil",
"{",
"return",
"ErrInvalidMsg",
"\n",
"}",
"\n",
"return",
"nc",
".",
"publish",
"(",
"m",
".",
"Subject",
",",
"m",
".",
"Reply",... | // PublishMsg publishes the Msg structure, which includes the
// Subject, an optional Reply and an optional Data field. | [
"PublishMsg",
"publishes",
"the",
"Msg",
"structure",
"which",
"includes",
"the",
"Subject",
"an",
"optional",
"Reply",
"and",
"an",
"optional",
"Data",
"field",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2425-L2430 | train |
nats-io/go-nats | nats.go | publish | func (nc *Conn) publish(subj, reply string, data []byte) error {
if nc == nil {
return ErrInvalidConnection
}
if subj == "" {
return ErrBadSubject
}
nc.mu.Lock()
if nc.isClosed() {
nc.mu.Unlock()
return ErrConnectionClosed
}
if nc.isDrainingPubs() {
nc.mu.Unlock()
return ErrConnectionDraining
}
... | go | func (nc *Conn) publish(subj, reply string, data []byte) error {
if nc == nil {
return ErrInvalidConnection
}
if subj == "" {
return ErrBadSubject
}
nc.mu.Lock()
if nc.isClosed() {
nc.mu.Unlock()
return ErrConnectionClosed
}
if nc.isDrainingPubs() {
nc.mu.Unlock()
return ErrConnectionDraining
}
... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"publish",
"(",
"subj",
",",
"reply",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"nc",
"==",
"nil",
"{",
"return",
"ErrInvalidConnection",
"\n",
"}",
"\n",
"if",
"subj",
"==",
"\"",
"\"",
... | // publish is the internal function to publish messages to a nats-server.
// Sends a protocol data message by queuing into the bufio writer
// and kicking the flush go routine. These writes should be protected. | [
"publish",
"is",
"the",
"internal",
"function",
"to",
"publish",
"messages",
"to",
"a",
"nats",
"-",
"server",
".",
"Sends",
"a",
"protocol",
"data",
"message",
"by",
"queuing",
"into",
"the",
"bufio",
"writer",
"and",
"kicking",
"the",
"flush",
"go",
"rou... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2445-L2531 | train |
nats-io/go-nats | nats.go | respHandler | func (nc *Conn) respHandler(m *Msg) {
rt := respToken(m.Subject)
nc.mu.Lock()
// Just return if closed.
if nc.isClosed() {
nc.mu.Unlock()
return
}
// Grab mch
mch := nc.respMap[rt]
// Delete the key regardless, one response only.
// FIXME(dlc) - should we track responses past 1
// just statistics wise?
... | go | func (nc *Conn) respHandler(m *Msg) {
rt := respToken(m.Subject)
nc.mu.Lock()
// Just return if closed.
if nc.isClosed() {
nc.mu.Unlock()
return
}
// Grab mch
mch := nc.respMap[rt]
// Delete the key regardless, one response only.
// FIXME(dlc) - should we track responses past 1
// just statistics wise?
... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"respHandler",
"(",
"m",
"*",
"Msg",
")",
"{",
"rt",
":=",
"respToken",
"(",
"m",
".",
"Subject",
")",
"\n\n",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"// Just return if closed.",
"if",
"nc",
".",
"isClose... | // respHandler is the global response handler. It will look up
// the appropriate channel based on the last token and place
// the message on the channel if possible. | [
"respHandler",
"is",
"the",
"global",
"response",
"handler",
".",
"It",
"will",
"look",
"up",
"the",
"appropriate",
"channel",
"based",
"on",
"the",
"last",
"token",
"and",
"place",
"the",
"message",
"on",
"the",
"channel",
"if",
"possible",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2536-L2562 | train |
nats-io/go-nats | nats.go | createRespMux | func (nc *Conn) createRespMux(respSub string) error {
s, err := nc.Subscribe(respSub, nc.respHandler)
if err != nil {
return err
}
nc.mu.Lock()
nc.respMux = s
nc.mu.Unlock()
return nil
} | go | func (nc *Conn) createRespMux(respSub string) error {
s, err := nc.Subscribe(respSub, nc.respHandler)
if err != nil {
return err
}
nc.mu.Lock()
nc.respMux = s
nc.mu.Unlock()
return nil
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"createRespMux",
"(",
"respSub",
"string",
")",
"error",
"{",
"s",
",",
"err",
":=",
"nc",
".",
"Subscribe",
"(",
"respSub",
",",
"nc",
".",
"respHandler",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"er... | // Create the response subscription we will use for all
// new style responses. This will be on an _INBOX with an
// additional terminal token. The subscription will be on
// a wildcard. Caller is responsible for ensuring this is
// only called once. | [
"Create",
"the",
"response",
"subscription",
"we",
"will",
"use",
"for",
"all",
"new",
"style",
"responses",
".",
"This",
"will",
"be",
"on",
"an",
"_INBOX",
"with",
"an",
"additional",
"terminal",
"token",
".",
"The",
"subscription",
"will",
"be",
"on",
"... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2569-L2578 | train |
nats-io/go-nats | nats.go | Request | func (nc *Conn) Request(subj string, data []byte, timeout time.Duration) (*Msg, error) {
if nc == nil {
return nil, ErrInvalidConnection
}
nc.mu.Lock()
// If user wants the old style.
if nc.Opts.UseOldRequestStyle {
nc.mu.Unlock()
return nc.oldRequest(subj, data, timeout)
}
// Do setup for the new style.... | go | func (nc *Conn) Request(subj string, data []byte, timeout time.Duration) (*Msg, error) {
if nc == nil {
return nil, ErrInvalidConnection
}
nc.mu.Lock()
// If user wants the old style.
if nc.Opts.UseOldRequestStyle {
nc.mu.Unlock()
return nc.oldRequest(subj, data, timeout)
}
// Do setup for the new style.... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"Request",
"(",
"subj",
"string",
",",
"data",
"[",
"]",
"byte",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Msg",
",",
"error",
")",
"{",
"if",
"nc",
"==",
"nil",
"{",
"return",
"nil",
",",
"Er... | // Request will send a request payload and deliver the response message,
// or an error, including a timeout if no message was received properly. | [
"Request",
"will",
"send",
"a",
"request",
"payload",
"and",
"deliver",
"the",
"response",
"message",
"or",
"an",
"error",
"including",
"a",
"timeout",
"if",
"no",
"message",
"was",
"received",
"properly",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2582-L2639 | train |
nats-io/go-nats | nats.go | NewInbox | func NewInbox() string {
var b [inboxPrefixLen + nuidSize]byte
pres := b[:inboxPrefixLen]
copy(pres, InboxPrefix)
ns := b[inboxPrefixLen:]
copy(ns, nuid.Next())
return string(b[:])
} | go | func NewInbox() string {
var b [inboxPrefixLen + nuidSize]byte
pres := b[:inboxPrefixLen]
copy(pres, InboxPrefix)
ns := b[inboxPrefixLen:]
copy(ns, nuid.Next())
return string(b[:])
} | [
"func",
"NewInbox",
"(",
")",
"string",
"{",
"var",
"b",
"[",
"inboxPrefixLen",
"+",
"nuidSize",
"]",
"byte",
"\n",
"pres",
":=",
"b",
"[",
":",
"inboxPrefixLen",
"]",
"\n",
"copy",
"(",
"pres",
",",
"InboxPrefix",
")",
"\n",
"ns",
":=",
"b",
"[",
... | // NewInbox will return an inbox string which can be used for directed replies from
// subscribers. These are guaranteed to be unique, but can be shared and subscribed
// to by others. | [
"NewInbox",
"will",
"return",
"an",
"inbox",
"string",
"which",
"can",
"be",
"used",
"for",
"directed",
"replies",
"from",
"subscribers",
".",
"These",
"are",
"guaranteed",
"to",
"be",
"unique",
"but",
"can",
"be",
"shared",
"and",
"subscribed",
"to",
"by",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2675-L2682 | train |
nats-io/go-nats | nats.go | initNewResp | func (nc *Conn) initNewResp() {
// _INBOX wildcard
nc.respSub = fmt.Sprintf("%s.*", NewInbox())
nc.respMap = make(map[string]chan *Msg)
nc.respRand = rand.New(rand.NewSource(time.Now().UnixNano()))
} | go | func (nc *Conn) initNewResp() {
// _INBOX wildcard
nc.respSub = fmt.Sprintf("%s.*", NewInbox())
nc.respMap = make(map[string]chan *Msg)
nc.respRand = rand.New(rand.NewSource(time.Now().UnixNano()))
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"initNewResp",
"(",
")",
"{",
"// _INBOX wildcard",
"nc",
".",
"respSub",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"NewInbox",
"(",
")",
")",
"\n",
"nc",
".",
"respMap",
"=",
"make",
"(",
"map",
"[",
... | // Function to init new response structures. | [
"Function",
"to",
"init",
"new",
"response",
"structures",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2685-L2690 | train |
nats-io/go-nats | nats.go | newRespInbox | func (nc *Conn) newRespInbox() string {
if nc.respMap == nil {
nc.initNewResp()
}
var b [respInboxPrefixLen + replySuffixLen]byte
pres := b[:respInboxPrefixLen]
copy(pres, nc.respSub)
rn := nc.respRand.Int63()
for i, l := respInboxPrefixLen, rn; i < len(b); i++ {
b[i] = rdigits[l%base]
l /= base
}
return... | go | func (nc *Conn) newRespInbox() string {
if nc.respMap == nil {
nc.initNewResp()
}
var b [respInboxPrefixLen + replySuffixLen]byte
pres := b[:respInboxPrefixLen]
copy(pres, nc.respSub)
rn := nc.respRand.Int63()
for i, l := respInboxPrefixLen, rn; i < len(b); i++ {
b[i] = rdigits[l%base]
l /= base
}
return... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"newRespInbox",
"(",
")",
"string",
"{",
"if",
"nc",
".",
"respMap",
"==",
"nil",
"{",
"nc",
".",
"initNewResp",
"(",
")",
"\n",
"}",
"\n",
"var",
"b",
"[",
"respInboxPrefixLen",
"+",
"replySuffixLen",
"]",
"byte"... | // newRespInbox creates a new literal response subject
// that will trigger the mux subscription handler.
// Lock should be held. | [
"newRespInbox",
"creates",
"a",
"new",
"literal",
"response",
"subject",
"that",
"will",
"trigger",
"the",
"mux",
"subscription",
"handler",
".",
"Lock",
"should",
"be",
"held",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2695-L2708 | train |
nats-io/go-nats | nats.go | NewRespInbox | func (nc *Conn) NewRespInbox() string {
nc.mu.Lock()
s := nc.newRespInbox()
nc.mu.Unlock()
return s
} | go | func (nc *Conn) NewRespInbox() string {
nc.mu.Lock()
s := nc.newRespInbox()
nc.mu.Unlock()
return s
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"NewRespInbox",
"(",
")",
"string",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
":=",
"nc",
".",
"newRespInbox",
"(",
")",
"\n",
"nc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
"... | // NewRespInbox is the new format used for _INBOX. | [
"NewRespInbox",
"is",
"the",
"new",
"format",
"used",
"for",
"_INBOX",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2711-L2716 | train |
nats-io/go-nats | nats.go | QueueSubscribe | func (nc *Conn) QueueSubscribe(subj, queue string, cb MsgHandler) (*Subscription, error) {
return nc.subscribe(subj, queue, cb, nil, false)
} | go | func (nc *Conn) QueueSubscribe(subj, queue string, cb MsgHandler) (*Subscription, error) {
return nc.subscribe(subj, queue, cb, nil, false)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"QueueSubscribe",
"(",
"subj",
",",
"queue",
"string",
",",
"cb",
"MsgHandler",
")",
"(",
"*",
"Subscription",
",",
"error",
")",
"{",
"return",
"nc",
".",
"subscribe",
"(",
"subj",
",",
"queue",
",",
"cb",
",",
... | // QueueSubscribe creates an asynchronous queue subscriber on the given subject.
// All subscribers with the same queue name will form the queue group and
// only one member of the group will be selected to receive any given
// message asynchronously. | [
"QueueSubscribe",
"creates",
"an",
"asynchronous",
"queue",
"subscriber",
"on",
"the",
"given",
"subject",
".",
"All",
"subscribers",
"with",
"the",
"same",
"queue",
"name",
"will",
"form",
"the",
"queue",
"group",
"and",
"only",
"one",
"member",
"of",
"the",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2763-L2765 | train |
nats-io/go-nats | nats.go | subscribe | func (nc *Conn) subscribe(subj, queue string, cb MsgHandler, ch chan *Msg, isSync bool) (*Subscription, error) {
if nc == nil {
return nil, ErrInvalidConnection
}
nc.mu.Lock()
// ok here, but defer is generally expensive
defer nc.mu.Unlock()
// Check for some error conditions.
if nc.isClosed() {
return nil,... | go | func (nc *Conn) subscribe(subj, queue string, cb MsgHandler, ch chan *Msg, isSync bool) (*Subscription, error) {
if nc == nil {
return nil, ErrInvalidConnection
}
nc.mu.Lock()
// ok here, but defer is generally expensive
defer nc.mu.Unlock()
// Check for some error conditions.
if nc.isClosed() {
return nil,... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"subscribe",
"(",
"subj",
",",
"queue",
"string",
",",
"cb",
"MsgHandler",
",",
"ch",
"chan",
"*",
"Msg",
",",
"isSync",
"bool",
")",
"(",
"*",
"Subscription",
",",
"error",
")",
"{",
"if",
"nc",
"==",
"nil",
... | // subscribe is the internal subscribe function that indicates interest in a subject. | [
"subscribe",
"is",
"the",
"internal",
"subscribe",
"function",
"that",
"indicates",
"interest",
"in",
"a",
"subject",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2788-L2844 | train |
nats-io/go-nats | nats.go | NumSubscriptions | func (nc *Conn) NumSubscriptions() int {
nc.mu.RLock()
defer nc.mu.RUnlock()
return len(nc.subs)
} | go | func (nc *Conn) NumSubscriptions() int {
nc.mu.RLock()
defer nc.mu.RUnlock()
return len(nc.subs)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"NumSubscriptions",
"(",
")",
"int",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"nc",
".",
"subs",
")",
"\n",
"}"
] | // NumSubscriptions returns active number of subscriptions. | [
"NumSubscriptions",
"returns",
"active",
"number",
"of",
"subscriptions",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2847-L2851 | train |
nats-io/go-nats | nats.go | removeSub | func (nc *Conn) removeSub(s *Subscription) {
nc.subsMu.Lock()
delete(nc.subs, s.sid)
nc.subsMu.Unlock()
s.mu.Lock()
defer s.mu.Unlock()
// Release callers on NextMsg for SyncSubscription only
if s.mch != nil && s.typ == SyncSubscription {
close(s.mch)
}
s.mch = nil
// Mark as invalid
s.conn = nil
s.close... | go | func (nc *Conn) removeSub(s *Subscription) {
nc.subsMu.Lock()
delete(nc.subs, s.sid)
nc.subsMu.Unlock()
s.mu.Lock()
defer s.mu.Unlock()
// Release callers on NextMsg for SyncSubscription only
if s.mch != nil && s.typ == SyncSubscription {
close(s.mch)
}
s.mch = nil
// Mark as invalid
s.conn = nil
s.close... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"removeSub",
"(",
"s",
"*",
"Subscription",
")",
"{",
"nc",
".",
"subsMu",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"nc",
".",
"subs",
",",
"s",
".",
"sid",
")",
"\n",
"nc",
".",
"subsMu",
".",
"Unlock",
... | // Lock for nc should be held here upon entry | [
"Lock",
"for",
"nc",
"should",
"be",
"held",
"here",
"upon",
"entry"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2854-L2872 | train |
nats-io/go-nats | nats.go | Type | func (s *Subscription) Type() SubscriptionType {
if s == nil {
return NilSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
return s.typ
} | go | func (s *Subscription) Type() SubscriptionType {
if s == nil {
return NilSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
return s.typ
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"Type",
"(",
")",
"SubscriptionType",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"NilSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
... | // Type returns the type of Subscription. | [
"Type",
"returns",
"the",
"type",
"of",
"Subscription",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2886-L2893 | train |
nats-io/go-nats | nats.go | Drain | func (s *Subscription) Drain() error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
return conn.unsubscribe(s, 0, true)
} | go | func (s *Subscription) Drain() error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
return conn.unsubscribe(s, 0, true)
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"Drain",
"(",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrBadSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"conn",
":=",
"s",
".",
"conn",
"\n",
"s",
"... | // Drain will remove interest but continue callbacks until all messages
// have been processed. | [
"Drain",
"will",
"remove",
"interest",
"but",
"continue",
"callbacks",
"until",
"all",
"messages",
"have",
"been",
"processed",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2909-L2920 | train |
nats-io/go-nats | nats.go | Unsubscribe | func (s *Subscription) Unsubscribe() error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
if conn.IsDraining() {
return ErrConnectionDraining
}
return conn.unsubscribe(s, 0, false)
} | go | func (s *Subscription) Unsubscribe() error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
if conn.IsDraining() {
return ErrConnectionDraining
}
return conn.unsubscribe(s, 0, false)
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"Unsubscribe",
"(",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrBadSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"conn",
":=",
"s",
".",
"conn",
"\n",
"s... | // Unsubscribe will remove interest in the given subject. | [
"Unsubscribe",
"will",
"remove",
"interest",
"in",
"the",
"given",
"subject",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2923-L2937 | train |
nats-io/go-nats | nats.go | checkDrained | func (nc *Conn) checkDrained(sub *Subscription) {
if nc == nil || sub == nil {
return
}
// This allows us to know that whatever we have in the client pending
// is correct and the server will not send additional information.
nc.Flush()
// Once we are here we just wait for Pending to reach 0 or
// any other s... | go | func (nc *Conn) checkDrained(sub *Subscription) {
if nc == nil || sub == nil {
return
}
// This allows us to know that whatever we have in the client pending
// is correct and the server will not send additional information.
nc.Flush()
// Once we are here we just wait for Pending to reach 0 or
// any other s... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"checkDrained",
"(",
"sub",
"*",
"Subscription",
")",
"{",
"if",
"nc",
"==",
"nil",
"||",
"sub",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// This allows us to know that whatever we have in the client pending",
"// is c... | // checkDrained will watch for a subscription to be fully drained
// and then remove it. | [
"checkDrained",
"will",
"watch",
"for",
"a",
"subscription",
"to",
"be",
"fully",
"drained",
"and",
"then",
"remove",
"it",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2941-L2974 | train |
nats-io/go-nats | nats.go | AutoUnsubscribe | func (s *Subscription) AutoUnsubscribe(max int) error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
return conn.unsubscribe(s, max, false)
} | go | func (s *Subscription) AutoUnsubscribe(max int) error {
if s == nil {
return ErrBadSubscription
}
s.mu.Lock()
conn := s.conn
s.mu.Unlock()
if conn == nil {
return ErrBadSubscription
}
return conn.unsubscribe(s, max, false)
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"AutoUnsubscribe",
"(",
"max",
"int",
")",
"error",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"ErrBadSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"conn",
":=",
"s",
".",
... | // AutoUnsubscribe will issue an automatic Unsubscribe that is
// processed by the server when max messages have been received.
// This can be useful when sending a request to an unknown number
// of subscribers. | [
"AutoUnsubscribe",
"will",
"issue",
"an",
"automatic",
"Unsubscribe",
"that",
"is",
"processed",
"by",
"the",
"server",
"when",
"max",
"messages",
"have",
"been",
"received",
".",
"This",
"can",
"be",
"useful",
"when",
"sending",
"a",
"request",
"to",
"an",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L2980-L2991 | train |
nats-io/go-nats | nats.go | NextMsg | func (s *Subscription) NextMsg(timeout time.Duration) (*Msg, error) {
if s == nil {
return nil, ErrBadSubscription
}
s.mu.Lock()
err := s.validateNextMsgState()
if err != nil {
s.mu.Unlock()
return nil, err
}
// snapshot
mch := s.mch
s.mu.Unlock()
var ok bool
var msg *Msg
// If something is availa... | go | func (s *Subscription) NextMsg(timeout time.Duration) (*Msg, error) {
if s == nil {
return nil, ErrBadSubscription
}
s.mu.Lock()
err := s.validateNextMsgState()
if err != nil {
s.mu.Unlock()
return nil, err
}
// snapshot
mch := s.mch
s.mu.Unlock()
var ok bool
var msg *Msg
// If something is availa... | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"NextMsg",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Msg",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrBadSubscription",
"\n",
"}",
"\n\n",
"s",
".",
"mu"... | // NextMsg will return the next message available to a synchronous subscriber
// or block until one is available. A timeout can be used to return when no
// message has been delivered. | [
"NextMsg",
"will",
"return",
"the",
"next",
"message",
"available",
"to",
"a",
"synchronous",
"subscriber",
"or",
"block",
"until",
"one",
"is",
"available",
".",
"A",
"timeout",
"can",
"be",
"used",
"to",
"return",
"when",
"no",
"message",
"has",
"been",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3036-L3088 | train |
nats-io/go-nats | nats.go | validateNextMsgState | func (s *Subscription) validateNextMsgState() error {
if s.connClosed {
return ErrConnectionClosed
}
if s.mch == nil {
if s.max > 0 && s.delivered >= s.max {
return ErrMaxMessages
} else if s.closed {
return ErrBadSubscription
}
}
if s.mcb != nil {
return ErrSyncSubRequired
}
if s.sc {
s.sc = f... | go | func (s *Subscription) validateNextMsgState() error {
if s.connClosed {
return ErrConnectionClosed
}
if s.mch == nil {
if s.max > 0 && s.delivered >= s.max {
return ErrMaxMessages
} else if s.closed {
return ErrBadSubscription
}
}
if s.mcb != nil {
return ErrSyncSubRequired
}
if s.sc {
s.sc = f... | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"validateNextMsgState",
"(",
")",
"error",
"{",
"if",
"s",
".",
"connClosed",
"{",
"return",
"ErrConnectionClosed",
"\n",
"}",
"\n",
"if",
"s",
".",
"mch",
"==",
"nil",
"{",
"if",
"s",
".",
"max",
">",
"0",... | // validateNextMsgState checks whether the subscription is in a valid
// state to call NextMsg and be delivered another message synchronously.
// This should be called while holding the lock. | [
"validateNextMsgState",
"checks",
"whether",
"the",
"subscription",
"is",
"in",
"a",
"valid",
"state",
"to",
"call",
"NextMsg",
"and",
"be",
"delivered",
"another",
"message",
"synchronously",
".",
"This",
"should",
"be",
"called",
"while",
"holding",
"the",
"lo... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3093-L3113 | train |
nats-io/go-nats | nats.go | processNextMsgDelivered | func (s *Subscription) processNextMsgDelivered(msg *Msg) error {
s.mu.Lock()
nc := s.conn
max := s.max
// Update some stats.
s.delivered++
delivered := s.delivered
if s.typ == SyncSubscription {
s.pMsgs--
s.pBytes -= len(msg.Data)
}
s.mu.Unlock()
if max > 0 {
if delivered > max {
return ErrMaxMessa... | go | func (s *Subscription) processNextMsgDelivered(msg *Msg) error {
s.mu.Lock()
nc := s.conn
max := s.max
// Update some stats.
s.delivered++
delivered := s.delivered
if s.typ == SyncSubscription {
s.pMsgs--
s.pBytes -= len(msg.Data)
}
s.mu.Unlock()
if max > 0 {
if delivered > max {
return ErrMaxMessa... | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"processNextMsgDelivered",
"(",
"msg",
"*",
"Msg",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"nc",
":=",
"s",
".",
"conn",
"\n",
"max",
":=",
"s",
".",
"max",
"\n\n",
"// Update some... | // processNextMsgDelivered takes a message and applies the needed
// accounting to the stats from the subscription, returning an
// error in case we have the maximum number of messages have been
// delivered already. It should not be called while holding the lock. | [
"processNextMsgDelivered",
"takes",
"a",
"message",
"and",
"applies",
"the",
"needed",
"accounting",
"to",
"the",
"stats",
"from",
"the",
"subscription",
"returning",
"an",
"error",
"in",
"case",
"we",
"have",
"the",
"maximum",
"number",
"of",
"messages",
"have"... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3119-L3146 | train |
nats-io/go-nats | nats.go | Pending | func (s *Subscription) Pending() (int, int, error) {
if s == nil {
return -1, -1, ErrBadSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
if s.conn == nil {
return -1, -1, ErrBadSubscription
}
if s.typ == ChanSubscription {
return -1, -1, ErrTypeSubscription
}
return s.pMsgs, s.pBytes, nil
} | go | func (s *Subscription) Pending() (int, int, error) {
if s == nil {
return -1, -1, ErrBadSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
if s.conn == nil {
return -1, -1, ErrBadSubscription
}
if s.typ == ChanSubscription {
return -1, -1, ErrTypeSubscription
}
return s.pMsgs, s.pBytes, nil
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"Pending",
"(",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"-",
"1",
",",
"ErrBadSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
... | // Pending returns the number of queued messages and queued bytes in the client for this subscription. | [
"Pending",
"returns",
"the",
"number",
"of",
"queued",
"messages",
"and",
"queued",
"bytes",
"in",
"the",
"client",
"for",
"this",
"subscription",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3156-L3169 | train |
nats-io/go-nats | nats.go | PendingLimits | func (s *Subscription) PendingLimits() (int, int, error) {
if s == nil {
return -1, -1, ErrBadSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
if s.conn == nil {
return -1, -1, ErrBadSubscription
}
if s.typ == ChanSubscription {
return -1, -1, ErrTypeSubscription
}
return s.pMsgsLimit, s.pBytesLimit, nil
} | go | func (s *Subscription) PendingLimits() (int, int, error) {
if s == nil {
return -1, -1, ErrBadSubscription
}
s.mu.Lock()
defer s.mu.Unlock()
if s.conn == nil {
return -1, -1, ErrBadSubscription
}
if s.typ == ChanSubscription {
return -1, -1, ErrTypeSubscription
}
return s.pMsgsLimit, s.pBytesLimit, nil
} | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"PendingLimits",
"(",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"-",
"1",
",",
"ErrBadSubscription",
"\n",
"}",
"\n",
"s",
".",
"mu",
"... | // PendingLimits returns the current limits for this subscription.
// If no error is returned, a negative value indicates that the
// given metric is not limited. | [
"PendingLimits",
"returns",
"the",
"current",
"limits",
"for",
"this",
"subscription",
".",
"If",
"no",
"error",
"is",
"returned",
"a",
"negative",
"value",
"indicates",
"that",
"the",
"given",
"metric",
"is",
"not",
"limited",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3213-L3226 | train |
nats-io/go-nats | nats.go | sendPing | func (nc *Conn) sendPing(ch chan struct{}) {
nc.pongs = append(nc.pongs, ch)
nc.bw.WriteString(pingProto)
// Flush in place.
nc.bw.Flush()
} | go | func (nc *Conn) sendPing(ch chan struct{}) {
nc.pongs = append(nc.pongs, ch)
nc.bw.WriteString(pingProto)
// Flush in place.
nc.bw.Flush()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"sendPing",
"(",
"ch",
"chan",
"struct",
"{",
"}",
")",
"{",
"nc",
".",
"pongs",
"=",
"append",
"(",
"nc",
".",
"pongs",
",",
"ch",
")",
"\n",
"nc",
".",
"bw",
".",
"WriteString",
"(",
"pingProto",
")",
"\n"... | // The lock must be held entering this function. | [
"The",
"lock",
"must",
"be",
"held",
"entering",
"this",
"function",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3298-L3303 | train |
nats-io/go-nats | nats.go | processPingTimer | func (nc *Conn) processPingTimer() {
nc.mu.Lock()
if nc.status != CONNECTED {
nc.mu.Unlock()
return
}
// Check for violation
nc.pout++
if nc.pout > nc.Opts.MaxPingsOut {
nc.mu.Unlock()
nc.processOpErr(ErrStaleConnection)
return
}
nc.sendPing(nil)
nc.ptmr.Reset(nc.Opts.PingInterval)
nc.mu.Unlock()... | go | func (nc *Conn) processPingTimer() {
nc.mu.Lock()
if nc.status != CONNECTED {
nc.mu.Unlock()
return
}
// Check for violation
nc.pout++
if nc.pout > nc.Opts.MaxPingsOut {
nc.mu.Unlock()
nc.processOpErr(ErrStaleConnection)
return
}
nc.sendPing(nil)
nc.ptmr.Reset(nc.Opts.PingInterval)
nc.mu.Unlock()... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"processPingTimer",
"(",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"nc",
".",
"status",
"!=",
"CONNECTED",
"{",
"nc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\... | // This will fire periodically and send a client origin
// ping to the server. Will also check that we have received
// responses from the server. | [
"This",
"will",
"fire",
"periodically",
"and",
"send",
"a",
"client",
"origin",
"ping",
"to",
"the",
"server",
".",
"Will",
"also",
"check",
"that",
"we",
"have",
"received",
"responses",
"from",
"the",
"server",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3308-L3327 | train |
nats-io/go-nats | nats.go | resendSubscriptions | func (nc *Conn) resendSubscriptions() {
// Since we are going to send protocols to the server, we don't want to
// be holding the subsMu lock (which is used in processMsg). So copy
// the subscriptions in a temporary array.
nc.subsMu.RLock()
subs := make([]*Subscription, 0, len(nc.subs))
for _, s := range nc.subs... | go | func (nc *Conn) resendSubscriptions() {
// Since we are going to send protocols to the server, we don't want to
// be holding the subsMu lock (which is used in processMsg). So copy
// the subscriptions in a temporary array.
nc.subsMu.RLock()
subs := make([]*Subscription, 0, len(nc.subs))
for _, s := range nc.subs... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"resendSubscriptions",
"(",
")",
"{",
"// Since we are going to send protocols to the server, we don't want to",
"// be holding the subsMu lock (which is used in processMsg). So copy",
"// the subscriptions in a temporary array.",
"nc",
".",
"subsMu... | // resendSubscriptions will send our subscription state back to the
// server. Used in reconnects | [
"resendSubscriptions",
"will",
"send",
"our",
"subscription",
"state",
"back",
"to",
"the",
"server",
".",
"Used",
"in",
"reconnects"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3389-L3422 | train |
nats-io/go-nats | nats.go | clearPendingFlushCalls | func (nc *Conn) clearPendingFlushCalls() {
// Clear any queued pongs, e.g. pending flush calls.
for _, ch := range nc.pongs {
if ch != nil {
close(ch)
}
}
nc.pongs = nil
} | go | func (nc *Conn) clearPendingFlushCalls() {
// Clear any queued pongs, e.g. pending flush calls.
for _, ch := range nc.pongs {
if ch != nil {
close(ch)
}
}
nc.pongs = nil
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"clearPendingFlushCalls",
"(",
")",
"{",
"// Clear any queued pongs, e.g. pending flush calls.",
"for",
"_",
",",
"ch",
":=",
"range",
"nc",
".",
"pongs",
"{",
"if",
"ch",
"!=",
"nil",
"{",
"close",
"(",
"ch",
")",
"\n"... | // This will clear any pending flush calls and release pending calls.
// Lock is assumed to be held by the caller. | [
"This",
"will",
"clear",
"any",
"pending",
"flush",
"calls",
"and",
"release",
"pending",
"calls",
".",
"Lock",
"is",
"assumed",
"to",
"be",
"held",
"by",
"the",
"caller",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3426-L3434 | train |
nats-io/go-nats | nats.go | clearPendingRequestCalls | func (nc *Conn) clearPendingRequestCalls() {
if nc.respMap == nil {
return
}
for key, ch := range nc.respMap {
if ch != nil {
close(ch)
delete(nc.respMap, key)
}
}
} | go | func (nc *Conn) clearPendingRequestCalls() {
if nc.respMap == nil {
return
}
for key, ch := range nc.respMap {
if ch != nil {
close(ch)
delete(nc.respMap, key)
}
}
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"clearPendingRequestCalls",
"(",
")",
"{",
"if",
"nc",
".",
"respMap",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"key",
",",
"ch",
":=",
"range",
"nc",
".",
"respMap",
"{",
"if",
"ch",
"!=",
"nil",
"... | // This will clear any pending Request calls.
// Lock is assumed to be held by the caller. | [
"This",
"will",
"clear",
"any",
"pending",
"Request",
"calls",
".",
"Lock",
"is",
"assumed",
"to",
"be",
"held",
"by",
"the",
"caller",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3438-L3448 | train |
nats-io/go-nats | nats.go | close | func (nc *Conn) close(status Status, doCBs bool) {
nc.mu.Lock()
if nc.isClosed() {
nc.status = status
nc.mu.Unlock()
return
}
nc.status = CLOSED
// Kick the Go routines so they fall out.
nc.kickFlusher()
nc.mu.Unlock()
nc.mu.Lock()
// Clear any queued pongs, e.g. pending flush calls.
nc.clearPendingF... | go | func (nc *Conn) close(status Status, doCBs bool) {
nc.mu.Lock()
if nc.isClosed() {
nc.status = status
nc.mu.Unlock()
return
}
nc.status = CLOSED
// Kick the Go routines so they fall out.
nc.kickFlusher()
nc.mu.Unlock()
nc.mu.Lock()
// Clear any queued pongs, e.g. pending flush calls.
nc.clearPendingF... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"close",
"(",
"status",
"Status",
",",
"doCBs",
"bool",
")",
"{",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"nc",
".",
"isClosed",
"(",
")",
"{",
"nc",
".",
"status",
"=",
"status",
"\n",
"nc",
"... | // Low level close call that will do correct cleanup and set
// desired status. Also controls whether user defined callbacks
// will be triggered. The lock should not be held entering this
// function. This function will handle the locking manually. | [
"Low",
"level",
"close",
"call",
"that",
"will",
"do",
"correct",
"cleanup",
"and",
"set",
"desired",
"status",
".",
"Also",
"controls",
"whether",
"user",
"defined",
"callbacks",
"will",
"be",
"triggered",
".",
"The",
"lock",
"should",
"not",
"be",
"held",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3454-L3523 | train |
nats-io/go-nats | nats.go | IsClosed | func (nc *Conn) IsClosed() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isClosed()
} | go | func (nc *Conn) IsClosed() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isClosed()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"IsClosed",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"isClosed",
"(",
")",
"\n",
"}"
] | // IsClosed tests if a Conn has been closed. | [
"IsClosed",
"tests",
"if",
"a",
"Conn",
"has",
"been",
"closed",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3534-L3538 | train |
nats-io/go-nats | nats.go | IsReconnecting | func (nc *Conn) IsReconnecting() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isReconnecting()
} | go | func (nc *Conn) IsReconnecting() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isReconnecting()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"IsReconnecting",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"isReconnecting",
"(",
")",
"\n",
"}"
] | // IsReconnecting tests if a Conn is reconnecting. | [
"IsReconnecting",
"tests",
"if",
"a",
"Conn",
"is",
"reconnecting",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3541-L3545 | train |
nats-io/go-nats | nats.go | IsConnected | func (nc *Conn) IsConnected() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isConnected()
} | go | func (nc *Conn) IsConnected() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isConnected()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"IsConnected",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"isConnected",
"(",
")",
"\n",
"}"
] | // IsConnected tests if a Conn is connected. | [
"IsConnected",
"tests",
"if",
"a",
"Conn",
"is",
"connected",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3548-L3552 | train |
nats-io/go-nats | nats.go | drainConnection | func (nc *Conn) drainConnection() {
// Snapshot subs list.
nc.mu.Lock()
subs := make([]*Subscription, 0, len(nc.subs))
for _, s := range nc.subs {
subs = append(subs, s)
}
errCB := nc.Opts.AsyncErrorCB
drainWait := nc.Opts.DrainTimeout
nc.mu.Unlock()
// for pushing errors with context.
pushErr := func(err ... | go | func (nc *Conn) drainConnection() {
// Snapshot subs list.
nc.mu.Lock()
subs := make([]*Subscription, 0, len(nc.subs))
for _, s := range nc.subs {
subs = append(subs, s)
}
errCB := nc.Opts.AsyncErrorCB
drainWait := nc.Opts.DrainTimeout
nc.mu.Unlock()
// for pushing errors with context.
pushErr := func(err ... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"drainConnection",
"(",
")",
"{",
"// Snapshot subs list.",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"subs",
":=",
"make",
"(",
"[",
"]",
"*",
"Subscription",
",",
"0",
",",
"len",
"(",
"nc",
".",
"subs",
... | // drainConnection will run in a separate Go routine and will
// flush all publishes and drain all active subscriptions. | [
"drainConnection",
"will",
"run",
"in",
"a",
"separate",
"Go",
"routine",
"and",
"will",
"flush",
"all",
"publishes",
"and",
"drain",
"all",
"active",
"subscriptions",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3556-L3614 | train |
nats-io/go-nats | nats.go | IsDraining | func (nc *Conn) IsDraining() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isDraining()
} | go | func (nc *Conn) IsDraining() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.isDraining()
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"IsDraining",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"isDraining",
"(",
")",
"\n",
"}"
] | // IsDraining tests if a Conn is in the draining state. | [
"IsDraining",
"tests",
"if",
"a",
"Conn",
"is",
"in",
"the",
"draining",
"state",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3641-L3645 | train |
nats-io/go-nats | nats.go | getServers | func (nc *Conn) getServers(implicitOnly bool) []string {
poolSize := len(nc.srvPool)
var servers = make([]string, 0)
for i := 0; i < poolSize; i++ {
if implicitOnly && !nc.srvPool[i].isImplicit {
continue
}
url := nc.srvPool[i].url
servers = append(servers, fmt.Sprintf("%s://%s", url.Scheme, url.Host))
}... | go | func (nc *Conn) getServers(implicitOnly bool) []string {
poolSize := len(nc.srvPool)
var servers = make([]string, 0)
for i := 0; i < poolSize; i++ {
if implicitOnly && !nc.srvPool[i].isImplicit {
continue
}
url := nc.srvPool[i].url
servers = append(servers, fmt.Sprintf("%s://%s", url.Scheme, url.Host))
}... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"getServers",
"(",
"implicitOnly",
"bool",
")",
"[",
"]",
"string",
"{",
"poolSize",
":=",
"len",
"(",
"nc",
".",
"srvPool",
")",
"\n",
"var",
"servers",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\... | // caller must lock | [
"caller",
"must",
"lock"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3648-L3659 | train |
nats-io/go-nats | nats.go | Servers | func (nc *Conn) Servers() []string {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.getServers(false)
} | go | func (nc *Conn) Servers() []string {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.getServers(false)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"Servers",
"(",
")",
"[",
"]",
"string",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"getServers",
"(",
"false",
")",
... | // Servers returns the list of known server urls, including additional
// servers discovered after a connection has been established. If
// authentication is enabled, use UserInfo or Token when connecting with
// these urls. | [
"Servers",
"returns",
"the",
"list",
"of",
"known",
"server",
"urls",
"including",
"additional",
"servers",
"discovered",
"after",
"a",
"connection",
"has",
"been",
"established",
".",
"If",
"authentication",
"is",
"enabled",
"use",
"UserInfo",
"or",
"Token",
"w... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3665-L3669 | train |
nats-io/go-nats | nats.go | DiscoveredServers | func (nc *Conn) DiscoveredServers() []string {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.getServers(true)
} | go | func (nc *Conn) DiscoveredServers() []string {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.getServers(true)
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"DiscoveredServers",
"(",
")",
"[",
"]",
"string",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"getServers",
"(",
"true",
... | // DiscoveredServers returns only the server urls that have been discovered
// after a connection has been established. If authentication is enabled,
// use UserInfo or Token when connecting with these urls. | [
"DiscoveredServers",
"returns",
"only",
"the",
"server",
"urls",
"that",
"have",
"been",
"discovered",
"after",
"a",
"connection",
"has",
"been",
"established",
".",
"If",
"authentication",
"is",
"enabled",
"use",
"UserInfo",
"or",
"Token",
"when",
"connecting",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3674-L3678 | train |
nats-io/go-nats | nats.go | Status | func (nc *Conn) Status() Status {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.status
} | go | func (nc *Conn) Status() Status {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.status
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"Status",
"(",
")",
"Status",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"status",
"\n",
"}"
] | // Status returns the current state of the connection. | [
"Status",
"returns",
"the",
"current",
"state",
"of",
"the",
"connection",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3681-L3685 | train |
nats-io/go-nats | nats.go | isDraining | func (nc *Conn) isDraining() bool {
return nc.status == DRAINING_SUBS || nc.status == DRAINING_PUBS
} | go | func (nc *Conn) isDraining() bool {
return nc.status == DRAINING_SUBS || nc.status == DRAINING_PUBS
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"isDraining",
"(",
")",
"bool",
"{",
"return",
"nc",
".",
"status",
"==",
"DRAINING_SUBS",
"||",
"nc",
".",
"status",
"==",
"DRAINING_PUBS",
"\n",
"}"
] | // Test if Conn is in the draining state. | [
"Test",
"if",
"Conn",
"is",
"in",
"the",
"draining",
"state",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3708-L3710 | train |
nats-io/go-nats | nats.go | Stats | func (nc *Conn) Stats() Statistics {
// Stats are updated either under connection's mu or subsMu mutexes.
// Lock both to safely get them.
nc.mu.Lock()
nc.subsMu.RLock()
stats := Statistics{
InMsgs: nc.InMsgs,
InBytes: nc.InBytes,
OutMsgs: nc.OutMsgs,
OutBytes: nc.OutBytes,
Reconnects: nc.Rec... | go | func (nc *Conn) Stats() Statistics {
// Stats are updated either under connection's mu or subsMu mutexes.
// Lock both to safely get them.
nc.mu.Lock()
nc.subsMu.RLock()
stats := Statistics{
InMsgs: nc.InMsgs,
InBytes: nc.InBytes,
OutMsgs: nc.OutMsgs,
OutBytes: nc.OutBytes,
Reconnects: nc.Rec... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"Stats",
"(",
")",
"Statistics",
"{",
"// Stats are updated either under connection's mu or subsMu mutexes.",
"// Lock both to safely get them.",
"nc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"nc",
".",
"subsMu",
".",
"RLock",
... | // Stats will return a race safe copy of the Statistics section for the connection. | [
"Stats",
"will",
"return",
"a",
"race",
"safe",
"copy",
"of",
"the",
"Statistics",
"section",
"for",
"the",
"connection",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3718-L3733 | train |
nats-io/go-nats | nats.go | MaxPayload | func (nc *Conn) MaxPayload() int64 {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.MaxPayload
} | go | func (nc *Conn) MaxPayload() int64 {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.MaxPayload
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"MaxPayload",
"(",
")",
"int64",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"info",
".",
"MaxPayload",
"\n",
"}"
] | // MaxPayload returns the size limit that a message payload can have.
// This is set by the server configuration and delivered to the client
// upon connect. | [
"MaxPayload",
"returns",
"the",
"size",
"limit",
"that",
"a",
"message",
"payload",
"can",
"have",
".",
"This",
"is",
"set",
"by",
"the",
"server",
"configuration",
"and",
"delivered",
"to",
"the",
"client",
"upon",
"connect",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3738-L3742 | train |
nats-io/go-nats | nats.go | AuthRequired | func (nc *Conn) AuthRequired() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.AuthRequired
} | go | func (nc *Conn) AuthRequired() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.AuthRequired
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"AuthRequired",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"info",
".",
"AuthRequired",
"\n",
"}"
] | // AuthRequired will return if the connected server requires authorization. | [
"AuthRequired",
"will",
"return",
"if",
"the",
"connected",
"server",
"requires",
"authorization",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3745-L3749 | train |
nats-io/go-nats | nats.go | TLSRequired | func (nc *Conn) TLSRequired() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.TLSRequired
} | go | func (nc *Conn) TLSRequired() bool {
nc.mu.RLock()
defer nc.mu.RUnlock()
return nc.info.TLSRequired
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"TLSRequired",
"(",
")",
"bool",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"nc",
".",
"info",
".",
"TLSRequired",
"\n",
"}"
] | // TLSRequired will return if the connected server requires TLS connections. | [
"TLSRequired",
"will",
"return",
"if",
"the",
"connected",
"server",
"requires",
"TLS",
"connections",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3752-L3756 | train |
nats-io/go-nats | nats.go | GetClientID | func (nc *Conn) GetClientID() (uint64, error) {
nc.mu.RLock()
defer nc.mu.RUnlock()
if nc.isClosed() {
return 0, ErrConnectionClosed
}
if nc.info.CID == 0 {
return 0, ErrClientIDNotSupported
}
return nc.info.CID, nil
} | go | func (nc *Conn) GetClientID() (uint64, error) {
nc.mu.RLock()
defer nc.mu.RUnlock()
if nc.isClosed() {
return 0, ErrConnectionClosed
}
if nc.info.CID == 0 {
return 0, ErrClientIDNotSupported
}
return nc.info.CID, nil
} | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"GetClientID",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"nc",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"nc",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"nc",
".",
"isClosed",
"(",
")... | // GetClientID returns the client ID assigned by the server to which
// the client is currently connected to. Note that the value may change if
// the client reconnects.
// This function returns ErrNoClientIDReturned if the server is of a
// version prior to 1.2.0. | [
"GetClientID",
"returns",
"the",
"client",
"ID",
"assigned",
"by",
"the",
"server",
"to",
"which",
"the",
"client",
"is",
"currently",
"connected",
"to",
".",
"Note",
"that",
"the",
"value",
"may",
"change",
"if",
"the",
"client",
"reconnects",
".",
"This",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3811-L3821 | train |
nats-io/go-nats | nats.go | NkeyOptionFromSeed | func NkeyOptionFromSeed(seedFile string) (Option, error) {
kp, err := nkeyPairFromSeedFile(seedFile)
if err != nil {
return nil, err
}
// Wipe our key on exit.
defer kp.Wipe()
pub, err := kp.PublicKey()
if err != nil {
return nil, err
}
if !nkeys.IsValidPublicUserKey(pub) {
return nil, fmt.Errorf("nats:... | go | func NkeyOptionFromSeed(seedFile string) (Option, error) {
kp, err := nkeyPairFromSeedFile(seedFile)
if err != nil {
return nil, err
}
// Wipe our key on exit.
defer kp.Wipe()
pub, err := kp.PublicKey()
if err != nil {
return nil, err
}
if !nkeys.IsValidPublicUserKey(pub) {
return nil, fmt.Errorf("nats:... | [
"func",
"NkeyOptionFromSeed",
"(",
"seedFile",
"string",
")",
"(",
"Option",
",",
"error",
")",
"{",
"kp",
",",
"err",
":=",
"nkeyPairFromSeedFile",
"(",
"seedFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n"... | // NkeyOptionFromSeed will load an nkey pair from a seed file.
// It will return the NKey Option and will handle
// signing of nonce challenges from the server. It will take
// care to not hold keys in memory and to wipe memory. | [
"NkeyOptionFromSeed",
"will",
"load",
"an",
"nkey",
"pair",
"from",
"a",
"seed",
"file",
".",
"It",
"will",
"return",
"the",
"NKey",
"Option",
"and",
"will",
"handle",
"signing",
"of",
"nonce",
"challenges",
"from",
"the",
"server",
".",
"It",
"will",
"tak... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3827-L3846 | train |
nats-io/go-nats | nats.go | sigHandler | func sigHandler(nonce []byte, seedFile string) ([]byte, error) {
kp, err := nkeyPairFromSeedFile(seedFile)
if err != nil {
return nil, err
}
// Wipe our key on exit.
defer kp.Wipe()
sig, _ := kp.Sign(nonce)
return sig, nil
} | go | func sigHandler(nonce []byte, seedFile string) ([]byte, error) {
kp, err := nkeyPairFromSeedFile(seedFile)
if err != nil {
return nil, err
}
// Wipe our key on exit.
defer kp.Wipe()
sig, _ := kp.Sign(nonce)
return sig, nil
} | [
"func",
"sigHandler",
"(",
"nonce",
"[",
"]",
"byte",
",",
"seedFile",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"kp",
",",
"err",
":=",
"nkeyPairFromSeedFile",
"(",
"seedFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // Sign authentication challenges from the server.
// Do not keep private seed in memory. | [
"Sign",
"authentication",
"challenges",
"from",
"the",
"server",
".",
"Do",
"not",
"keep",
"private",
"seed",
"in",
"memory",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/nats.go#L3916-L3926 | train |
nats-io/go-nats | util/tls.go | CloneTLSConfig | func CloneTLSConfig(c *tls.Config) *tls.Config {
if c == nil {
return &tls.Config{}
}
return c.Clone()
} | go | func CloneTLSConfig(c *tls.Config) *tls.Config {
if c == nil {
return &tls.Config{}
}
return c.Clone()
} | [
"func",
"CloneTLSConfig",
"(",
"c",
"*",
"tls",
".",
"Config",
")",
"*",
"tls",
".",
"Config",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"&",
"tls",
".",
"Config",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Clone",
"(",
")",
"\n",
"}"
... | // CloneTLSConfig returns a copy of c. | [
"CloneTLSConfig",
"returns",
"a",
"copy",
"of",
"c",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/util/tls.go#L21-L27 | train |
nats-io/go-nats | context.go | RequestWithContext | func (nc *Conn) RequestWithContext(ctx context.Context, subj string, data []byte) (*Msg, error) {
if ctx == nil {
return nil, ErrInvalidContext
}
if nc == nil {
return nil, ErrInvalidConnection
}
// Check whether the context is done already before making
// the request.
if ctx.Err() != nil {
return nil, ct... | go | func (nc *Conn) RequestWithContext(ctx context.Context, subj string, data []byte) (*Msg, error) {
if ctx == nil {
return nil, ErrInvalidContext
}
if nc == nil {
return nil, ErrInvalidConnection
}
// Check whether the context is done already before making
// the request.
if ctx.Err() != nil {
return nil, ct... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"RequestWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"subj",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Msg",
",",
"error",
")",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"nil",
... | // RequestWithContext takes a context, a subject and payload
// in bytes and request expecting a single response. | [
"RequestWithContext",
"takes",
"a",
"context",
"a",
"subject",
"and",
"payload",
"in",
"bytes",
"and",
"request",
"expecting",
"a",
"single",
"response",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/context.go#L26-L89 | train |
nats-io/go-nats | context.go | oldRequestWithContext | func (nc *Conn) oldRequestWithContext(ctx context.Context, subj string, data []byte) (*Msg, error) {
inbox := NewInbox()
ch := make(chan *Msg, RequestChanLen)
s, err := nc.subscribe(inbox, _EMPTY_, nil, ch, true)
if err != nil {
return nil, err
}
s.AutoUnsubscribe(1)
defer s.Unsubscribe()
err = nc.PublishRe... | go | func (nc *Conn) oldRequestWithContext(ctx context.Context, subj string, data []byte) (*Msg, error) {
inbox := NewInbox()
ch := make(chan *Msg, RequestChanLen)
s, err := nc.subscribe(inbox, _EMPTY_, nil, ch, true)
if err != nil {
return nil, err
}
s.AutoUnsubscribe(1)
defer s.Unsubscribe()
err = nc.PublishRe... | [
"func",
"(",
"nc",
"*",
"Conn",
")",
"oldRequestWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"subj",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Msg",
",",
"error",
")",
"{",
"inbox",
":=",
"NewInbox",
"(",
")",
"\n",
"ch"... | // oldRequestWithContext utilizes inbox and subscription per request. | [
"oldRequestWithContext",
"utilizes",
"inbox",
"and",
"subscription",
"per",
"request",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/context.go#L92-L109 | train |
nats-io/go-nats | context.go | NextMsgWithContext | func (s *Subscription) NextMsgWithContext(ctx context.Context) (*Msg, error) {
if ctx == nil {
return nil, ErrInvalidContext
}
if s == nil {
return nil, ErrBadSubscription
}
if ctx.Err() != nil {
return nil, ctx.Err()
}
s.mu.Lock()
err := s.validateNextMsgState()
if err != nil {
s.mu.Unlock()
return... | go | func (s *Subscription) NextMsgWithContext(ctx context.Context) (*Msg, error) {
if ctx == nil {
return nil, ErrInvalidContext
}
if s == nil {
return nil, ErrBadSubscription
}
if ctx.Err() != nil {
return nil, ctx.Err()
}
s.mu.Lock()
err := s.validateNextMsgState()
if err != nil {
s.mu.Unlock()
return... | [
"func",
"(",
"s",
"*",
"Subscription",
")",
"NextMsgWithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Msg",
",",
"error",
")",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrInvalidContext",
"\n",
"}",
"\n",
"if",
"s... | // NextMsgWithContext takes a context and returns the next message
// available to a synchronous subscriber, blocking until it is delivered
// or context gets canceled. | [
"NextMsgWithContext",
"takes",
"a",
"context",
"and",
"returns",
"the",
"next",
"message",
"available",
"to",
"a",
"synchronous",
"subscriber",
"blocking",
"until",
"it",
"is",
"delivered",
"or",
"context",
"gets",
"canceled",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/context.go#L114-L166 | train |
nats-io/go-nats | context.go | RequestWithContext | func (c *EncodedConn) RequestWithContext(ctx context.Context, subject string, v interface{}, vPtr interface{}) error {
if ctx == nil {
return ErrInvalidContext
}
b, err := c.Enc.Encode(subject, v)
if err != nil {
return err
}
m, err := c.Conn.RequestWithContext(ctx, subject, b)
if err != nil {
return err
... | go | func (c *EncodedConn) RequestWithContext(ctx context.Context, subject string, v interface{}, vPtr interface{}) error {
if ctx == nil {
return ErrInvalidContext
}
b, err := c.Enc.Encode(subject, v)
if err != nil {
return err
}
m, err := c.Conn.RequestWithContext(ctx, subject, b)
if err != nil {
return err
... | [
"func",
"(",
"c",
"*",
"EncodedConn",
")",
"RequestWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"subject",
"string",
",",
"v",
"interface",
"{",
"}",
",",
"vPtr",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"... | // RequestWithContext will create an Inbox and perform a Request
// using the provided cancellation context with the Inbox reply
// for the data v. A response will be decoded into the vPtrResponse. | [
"RequestWithContext",
"will",
"create",
"an",
"Inbox",
"and",
"perform",
"a",
"Request",
"using",
"the",
"provided",
"cancellation",
"context",
"with",
"the",
"Inbox",
"reply",
"for",
"the",
"data",
"v",
".",
"A",
"response",
"will",
"be",
"decoded",
"into",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/context.go#L217-L241 | train |
nats-io/go-nats | netchan.go | BindSendChan | func (c *EncodedConn) BindSendChan(subject string, channel interface{}) error {
chVal := reflect.ValueOf(channel)
if chVal.Kind() != reflect.Chan {
return ErrChanArg
}
go chPublish(c, chVal, subject)
return nil
} | go | func (c *EncodedConn) BindSendChan(subject string, channel interface{}) error {
chVal := reflect.ValueOf(channel)
if chVal.Kind() != reflect.Chan {
return ErrChanArg
}
go chPublish(c, chVal, subject)
return nil
} | [
"func",
"(",
"c",
"*",
"EncodedConn",
")",
"BindSendChan",
"(",
"subject",
"string",
",",
"channel",
"interface",
"{",
"}",
")",
"error",
"{",
"chVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"channel",
")",
"\n",
"if",
"chVal",
".",
"Kind",
"(",
")",
... | // This allows the functionality for network channels by binding send and receive Go chans
// to subjects and optionally queue groups.
// Data will be encoded and decoded via the EncodedConn and its associated encoders.
// BindSendChan binds a channel for send operations to NATS. | [
"This",
"allows",
"the",
"functionality",
"for",
"network",
"channels",
"by",
"binding",
"send",
"and",
"receive",
"Go",
"chans",
"to",
"subjects",
"and",
"optionally",
"queue",
"groups",
".",
"Data",
"will",
"be",
"encoded",
"and",
"decoded",
"via",
"the",
... | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/netchan.go#L26-L33 | train |
nats-io/go-nats | netchan.go | chPublish | func chPublish(c *EncodedConn, chVal reflect.Value, subject string) {
for {
val, ok := chVal.Recv()
if !ok {
// Channel has most likely been closed.
return
}
if e := c.Publish(subject, val.Interface()); e != nil {
// Do this under lock.
c.Conn.mu.Lock()
defer c.Conn.mu.Unlock()
if c.Conn.Opt... | go | func chPublish(c *EncodedConn, chVal reflect.Value, subject string) {
for {
val, ok := chVal.Recv()
if !ok {
// Channel has most likely been closed.
return
}
if e := c.Publish(subject, val.Interface()); e != nil {
// Do this under lock.
c.Conn.mu.Lock()
defer c.Conn.mu.Unlock()
if c.Conn.Opt... | [
"func",
"chPublish",
"(",
"c",
"*",
"EncodedConn",
",",
"chVal",
"reflect",
".",
"Value",
",",
"subject",
"string",
")",
"{",
"for",
"{",
"val",
",",
"ok",
":=",
"chVal",
".",
"Recv",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"// Channel has most likely be... | // Publish all values that arrive on the channel until it is closed or we
// encounter an error. | [
"Publish",
"all",
"values",
"that",
"arrive",
"on",
"the",
"channel",
"until",
"it",
"is",
"closed",
"or",
"we",
"encounter",
"an",
"error",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/netchan.go#L37-L61 | train |
nats-io/go-nats | netchan.go | BindRecvChan | func (c *EncodedConn) BindRecvChan(subject string, channel interface{}) (*Subscription, error) {
return c.bindRecvChan(subject, _EMPTY_, channel)
} | go | func (c *EncodedConn) BindRecvChan(subject string, channel interface{}) (*Subscription, error) {
return c.bindRecvChan(subject, _EMPTY_, channel)
} | [
"func",
"(",
"c",
"*",
"EncodedConn",
")",
"BindRecvChan",
"(",
"subject",
"string",
",",
"channel",
"interface",
"{",
"}",
")",
"(",
"*",
"Subscription",
",",
"error",
")",
"{",
"return",
"c",
".",
"bindRecvChan",
"(",
"subject",
",",
"_EMPTY_",
",",
... | // BindRecvChan binds a channel for receive operations from NATS. | [
"BindRecvChan",
"binds",
"a",
"channel",
"for",
"receive",
"operations",
"from",
"NATS",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/netchan.go#L64-L66 | train |
nats-io/go-nats | netchan.go | BindRecvQueueChan | func (c *EncodedConn) BindRecvQueueChan(subject, queue string, channel interface{}) (*Subscription, error) {
return c.bindRecvChan(subject, queue, channel)
} | go | func (c *EncodedConn) BindRecvQueueChan(subject, queue string, channel interface{}) (*Subscription, error) {
return c.bindRecvChan(subject, queue, channel)
} | [
"func",
"(",
"c",
"*",
"EncodedConn",
")",
"BindRecvQueueChan",
"(",
"subject",
",",
"queue",
"string",
",",
"channel",
"interface",
"{",
"}",
")",
"(",
"*",
"Subscription",
",",
"error",
")",
"{",
"return",
"c",
".",
"bindRecvChan",
"(",
"subject",
",",... | // BindRecvQueueChan binds a channel for queue-based receive operations from NATS. | [
"BindRecvQueueChan",
"binds",
"a",
"channel",
"for",
"queue",
"-",
"based",
"receive",
"operations",
"from",
"NATS",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/netchan.go#L69-L71 | train |
nats-io/go-nats | netchan.go | bindRecvChan | func (c *EncodedConn) bindRecvChan(subject, queue string, channel interface{}) (*Subscription, error) {
chVal := reflect.ValueOf(channel)
if chVal.Kind() != reflect.Chan {
return nil, ErrChanArg
}
argType := chVal.Type().Elem()
cb := func(m *Msg) {
var oPtr reflect.Value
if argType.Kind() != reflect.Ptr {
... | go | func (c *EncodedConn) bindRecvChan(subject, queue string, channel interface{}) (*Subscription, error) {
chVal := reflect.ValueOf(channel)
if chVal.Kind() != reflect.Chan {
return nil, ErrChanArg
}
argType := chVal.Type().Elem()
cb := func(m *Msg) {
var oPtr reflect.Value
if argType.Kind() != reflect.Ptr {
... | [
"func",
"(",
"c",
"*",
"EncodedConn",
")",
"bindRecvChan",
"(",
"subject",
",",
"queue",
"string",
",",
"channel",
"interface",
"{",
"}",
")",
"(",
"*",
"Subscription",
",",
"error",
")",
"{",
"chVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"channel",
"... | // Internal function to bind receive operations for a channel. | [
"Internal",
"function",
"to",
"bind",
"receive",
"operations",
"for",
"a",
"channel",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/netchan.go#L74-L111 | train |
nats-io/go-nats | examples/nats-echo/main.go | lookupGeo | func lookupGeo() string {
c := &http.Client{Timeout: 2 * time.Second}
resp, err := c.Get("https://ipinfo.io")
if err != nil || resp == nil {
log.Fatalf("Could not retrive geo location data: %v", err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
g := geo{}
if err := json.Unmarshal(body, &g); ... | go | func lookupGeo() string {
c := &http.Client{Timeout: 2 * time.Second}
resp, err := c.Get("https://ipinfo.io")
if err != nil || resp == nil {
log.Fatalf("Could not retrive geo location data: %v", err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
g := geo{}
if err := json.Unmarshal(body, &g); ... | [
"func",
"lookupGeo",
"(",
")",
"string",
"{",
"c",
":=",
"&",
"http",
".",
"Client",
"{",
"Timeout",
":",
"2",
"*",
"time",
".",
"Second",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"n... | // lookup our current region and country.. | [
"lookup",
"our",
"current",
"region",
"and",
"country",
".."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/examples/nats-echo/main.go#L153-L166 | train |
nats-io/go-nats | bench/bench.go | CSV | func (bm *Benchmark) CSV() string {
var buffer bytes.Buffer
writer := csv.NewWriter(&buffer)
headers := []string{"#RunID", "ClientID", "MsgCount", "MsgBytes", "MsgsPerSec", "BytesPerSec", "DurationSecs"}
if err := writer.Write(headers); err != nil {
log.Fatalf("Error while serializing headers %q: %v", headers, er... | go | func (bm *Benchmark) CSV() string {
var buffer bytes.Buffer
writer := csv.NewWriter(&buffer)
headers := []string{"#RunID", "ClientID", "MsgCount", "MsgBytes", "MsgsPerSec", "BytesPerSec", "DurationSecs"}
if err := writer.Write(headers); err != nil {
log.Fatalf("Error while serializing headers %q: %v", headers, er... | [
"func",
"(",
"bm",
"*",
"Benchmark",
")",
"CSV",
"(",
")",
"string",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"writer",
":=",
"csv",
".",
"NewWriter",
"(",
"&",
"buffer",
")",
"\n",
"headers",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
... | // CSV generates a csv report of all the samples collected | [
"CSV",
"generates",
"a",
"csv",
"report",
"of",
"all",
"the",
"samples",
"collected"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L120-L143 | train |
nats-io/go-nats | bench/bench.go | NewSample | func NewSample(jobCount int, msgSize int, start, end time.Time, nc *nats.Conn) *Sample {
s := Sample{JobMsgCnt: jobCount, Start: start, End: end}
s.MsgBytes = uint64(msgSize * jobCount)
s.MsgCnt = nc.OutMsgs + nc.InMsgs
s.IOBytes = nc.OutBytes + nc.InBytes
return &s
} | go | func NewSample(jobCount int, msgSize int, start, end time.Time, nc *nats.Conn) *Sample {
s := Sample{JobMsgCnt: jobCount, Start: start, End: end}
s.MsgBytes = uint64(msgSize * jobCount)
s.MsgCnt = nc.OutMsgs + nc.InMsgs
s.IOBytes = nc.OutBytes + nc.InBytes
return &s
} | [
"func",
"NewSample",
"(",
"jobCount",
"int",
",",
"msgSize",
"int",
",",
"start",
",",
"end",
"time",
".",
"Time",
",",
"nc",
"*",
"nats",
".",
"Conn",
")",
"*",
"Sample",
"{",
"s",
":=",
"Sample",
"{",
"JobMsgCnt",
":",
"jobCount",
",",
"Start",
"... | // NewSample creates a new Sample initialized to the provided values. The nats.Conn information captured | [
"NewSample",
"creates",
"a",
"new",
"Sample",
"initialized",
"to",
"the",
"provided",
"values",
".",
"The",
"nats",
".",
"Conn",
"information",
"captured"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L146-L152 | train |
nats-io/go-nats | bench/bench.go | Throughput | func (s *Sample) Throughput() float64 {
return float64(s.MsgBytes) / s.Duration().Seconds()
} | go | func (s *Sample) Throughput() float64 {
return float64(s.MsgBytes) / s.Duration().Seconds()
} | [
"func",
"(",
"s",
"*",
"Sample",
")",
"Throughput",
"(",
")",
"float64",
"{",
"return",
"float64",
"(",
"s",
".",
"MsgBytes",
")",
"/",
"s",
".",
"Duration",
"(",
")",
".",
"Seconds",
"(",
")",
"\n",
"}"
] | // Throughput of bytes per second | [
"Throughput",
"of",
"bytes",
"per",
"second"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L155-L157 | train |
nats-io/go-nats | bench/bench.go | Rate | func (s *Sample) Rate() int64 {
return int64(float64(s.JobMsgCnt) / s.Duration().Seconds())
} | go | func (s *Sample) Rate() int64 {
return int64(float64(s.JobMsgCnt) / s.Duration().Seconds())
} | [
"func",
"(",
"s",
"*",
"Sample",
")",
"Rate",
"(",
")",
"int64",
"{",
"return",
"int64",
"(",
"float64",
"(",
"s",
".",
"JobMsgCnt",
")",
"/",
"s",
".",
"Duration",
"(",
")",
".",
"Seconds",
"(",
")",
")",
"\n",
"}"
] | // Rate of meessages in the job per second | [
"Rate",
"of",
"meessages",
"in",
"the",
"job",
"per",
"second"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L160-L162 | train |
nats-io/go-nats | bench/bench.go | Duration | func (s *Sample) Duration() time.Duration {
return s.End.Sub(s.Start)
} | go | func (s *Sample) Duration() time.Duration {
return s.End.Sub(s.Start)
} | [
"func",
"(",
"s",
"*",
"Sample",
")",
"Duration",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"s",
".",
"End",
".",
"Sub",
"(",
"s",
".",
"Start",
")",
"\n",
"}"
] | // Duration that the sample was active | [
"Duration",
"that",
"the",
"sample",
"was",
"active"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L171-L173 | train |
nats-io/go-nats | bench/bench.go | MinRate | func (sg *SampleGroup) MinRate() int64 {
m := int64(0)
for i, s := range sg.Samples {
if i == 0 {
m = s.Rate()
}
m = min(m, s.Rate())
}
return m
} | go | func (sg *SampleGroup) MinRate() int64 {
m := int64(0)
for i, s := range sg.Samples {
if i == 0 {
m = s.Rate()
}
m = min(m, s.Rate())
}
return m
} | [
"func",
"(",
"sg",
"*",
"SampleGroup",
")",
"MinRate",
"(",
")",
"int64",
"{",
"m",
":=",
"int64",
"(",
"0",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"sg",
".",
"Samples",
"{",
"if",
"i",
"==",
"0",
"{",
"m",
"=",
"s",
".",
"Rate",
"... | // MinRate returns the smallest message rate in the SampleGroup | [
"MinRate",
"returns",
"the",
"smallest",
"message",
"rate",
"in",
"the",
"SampleGroup"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L193-L202 | train |
nats-io/go-nats | bench/bench.go | MaxRate | func (sg *SampleGroup) MaxRate() int64 {
m := int64(0)
for i, s := range sg.Samples {
if i == 0 {
m = s.Rate()
}
m = max(m, s.Rate())
}
return m
} | go | func (sg *SampleGroup) MaxRate() int64 {
m := int64(0)
for i, s := range sg.Samples {
if i == 0 {
m = s.Rate()
}
m = max(m, s.Rate())
}
return m
} | [
"func",
"(",
"sg",
"*",
"SampleGroup",
")",
"MaxRate",
"(",
")",
"int64",
"{",
"m",
":=",
"int64",
"(",
"0",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"sg",
".",
"Samples",
"{",
"if",
"i",
"==",
"0",
"{",
"m",
"=",
"s",
".",
"Rate",
"... | // MaxRate returns the largest message rate in the SampleGroup | [
"MaxRate",
"returns",
"the",
"largest",
"message",
"rate",
"in",
"the",
"SampleGroup"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L205-L214 | train |
nats-io/go-nats | bench/bench.go | AvgRate | func (sg *SampleGroup) AvgRate() int64 {
sum := uint64(0)
for _, s := range sg.Samples {
sum += uint64(s.Rate())
}
return int64(sum / uint64(len(sg.Samples)))
} | go | func (sg *SampleGroup) AvgRate() int64 {
sum := uint64(0)
for _, s := range sg.Samples {
sum += uint64(s.Rate())
}
return int64(sum / uint64(len(sg.Samples)))
} | [
"func",
"(",
"sg",
"*",
"SampleGroup",
")",
"AvgRate",
"(",
")",
"int64",
"{",
"sum",
":=",
"uint64",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"sg",
".",
"Samples",
"{",
"sum",
"+=",
"uint64",
"(",
"s",
".",
"Rate",
"(",
")",
... | // AvgRate returns the average of all the message rates in the SampleGroup | [
"AvgRate",
"returns",
"the",
"average",
"of",
"all",
"the",
"message",
"rates",
"in",
"the",
"SampleGroup"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L217-L223 | train |
nats-io/go-nats | bench/bench.go | StdDev | func (sg *SampleGroup) StdDev() float64 {
avg := float64(sg.AvgRate())
sum := float64(0)
for _, c := range sg.Samples {
sum += math.Pow(float64(c.Rate())-avg, 2)
}
variance := sum / float64(len(sg.Samples))
return math.Sqrt(variance)
} | go | func (sg *SampleGroup) StdDev() float64 {
avg := float64(sg.AvgRate())
sum := float64(0)
for _, c := range sg.Samples {
sum += math.Pow(float64(c.Rate())-avg, 2)
}
variance := sum / float64(len(sg.Samples))
return math.Sqrt(variance)
} | [
"func",
"(",
"sg",
"*",
"SampleGroup",
")",
"StdDev",
"(",
")",
"float64",
"{",
"avg",
":=",
"float64",
"(",
"sg",
".",
"AvgRate",
"(",
")",
")",
"\n",
"sum",
":=",
"float64",
"(",
"0",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"sg",
".",... | // StdDev returns the standard deviation the message rates in the SampleGroup | [
"StdDev",
"returns",
"the",
"standard",
"deviation",
"the",
"message",
"rates",
"in",
"the",
"SampleGroup"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L226-L234 | train |
nats-io/go-nats | bench/bench.go | AddSample | func (sg *SampleGroup) AddSample(e *Sample) {
sg.Samples = append(sg.Samples, e)
if len(sg.Samples) == 1 {
sg.Start = e.Start
sg.End = e.End
}
sg.IOBytes += e.IOBytes
sg.JobMsgCnt += e.JobMsgCnt
sg.MsgCnt += e.MsgCnt
sg.MsgBytes += e.MsgBytes
if e.Start.Before(sg.Start) {
sg.Start = e.Start
}
if e.En... | go | func (sg *SampleGroup) AddSample(e *Sample) {
sg.Samples = append(sg.Samples, e)
if len(sg.Samples) == 1 {
sg.Start = e.Start
sg.End = e.End
}
sg.IOBytes += e.IOBytes
sg.JobMsgCnt += e.JobMsgCnt
sg.MsgCnt += e.MsgCnt
sg.MsgBytes += e.MsgBytes
if e.Start.Before(sg.Start) {
sg.Start = e.Start
}
if e.En... | [
"func",
"(",
"sg",
"*",
"SampleGroup",
")",
"AddSample",
"(",
"e",
"*",
"Sample",
")",
"{",
"sg",
".",
"Samples",
"=",
"append",
"(",
"sg",
".",
"Samples",
",",
"e",
")",
"\n\n",
"if",
"len",
"(",
"sg",
".",
"Samples",
")",
"==",
"1",
"{",
"sg"... | // AddSample adds a Sample to the SampleGroup. After adding a Sample it shouldn't be modified. | [
"AddSample",
"adds",
"a",
"Sample",
"to",
"the",
"SampleGroup",
".",
"After",
"adding",
"a",
"Sample",
"it",
"shouldn",
"t",
"be",
"modified",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L237-L256 | train |
nats-io/go-nats | bench/bench.go | Report | func (bm *Benchmark) Report() string {
var buffer bytes.Buffer
indent := ""
if !bm.Pubs.HasSamples() && !bm.Subs.HasSamples() {
return "No publisher or subscribers. Nothing to report."
}
if bm.Pubs.HasSamples() && bm.Subs.HasSamples() {
buffer.WriteString(fmt.Sprintf("%s Pub/Sub stats: %s\n", bm.Name, bm))
... | go | func (bm *Benchmark) Report() string {
var buffer bytes.Buffer
indent := ""
if !bm.Pubs.HasSamples() && !bm.Subs.HasSamples() {
return "No publisher or subscribers. Nothing to report."
}
if bm.Pubs.HasSamples() && bm.Subs.HasSamples() {
buffer.WriteString(fmt.Sprintf("%s Pub/Sub stats: %s\n", bm.Name, bm))
... | [
"func",
"(",
"bm",
"*",
"Benchmark",
")",
"Report",
"(",
")",
"string",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"indent",
":=",
"\"",
"\"",
"\n",
"if",
"!",
"bm",
".",
"Pubs",
".",
"HasSamples",
"(",
")",
"&&",
"!",
"bm",
".",
"Subs... | // Report returns a human readable report of the samples taken in the Benchmark | [
"Report",
"returns",
"a",
"human",
"readable",
"report",
"of",
"the",
"samples",
"taken",
"in",
"the",
"Benchmark"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L264-L296 | train |
nats-io/go-nats | bench/bench.go | HumanBytes | func HumanBytes(bytes float64, si bool) string {
var base = 1024
pre := []string{"K", "M", "G", "T", "P", "E"}
var post = "B"
if si {
base = 1000
pre = []string{"k", "M", "G", "T", "P", "E"}
post = "iB"
}
if bytes < float64(base) {
return fmt.Sprintf("%.2f B", bytes)
}
exp := int(math.Log(bytes) / math.... | go | func HumanBytes(bytes float64, si bool) string {
var base = 1024
pre := []string{"K", "M", "G", "T", "P", "E"}
var post = "B"
if si {
base = 1000
pre = []string{"k", "M", "G", "T", "P", "E"}
post = "iB"
}
if bytes < float64(base) {
return fmt.Sprintf("%.2f B", bytes)
}
exp := int(math.Log(bytes) / math.... | [
"func",
"HumanBytes",
"(",
"bytes",
"float64",
",",
"si",
"bool",
")",
"string",
"{",
"var",
"base",
"=",
"1024",
"\n",
"pre",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
... | // HumanBytes formats bytes as a human readable string | [
"HumanBytes",
"formats",
"bytes",
"as",
"a",
"human",
"readable",
"string"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L317-L333 | train |
nats-io/go-nats | bench/bench.go | MsgsPerClient | func MsgsPerClient(numMsgs, numClients int) []int {
var counts []int
if numClients == 0 || numMsgs == 0 {
return counts
}
counts = make([]int, numClients)
mc := numMsgs / numClients
for i := 0; i < numClients; i++ {
counts[i] = mc
}
extra := numMsgs % numClients
for i := 0; i < extra; i++ {
counts[i]++
... | go | func MsgsPerClient(numMsgs, numClients int) []int {
var counts []int
if numClients == 0 || numMsgs == 0 {
return counts
}
counts = make([]int, numClients)
mc := numMsgs / numClients
for i := 0; i < numClients; i++ {
counts[i] = mc
}
extra := numMsgs % numClients
for i := 0; i < extra; i++ {
counts[i]++
... | [
"func",
"MsgsPerClient",
"(",
"numMsgs",
",",
"numClients",
"int",
")",
"[",
"]",
"int",
"{",
"var",
"counts",
"[",
"]",
"int",
"\n",
"if",
"numClients",
"==",
"0",
"||",
"numMsgs",
"==",
"0",
"{",
"return",
"counts",
"\n",
"}",
"\n",
"counts",
"=",
... | // MsgsPerClient divides the number of messages by the number of clients and tries to distribute them as evenly as possible | [
"MsgsPerClient",
"divides",
"the",
"number",
"of",
"messages",
"by",
"the",
"number",
"of",
"clients",
"and",
"tries",
"to",
"distribute",
"them",
"as",
"evenly",
"as",
"possible"
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/bench/bench.go#L350-L365 | train |
nats-io/go-nats | timer.go | Get | func (tp *timerPool) Get(d time.Duration) *time.Timer {
if t, _ := tp.p.Get().(*time.Timer); t != nil {
t.Reset(d)
return t
}
return time.NewTimer(d)
} | go | func (tp *timerPool) Get(d time.Duration) *time.Timer {
if t, _ := tp.p.Get().(*time.Timer); t != nil {
t.Reset(d)
return t
}
return time.NewTimer(d)
} | [
"func",
"(",
"tp",
"*",
"timerPool",
")",
"Get",
"(",
"d",
"time",
".",
"Duration",
")",
"*",
"time",
".",
"Timer",
"{",
"if",
"t",
",",
"_",
":=",
"tp",
".",
"p",
".",
"Get",
"(",
")",
".",
"(",
"*",
"time",
".",
"Timer",
")",
";",
"t",
... | // Get returns a timer that completes after the given duration. | [
"Get",
"returns",
"a",
"timer",
"that",
"completes",
"after",
"the",
"given",
"duration",
"."
] | 36d30b0ba7aa260ae25b4f3d312b2a700106fd78 | https://github.com/nats-io/go-nats/blob/36d30b0ba7aa260ae25b4f3d312b2a700106fd78/timer.go#L31-L38 | train |
securego/gosec | rules/blacklist.go | NewBlacklistedImports | func NewBlacklistedImports(id string, conf gosec.Config, blacklist map[string]string) (gosec.Rule, []ast.Node) {
return &blacklistedImport{
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.High,
},
Blacklisted: blacklist,
}, []ast.Node{(*ast.ImportSpec)(nil)}
} | go | func NewBlacklistedImports(id string, conf gosec.Config, blacklist map[string]string) (gosec.Rule, []ast.Node) {
return &blacklistedImport{
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.High,
},
Blacklisted: blacklist,
}, []ast.Node{(*ast.ImportSpec)(nil)}
} | [
"func",
"NewBlacklistedImports",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
",",
"blacklist",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"return",
"&",
"blacklistedIm... | // NewBlacklistedImports reports when a blacklisted import is being used.
// Typically when a deprecated technology is being used. | [
"NewBlacklistedImports",
"reports",
"when",
"a",
"blacklisted",
"import",
"is",
"being",
"used",
".",
"Typically",
"when",
"a",
"deprecated",
"technology",
"is",
"being",
"used",
"."
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/blacklist.go#L50-L59 | train |
securego/gosec | rules/blacklist.go | NewBlacklistedImportRC4 | func NewBlacklistedImportRC4(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
return NewBlacklistedImports(id, conf, map[string]string{
"crypto/rc4": "Blacklisted import crypto/rc4: weak cryptographic primitive",
})
} | go | func NewBlacklistedImportRC4(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
return NewBlacklistedImports(id, conf, map[string]string{
"crypto/rc4": "Blacklisted import crypto/rc4: weak cryptographic primitive",
})
} | [
"func",
"NewBlacklistedImportRC4",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"return",
"NewBlacklistedImports",
"(",
"id",
",",
"conf",
",",
"map",
"[",
"strin... | // NewBlacklistedImportRC4 fails if DES is imported | [
"NewBlacklistedImportRC4",
"fails",
"if",
"DES",
"is",
"imported"
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/blacklist.go#L76-L80 | train |
securego/gosec | rules/hardcoded_credentials.go | NewHardcodedCredentials | func NewHardcodedCredentials(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
pattern := `(?i)passwd|pass|password|pwd|secret|token`
entropyThreshold := 80.0
perCharThreshold := 3.0
ignoreEntropy := false
var truncateString = 16
if val, ok := conf["G101"]; ok {
conf := val.(map[string]string)
if confi... | go | func NewHardcodedCredentials(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
pattern := `(?i)passwd|pass|password|pwd|secret|token`
entropyThreshold := 80.0
perCharThreshold := 3.0
ignoreEntropy := false
var truncateString = 16
if val, ok := conf["G101"]; ok {
conf := val.(map[string]string)
if confi... | [
"func",
"NewHardcodedCredentials",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"pattern",
":=",
"`(?i)passwd|pass|password|pwd|secret|token`",
"\n",
"entropyThreshold",
... | // NewHardcodedCredentials attempts to find high entropy string constants being
// assigned to variables that appear to be related to credentials. | [
"NewHardcodedCredentials",
"attempts",
"to",
"find",
"high",
"entropy",
"string",
"constants",
"being",
"assigned",
"to",
"variables",
"that",
"appear",
"to",
"be",
"related",
"to",
"credentials",
"."
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/hardcoded_credentials.go#L101-L147 | train |
securego/gosec | rules/bind.go | NewBindsToAllNetworkInterfaces | func NewBindsToAllNetworkInterfaces(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
calls := gosec.NewCallList()
calls.Add("net", "Listen")
calls.Add("crypto/tls", "Listen")
return &bindsToAllNetworkInterfaces{
calls: calls,
pattern: regexp.MustCompile(`^(0.0.0.0|:).*$`),
MetaData: gosec.MetaData{
... | go | func NewBindsToAllNetworkInterfaces(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
calls := gosec.NewCallList()
calls.Add("net", "Listen")
calls.Add("crypto/tls", "Listen")
return &bindsToAllNetworkInterfaces{
calls: calls,
pattern: regexp.MustCompile(`^(0.0.0.0|:).*$`),
MetaData: gosec.MetaData{
... | [
"func",
"NewBindsToAllNetworkInterfaces",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"calls",
":=",
"gosec",
".",
"NewCallList",
"(",
")",
"\n",
"calls",
".",
... | // NewBindsToAllNetworkInterfaces detects socket connections that are setup to
// listen on all network interfaces. | [
"NewBindsToAllNetworkInterfaces",
"detects",
"socket",
"connections",
"that",
"are",
"setup",
"to",
"listen",
"on",
"all",
"network",
"interfaces",
"."
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/bind.go#L69-L83 | train |
securego/gosec | rules/fileperms.go | NewFilePerms | func NewFilePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
mode := getConfiguredMode(conf, "G302", 0600)
return &filePermissions{
mode: mode,
pkg: "os",
calls: []string{"OpenFile", "Chmod"},
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.High,... | go | func NewFilePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
mode := getConfiguredMode(conf, "G302", 0600)
return &filePermissions{
mode: mode,
pkg: "os",
calls: []string{"OpenFile", "Chmod"},
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.High,... | [
"func",
"NewFilePerms",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"mode",
":=",
"getConfiguredMode",
"(",
"conf",
",",
"\"",
"\"",
",",
"0600",
")",
"\n",
... | // NewFilePerms creates a rule to detect file creation with a more permissive than configured
// permission mask. | [
"NewFilePerms",
"creates",
"a",
"rule",
"to",
"detect",
"file",
"creation",
"with",
"a",
"more",
"permissive",
"than",
"configured",
"permission",
"mask",
"."
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/fileperms.go#L65-L78 | train |
securego/gosec | rules/rsa.go | NewWeakKeyStrength | func NewWeakKeyStrength(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
calls := gosec.NewCallList()
calls.Add("crypto/rsa", "GenerateKey")
bits := 2048
return &weakKeyStrength{
calls: calls,
bits: bits,
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.H... | go | func NewWeakKeyStrength(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
calls := gosec.NewCallList()
calls.Add("crypto/rsa", "GenerateKey")
bits := 2048
return &weakKeyStrength{
calls: calls,
bits: bits,
MetaData: gosec.MetaData{
ID: id,
Severity: gosec.Medium,
Confidence: gosec.H... | [
"func",
"NewWeakKeyStrength",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"calls",
":=",
"gosec",
".",
"NewCallList",
"(",
")",
"\n",
"calls",
".",
"Add",
"(... | // NewWeakKeyStrength builds a rule that detects RSA keys < 2048 bits | [
"NewWeakKeyStrength",
"builds",
"a",
"rule",
"that",
"detects",
"RSA",
"keys",
"<",
"2048",
"bits"
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/rsa.go#L44-L58 | train |
securego/gosec | rules/subproc.go | NewSubproc | func NewSubproc(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
rule := &subprocess{gosec.MetaData{ID: id}, gosec.NewCallList()}
rule.Add("os/exec", "Command")
rule.Add("os/exec", "CommandContext")
rule.Add("syscall", "Exec")
return rule, []ast.Node{(*ast.CallExpr)(nil)}
} | go | func NewSubproc(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
rule := &subprocess{gosec.MetaData{ID: id}, gosec.NewCallList()}
rule.Add("os/exec", "Command")
rule.Add("os/exec", "CommandContext")
rule.Add("syscall", "Exec")
return rule, []ast.Node{(*ast.CallExpr)(nil)}
} | [
"func",
"NewSubproc",
"(",
"id",
"string",
",",
"conf",
"gosec",
".",
"Config",
")",
"(",
"gosec",
".",
"Rule",
",",
"[",
"]",
"ast",
".",
"Node",
")",
"{",
"rule",
":=",
"&",
"subprocess",
"{",
"gosec",
".",
"MetaData",
"{",
"ID",
":",
"id",
"}"... | // NewSubproc detects cases where we are forking out to an external process | [
"NewSubproc",
"detects",
"cases",
"where",
"we",
"are",
"forking",
"out",
"to",
"an",
"external",
"process"
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/subproc.go#L58-L64 | train |
securego/gosec | rules/archive.go | Match | func (a *archive) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
if node := a.calls.ContainsCallExpr(n, c, false); node != nil {
for _, arg := range node.Args {
var argType types.Type
if selector, ok := arg.(*ast.SelectorExpr); ok {
argType = c.Info.TypeOf(selector.X)
} else if ident, ok :=... | go | func (a *archive) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
if node := a.calls.ContainsCallExpr(n, c, false); node != nil {
for _, arg := range node.Args {
var argType types.Type
if selector, ok := arg.(*ast.SelectorExpr); ok {
argType = c.Info.TypeOf(selector.X)
} else if ident, ok :=... | [
"func",
"(",
"a",
"*",
"archive",
")",
"Match",
"(",
"n",
"ast",
".",
"Node",
",",
"c",
"*",
"gosec",
".",
"Context",
")",
"(",
"*",
"gosec",
".",
"Issue",
",",
"error",
")",
"{",
"if",
"node",
":=",
"a",
".",
"calls",
".",
"ContainsCallExpr",
... | // Match inspects AST nodes to determine if the filepath.Joins uses any argument derived from type zip.File | [
"Match",
"inspects",
"AST",
"nodes",
"to",
"determine",
"if",
"the",
"filepath",
".",
"Joins",
"uses",
"any",
"argument",
"derived",
"from",
"type",
"zip",
".",
"File"
] | 29cec138dcc94f347e6d41550a5223571dc7d6cf | https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/archive.go#L21-L44 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.