id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
24,500
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
24,501
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
24,502
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
24,503
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
24,504
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
24,505
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
24,506
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
24,507
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
24,508
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
24,509
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
24,510
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
24,511
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
24,512
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
24,513
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
24,514
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
24,515
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
24,516
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
24,517
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
24,518
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
24,519
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
24,520
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
24,521
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
24,522
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
24,523
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
24,524
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
24,525
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
24,526
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
24,527
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
24,528
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
24,529
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
24,530
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
24,531
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
24,532
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
24,533
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
24,534
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
24,535
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
24,536
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
24,537
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
24,538
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
24,539
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
24,540
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
24,541
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
24,542
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
24,543
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
24,544
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
24,545
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
24,546
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
24,547
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
24,548
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
24,549
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
24,550
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
24,551
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
24,552
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
24,553
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
24,554
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
24,555
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
24,556
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
24,557
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
24,558
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
24,559
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
24,560
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
24,561
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
24,562
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
24,563
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
24,564
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
24,565
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
24,566
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
24,567
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
24,568
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
24,569
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
24,570
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
24,571
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
24,572
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
24,573
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
24,574
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
24,575
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
24,576
securego/gosec
rules/archive.go
NewArchive
func NewArchive(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("path/filepath", "Join") return &archive{ calls: calls, argType: "*archive/zip.File", MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: ...
go
func NewArchive(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("path/filepath", "Join") return &archive{ calls: calls, argType: "*archive/zip.File", MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: ...
[ "func", "NewArchive", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "calls", ":=", "gosec", ".", "NewCallList", "(", ")", "\n", "calls", ".", "Add", "(", "\"...
// NewArchive creates a new rule which detects the file traversal when extracting zip archives
[ "NewArchive", "creates", "a", "new", "rule", "which", "detects", "the", "file", "traversal", "when", "extracting", "zip", "archives" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/archive.go#L47-L60
24,577
securego/gosec
call_list.go
AddAll
func (c CallList) AddAll(selector string, idents ...string) { for _, ident := range idents { c.Add(selector, ident) } }
go
func (c CallList) AddAll(selector string, idents ...string) { for _, ident := range idents { c.Add(selector, ident) } }
[ "func", "(", "c", "CallList", ")", "AddAll", "(", "selector", "string", ",", "idents", "...", "string", ")", "{", "for", "_", ",", "ident", ":=", "range", "idents", "{", "c", ".", "Add", "(", "selector", ",", "ident", ")", "\n", "}", "\n", "}" ]
// AddAll will add several calls to the call list at once
[ "AddAll", "will", "add", "several", "calls", "to", "the", "call", "list", "at", "once" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/call_list.go#L35-L39
24,578
securego/gosec
call_list.go
Add
func (c CallList) Add(selector, ident string) { if _, ok := c[selector]; !ok { c[selector] = make(set) } c[selector][ident] = true }
go
func (c CallList) Add(selector, ident string) { if _, ok := c[selector]; !ok { c[selector] = make(set) } c[selector][ident] = true }
[ "func", "(", "c", "CallList", ")", "Add", "(", "selector", ",", "ident", "string", ")", "{", "if", "_", ",", "ok", ":=", "c", "[", "selector", "]", ";", "!", "ok", "{", "c", "[", "selector", "]", "=", "make", "(", "set", ")", "\n", "}", "\n",...
// Add a selector and call to the call list
[ "Add", "a", "selector", "and", "call", "to", "the", "call", "list" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/call_list.go#L42-L47
24,579
securego/gosec
helpers.go
MatchCompLit
func MatchCompLit(n ast.Node, ctx *Context, required string) *ast.CompositeLit { if complit, ok := n.(*ast.CompositeLit); ok { typeOf := ctx.Info.TypeOf(complit) if typeOf.String() == required { return complit } } return nil }
go
func MatchCompLit(n ast.Node, ctx *Context, required string) *ast.CompositeLit { if complit, ok := n.(*ast.CompositeLit); ok { typeOf := ctx.Info.TypeOf(complit) if typeOf.String() == required { return complit } } return nil }
[ "func", "MatchCompLit", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ",", "required", "string", ")", "*", "ast", ".", "CompositeLit", "{", "if", "complit", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "CompositeLit", ")", ";", "ok"...
// MatchCompLit will match an ast.CompositeLit based on the supplied type
[ "MatchCompLit", "will", "match", "an", "ast", ".", "CompositeLit", "based", "on", "the", "supplied", "type" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L86-L94
24,580
securego/gosec
helpers.go
GetInt
func GetInt(n ast.Node) (int64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.INT { return strconv.ParseInt(node.Value, 0, 64) } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetInt(n ast.Node) (int64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.INT { return strconv.ParseInt(node.Value, 0, 64) } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetInt", "(", "n", "ast", ".", "Node", ")", "(", "int64", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "INT", "{", ...
// GetInt will read and return an integer value from an ast.BasicLit
[ "GetInt", "will", "read", "and", "return", "an", "integer", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L97-L102
24,581
securego/gosec
helpers.go
GetFloat
func GetFloat(n ast.Node) (float64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.FLOAT { return strconv.ParseFloat(node.Value, 64) } return 0.0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetFloat(n ast.Node) (float64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.FLOAT { return strconv.ParseFloat(node.Value, 64) } return 0.0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetFloat", "(", "n", "ast", ".", "Node", ")", "(", "float64", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "FLOAT", ...
// GetFloat will read and return a float value from an ast.BasicLit
[ "GetFloat", "will", "read", "and", "return", "a", "float", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L105-L110
24,582
securego/gosec
helpers.go
GetChar
func GetChar(n ast.Node) (byte, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.CHAR { return node.Value[0], nil } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetChar(n ast.Node) (byte, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.CHAR { return node.Value[0], nil } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetChar", "(", "n", "ast", ".", "Node", ")", "(", "byte", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "CHAR", "{", ...
// GetChar will read and return a char value from an ast.BasicLit
[ "GetChar", "will", "read", "and", "return", "a", "char", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L113-L118
24,583
securego/gosec
helpers.go
GetString
func GetString(n ast.Node) (string, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.STRING { return strconv.Unquote(node.Value) } return "", fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetString(n ast.Node) (string, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.STRING { return strconv.Unquote(node.Value) } return "", fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetString", "(", "n", "ast", ".", "Node", ")", "(", "string", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "STRING", ...
// GetString will read and return a string value from an ast.BasicLit
[ "GetString", "will", "read", "and", "return", "a", "string", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L121-L126
24,584
securego/gosec
helpers.go
GetCallObject
func GetCallObject(n ast.Node, ctx *Context) (*ast.CallExpr, types.Object) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.Ident: return node, ctx.Info.Uses[fn] case *ast.SelectorExpr: return node, ctx.Info.Uses[fn.Sel] } } return nil, nil }
go
func GetCallObject(n ast.Node, ctx *Context) (*ast.CallExpr, types.Object) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.Ident: return node, ctx.Info.Uses[fn] case *ast.SelectorExpr: return node, ctx.Info.Uses[fn.Sel] } } return nil, nil }
[ "func", "GetCallObject", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "*", "ast", ".", "CallExpr", ",", "types", ".", "Object", ")", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "...
// GetCallObject returns the object and call expression and associated // object for a given AST node. nil, nil will be returned if the // object cannot be resolved.
[ "GetCallObject", "returns", "the", "object", "and", "call", "expression", "and", "associated", "object", "for", "a", "given", "AST", "node", ".", "nil", "nil", "will", "be", "returned", "if", "the", "object", "cannot", "be", "resolved", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L131-L142
24,585
securego/gosec
helpers.go
GetCallInfo
func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.SelectorExpr: switch expr := fn.X.(type) { case *ast.Ident: if expr.Obj != nil && expr.Obj.Kind == ast.Var { t := ctx.Info.TypeOf(expr) if...
go
func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.SelectorExpr: switch expr := fn.X.(type) { case *ast.Ident: if expr.Obj != nil && expr.Obj.Kind == ast.Var { t := ctx.Info.TypeOf(expr) if...
[ "func", "GetCallInfo", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "string", ",", "string", ",", "error", ")", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "CallExpr", ":", "switch...
// GetCallInfo returns the package or type and name associated with a // call expression.
[ "GetCallInfo", "returns", "the", "package", "or", "type", "and", "name", "associated", "with", "a", "call", "expression", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L146-L167
24,586
securego/gosec
helpers.go
GetCallStringArgsValues
func GetCallStringArgsValues(n ast.Node, ctx *Context) []string { values := []string{} switch node := n.(type) { case *ast.CallExpr: for _, arg := range node.Args { switch param := arg.(type) { case *ast.BasicLit: value, err := GetString(param) if err == nil { values = append(values, value) ...
go
func GetCallStringArgsValues(n ast.Node, ctx *Context) []string { values := []string{} switch node := n.(type) { case *ast.CallExpr: for _, arg := range node.Args { switch param := arg.(type) { case *ast.BasicLit: value, err := GetString(param) if err == nil { values = append(values, value) ...
[ "func", "GetCallStringArgsValues", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "[", "]", "string", "{", "values", ":=", "[", "]", "string", "{", "}", "\n", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "...
// GetCallStringArgsValues returns the values of strings arguments if they can be resolved
[ "GetCallStringArgsValues", "returns", "the", "values", "of", "strings", "arguments", "if", "they", "can", "be", "resolved" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L170-L187
24,587
securego/gosec
helpers.go
GetIdentStringValues
func GetIdentStringValues(ident *ast.Ident) []string { values := []string{} obj := ident.Obj if obj != nil { switch decl := obj.Decl.(type) { case *ast.ValueSpec: for _, v := range decl.Values { value, err := GetString(v) if err == nil { values = append(values, value) } } case *ast.Assig...
go
func GetIdentStringValues(ident *ast.Ident) []string { values := []string{} obj := ident.Obj if obj != nil { switch decl := obj.Decl.(type) { case *ast.ValueSpec: for _, v := range decl.Values { value, err := GetString(v) if err == nil { values = append(values, value) } } case *ast.Assig...
[ "func", "GetIdentStringValues", "(", "ident", "*", "ast", ".", "Ident", ")", "[", "]", "string", "{", "values", ":=", "[", "]", "string", "{", "}", "\n", "obj", ":=", "ident", ".", "Obj", "\n", "if", "obj", "!=", "nil", "{", "switch", "decl", ":=",...
// GetIdentStringValues return the string values of an Ident if they can be resolved
[ "GetIdentStringValues", "return", "the", "string", "values", "of", "an", "Ident", "if", "they", "can", "be", "resolved" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L190-L213
24,588
securego/gosec
helpers.go
GetImportedName
func GetImportedName(path string, ctx *Context) (string, bool) { importName, imported := ctx.Imports.Imported[path] if !imported { return "", false } if _, initonly := ctx.Imports.InitOnly[path]; initonly { return "", false } if alias, ok := ctx.Imports.Aliased[path]; ok { importName = alias } return im...
go
func GetImportedName(path string, ctx *Context) (string, bool) { importName, imported := ctx.Imports.Imported[path] if !imported { return "", false } if _, initonly := ctx.Imports.InitOnly[path]; initonly { return "", false } if alias, ok := ctx.Imports.Aliased[path]; ok { importName = alias } return im...
[ "func", "GetImportedName", "(", "path", "string", ",", "ctx", "*", "Context", ")", "(", "string", ",", "bool", ")", "{", "importName", ",", "imported", ":=", "ctx", ".", "Imports", ".", "Imported", "[", "path", "]", "\n", "if", "!", "imported", "{", ...
// GetImportedName returns the name used for the package within the // code. It will resolve aliases and ignores initialization only imports.
[ "GetImportedName", "returns", "the", "name", "used", "for", "the", "package", "within", "the", "code", ".", "It", "will", "resolve", "aliases", "and", "ignores", "initialization", "only", "imports", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L217-L231
24,589
securego/gosec
helpers.go
GetImportPath
func GetImportPath(name string, ctx *Context) (string, bool) { for path := range ctx.Imports.Imported { if imported, ok := GetImportedName(path, ctx); ok && imported == name { return path, true } } return "", false }
go
func GetImportPath(name string, ctx *Context) (string, bool) { for path := range ctx.Imports.Imported { if imported, ok := GetImportedName(path, ctx); ok && imported == name { return path, true } } return "", false }
[ "func", "GetImportPath", "(", "name", "string", ",", "ctx", "*", "Context", ")", "(", "string", ",", "bool", ")", "{", "for", "path", ":=", "range", "ctx", ".", "Imports", ".", "Imported", "{", "if", "imported", ",", "ok", ":=", "GetImportedName", "(",...
// GetImportPath resolves the full import path of an identifier based on // the imports in the current context.
[ "GetImportPath", "resolves", "the", "full", "import", "path", "of", "an", "identifier", "based", "on", "the", "imports", "in", "the", "current", "context", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L235-L242
24,590
securego/gosec
helpers.go
GetLocation
func GetLocation(n ast.Node, ctx *Context) (string, int) { fobj := ctx.FileSet.File(n.Pos()) return fobj.Name(), fobj.Line(n.Pos()) }
go
func GetLocation(n ast.Node, ctx *Context) (string, int) { fobj := ctx.FileSet.File(n.Pos()) return fobj.Name(), fobj.Line(n.Pos()) }
[ "func", "GetLocation", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "string", ",", "int", ")", "{", "fobj", ":=", "ctx", ".", "FileSet", ".", "File", "(", "n", ".", "Pos", "(", ")", ")", "\n", "return", "fobj", ".", "Name...
// GetLocation returns the filename and line number of an ast.Node
[ "GetLocation", "returns", "the", "filename", "and", "line", "number", "of", "an", "ast", ".", "Node" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L245-L248
24,591
securego/gosec
helpers.go
Gopath
func Gopath() []string { defaultGoPath := runtime.GOROOT() if u, err := user.Current(); err == nil { defaultGoPath = filepath.Join(u.HomeDir, "go") } path := Getenv("GOPATH", defaultGoPath) paths := strings.Split(path, string(os.PathListSeparator)) for idx, path := range paths { if abs, err := filepath.Abs(pa...
go
func Gopath() []string { defaultGoPath := runtime.GOROOT() if u, err := user.Current(); err == nil { defaultGoPath = filepath.Join(u.HomeDir, "go") } path := Getenv("GOPATH", defaultGoPath) paths := strings.Split(path, string(os.PathListSeparator)) for idx, path := range paths { if abs, err := filepath.Abs(pa...
[ "func", "Gopath", "(", ")", "[", "]", "string", "{", "defaultGoPath", ":=", "runtime", ".", "GOROOT", "(", ")", "\n", "if", "u", ",", "err", ":=", "user", ".", "Current", "(", ")", ";", "err", "==", "nil", "{", "defaultGoPath", "=", "filepath", "."...
// Gopath returns all GOPATHs
[ "Gopath", "returns", "all", "GOPATHs" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L251-L264
24,592
securego/gosec
helpers.go
Getenv
func Getenv(key, userDefault string) string { if val := os.Getenv(key); val != "" { return val } return userDefault }
go
func Getenv(key, userDefault string) string { if val := os.Getenv(key); val != "" { return val } return userDefault }
[ "func", "Getenv", "(", "key", ",", "userDefault", "string", ")", "string", "{", "if", "val", ":=", "os", ".", "Getenv", "(", "key", ")", ";", "val", "!=", "\"", "\"", "{", "return", "val", "\n", "}", "\n", "return", "userDefault", "\n", "}" ]
// Getenv returns the values of the environment variable, otherwise //returns the default if variable is not set
[ "Getenv", "returns", "the", "values", "of", "the", "environment", "variable", "otherwise", "returns", "the", "default", "if", "variable", "is", "not", "set" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L268-L273
24,593
securego/gosec
helpers.go
GetPkgRelativePath
func GetPkgRelativePath(path string) (string, error) { abspath, err := filepath.Abs(path) if err != nil { abspath = path } if strings.HasSuffix(abspath, ".go") { abspath = filepath.Dir(abspath) } for _, base := range Gopath() { projectRoot := filepath.FromSlash(fmt.Sprintf("%s/src/", base)) if strings.Has...
go
func GetPkgRelativePath(path string) (string, error) { abspath, err := filepath.Abs(path) if err != nil { abspath = path } if strings.HasSuffix(abspath, ".go") { abspath = filepath.Dir(abspath) } for _, base := range Gopath() { projectRoot := filepath.FromSlash(fmt.Sprintf("%s/src/", base)) if strings.Has...
[ "func", "GetPkgRelativePath", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "abspath", ",", "err", ":=", "filepath", ".", "Abs", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "abspath", "=", "path", "\n", "}", "\n", "i...
// GetPkgRelativePath returns the Go relative relative path derived // form the given path
[ "GetPkgRelativePath", "returns", "the", "Go", "relative", "relative", "path", "derived", "form", "the", "given", "path" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L277-L292
24,594
securego/gosec
helpers.go
GetPkgAbsPath
func GetPkgAbsPath(pkgPath string) (string, error) { absPath, err := filepath.Abs(pkgPath) if err != nil { return "", err } if _, err := os.Stat(absPath); os.IsNotExist(err) { return "", errors.New("no project absolute path found") } return absPath, nil }
go
func GetPkgAbsPath(pkgPath string) (string, error) { absPath, err := filepath.Abs(pkgPath) if err != nil { return "", err } if _, err := os.Stat(absPath); os.IsNotExist(err) { return "", errors.New("no project absolute path found") } return absPath, nil }
[ "func", "GetPkgAbsPath", "(", "pkgPath", "string", ")", "(", "string", ",", "error", ")", "{", "absPath", ",", "err", ":=", "filepath", ".", "Abs", "(", "pkgPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}...
// GetPkgAbsPath returns the Go package absolute path derived from // the given path
[ "GetPkgAbsPath", "returns", "the", "Go", "package", "absolute", "path", "derived", "from", "the", "given", "path" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L296-L305
24,595
securego/gosec
helpers.go
ConcatString
func ConcatString(n *ast.BinaryExpr) (string, bool) { var s string // sub expressions are found in X object, Y object is always last BasicLit if rightOperand, ok := n.Y.(*ast.BasicLit); ok { if str, err := GetString(rightOperand); err == nil { s = str + s } } else { return "", false } if leftOperand, ok ...
go
func ConcatString(n *ast.BinaryExpr) (string, bool) { var s string // sub expressions are found in X object, Y object is always last BasicLit if rightOperand, ok := n.Y.(*ast.BasicLit); ok { if str, err := GetString(rightOperand); err == nil { s = str + s } } else { return "", false } if leftOperand, ok ...
[ "func", "ConcatString", "(", "n", "*", "ast", ".", "BinaryExpr", ")", "(", "string", ",", "bool", ")", "{", "var", "s", "string", "\n", "// sub expressions are found in X object, Y object is always last BasicLit", "if", "rightOperand", ",", "ok", ":=", "n", ".", ...
// ConcatString recursively concatenates strings from a binary expression
[ "ConcatString", "recursively", "concatenates", "strings", "from", "a", "binary", "expression" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L308-L330
24,596
securego/gosec
helpers.go
FindVarIdentities
func FindVarIdentities(n *ast.BinaryExpr, c *Context) ([]*ast.Ident, bool) { identities := []*ast.Ident{} // sub expressions are found in X object, Y object is always the last term if rightOperand, ok := n.Y.(*ast.Ident); ok { obj := c.Info.ObjectOf(rightOperand) if _, ok := obj.(*types.Var); ok && !TryResolve(r...
go
func FindVarIdentities(n *ast.BinaryExpr, c *Context) ([]*ast.Ident, bool) { identities := []*ast.Ident{} // sub expressions are found in X object, Y object is always the last term if rightOperand, ok := n.Y.(*ast.Ident); ok { obj := c.Info.ObjectOf(rightOperand) if _, ok := obj.(*types.Var); ok && !TryResolve(r...
[ "func", "FindVarIdentities", "(", "n", "*", "ast", ".", "BinaryExpr", ",", "c", "*", "Context", ")", "(", "[", "]", "*", "ast", ".", "Ident", ",", "bool", ")", "{", "identities", ":=", "[", "]", "*", "ast", ".", "Ident", "{", "}", "\n", "// sub e...
// FindVarIdentities returns array of all variable identities in a given binary expression
[ "FindVarIdentities", "returns", "array", "of", "all", "variable", "identities", "in", "a", "given", "binary", "expression" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L333-L360
24,597
securego/gosec
helpers.go
PackagePaths
func PackagePaths(root string, exclude *regexp.Regexp) ([]string, error) { if strings.HasSuffix(root, "...") { root = root[0 : len(root)-3] } else { return []string{root}, nil } paths := map[string]bool{} err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error { if filepath.Ext(path) == ...
go
func PackagePaths(root string, exclude *regexp.Regexp) ([]string, error) { if strings.HasSuffix(root, "...") { root = root[0 : len(root)-3] } else { return []string{root}, nil } paths := map[string]bool{} err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error { if filepath.Ext(path) == ...
[ "func", "PackagePaths", "(", "root", "string", ",", "exclude", "*", "regexp", ".", "Regexp", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "strings", ".", "HasSuffix", "(", "root", ",", "\"", "\"", ")", "{", "root", "=", "root", "[", ...
// PackagePaths returns a slice with all packages path at given root directory
[ "PackagePaths", "returns", "a", "slice", "with", "all", "packages", "path", "at", "given", "root", "directory" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L363-L389
24,598
securego/gosec
rules/tls_config.go
NewModernTLSCheck
func NewModernTLSCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &insecureConfigTLS{ MetaData: gosec.MetaData{ID: id}, requiredType: "crypto/tls.Config", MinVersion: 0x0303, MaxVersion: 0x0303, goodCiphers: []string{ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RS...
go
func NewModernTLSCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &insecureConfigTLS{ MetaData: gosec.MetaData{ID: id}, requiredType: "crypto/tls.Config", MinVersion: 0x0303, MaxVersion: 0x0303, goodCiphers: []string{ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RS...
[ "func", "NewModernTLSCheck", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "insecureConfigTLS", "{", "MetaData", ":", "gosec", ".", "MetaData", "{",...
// NewModernTLSCheck creates a check for Modern TLS ciphers // DO NOT EDIT - generated by tlsconfig tool
[ "NewModernTLSCheck", "creates", "a", "check", "for", "Modern", "TLS", "ciphers", "DO", "NOT", "EDIT", "-", "generated", "by", "tlsconfig", "tool" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/tls_config.go#L11-L30
24,599
securego/gosec
rule.go
Register
func (r RuleSet) Register(rule Rule, nodes ...ast.Node) { for _, n := range nodes { t := reflect.TypeOf(n) if rules, ok := r[t]; ok { r[t] = append(rules, rule) } else { r[t] = []Rule{rule} } } }
go
func (r RuleSet) Register(rule Rule, nodes ...ast.Node) { for _, n := range nodes { t := reflect.TypeOf(n) if rules, ok := r[t]; ok { r[t] = append(rules, rule) } else { r[t] = []Rule{rule} } } }
[ "func", "(", "r", "RuleSet", ")", "Register", "(", "rule", "Rule", ",", "nodes", "...", "ast", ".", "Node", ")", "{", "for", "_", ",", "n", ":=", "range", "nodes", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "n", ")", "\n", "if", "rules", ",...
// Register adds a trigger for the supplied rule for the the // specified ast nodes.
[ "Register", "adds", "a", "trigger", "for", "the", "supplied", "rule", "for", "the", "the", "specified", "ast", "nodes", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rule.go#L41-L50