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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,600 | btcsuite/btcutil | block.go | TxLoc | func (b *Block) TxLoc() ([]wire.TxLoc, error) {
rawMsg, err := b.Bytes()
if err != nil {
return nil, err
}
rbuf := bytes.NewBuffer(rawMsg)
var mblock wire.MsgBlock
txLocs, err := mblock.DeserializeTxLoc(rbuf)
if err != nil {
return nil, err
}
return txLocs, err
} | go | func (b *Block) TxLoc() ([]wire.TxLoc, error) {
rawMsg, err := b.Bytes()
if err != nil {
return nil, err
}
rbuf := bytes.NewBuffer(rawMsg)
var mblock wire.MsgBlock
txLocs, err := mblock.DeserializeTxLoc(rbuf)
if err != nil {
return nil, err
}
return txLocs, err
} | [
"func",
"(",
"b",
"*",
"Block",
")",
"TxLoc",
"(",
")",
"(",
"[",
"]",
"wire",
".",
"TxLoc",
",",
"error",
")",
"{",
"rawMsg",
",",
"err",
":=",
"b",
".",
"Bytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // TxLoc returns the offsets and lengths of each transaction in a raw block.
// It is used to allow fast indexing into transactions within the raw byte
// stream. | [
"TxLoc",
"returns",
"the",
"offsets",
"and",
"lengths",
"of",
"each",
"transaction",
"in",
"a",
"raw",
"block",
".",
"It",
"is",
"used",
"to",
"allow",
"fast",
"indexing",
"into",
"transactions",
"within",
"the",
"raw",
"byte",
"stream",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/block.go#L193-L206 |
149,601 | btcsuite/btcutil | block.go | NewBlock | func NewBlock(msgBlock *wire.MsgBlock) *Block {
return &Block{
msgBlock: msgBlock,
blockHeight: BlockHeightUnknown,
}
} | go | func NewBlock(msgBlock *wire.MsgBlock) *Block {
return &Block{
msgBlock: msgBlock,
blockHeight: BlockHeightUnknown,
}
} | [
"func",
"NewBlock",
"(",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
")",
"*",
"Block",
"{",
"return",
"&",
"Block",
"{",
"msgBlock",
":",
"msgBlock",
",",
"blockHeight",
":",
"BlockHeightUnknown",
",",
"}",
"\n",
"}"
] | // NewBlock returns a new instance of a bitcoin block given an underlying
// wire.MsgBlock. See Block. | [
"NewBlock",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"block",
"given",
"an",
"underlying",
"wire",
".",
"MsgBlock",
".",
"See",
"Block",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/block.go#L221-L226 |
149,602 | btcsuite/btcutil | block.go | NewBlockFromBytes | func NewBlockFromBytes(serializedBlock []byte) (*Block, error) {
br := bytes.NewReader(serializedBlock)
b, err := NewBlockFromReader(br)
if err != nil {
return nil, err
}
b.serializedBlock = serializedBlock
return b, nil
} | go | func NewBlockFromBytes(serializedBlock []byte) (*Block, error) {
br := bytes.NewReader(serializedBlock)
b, err := NewBlockFromReader(br)
if err != nil {
return nil, err
}
b.serializedBlock = serializedBlock
return b, nil
} | [
"func",
"NewBlockFromBytes",
"(",
"serializedBlock",
"[",
"]",
"byte",
")",
"(",
"*",
"Block",
",",
"error",
")",
"{",
"br",
":=",
"bytes",
".",
"NewReader",
"(",
"serializedBlock",
")",
"\n",
"b",
",",
"err",
":=",
"NewBlockFromReader",
"(",
"br",
")",
... | // NewBlockFromBytes returns a new instance of a bitcoin block given the
// serialized bytes. See Block. | [
"NewBlockFromBytes",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"block",
"given",
"the",
"serialized",
"bytes",
".",
"See",
"Block",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/block.go#L230-L238 |
149,603 | btcsuite/btcutil | block.go | NewBlockFromReader | func NewBlockFromReader(r io.Reader) (*Block, error) {
// Deserialize the bytes into a MsgBlock.
var msgBlock wire.MsgBlock
err := msgBlock.Deserialize(r)
if err != nil {
return nil, err
}
b := Block{
msgBlock: &msgBlock,
blockHeight: BlockHeightUnknown,
}
return &b, nil
} | go | func NewBlockFromReader(r io.Reader) (*Block, error) {
// Deserialize the bytes into a MsgBlock.
var msgBlock wire.MsgBlock
err := msgBlock.Deserialize(r)
if err != nil {
return nil, err
}
b := Block{
msgBlock: &msgBlock,
blockHeight: BlockHeightUnknown,
}
return &b, nil
} | [
"func",
"NewBlockFromReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Block",
",",
"error",
")",
"{",
"// Deserialize the bytes into a MsgBlock.",
"var",
"msgBlock",
"wire",
".",
"MsgBlock",
"\n",
"err",
":=",
"msgBlock",
".",
"Deserialize",
"(",
"r",
... | // NewBlockFromReader returns a new instance of a bitcoin block given a
// Reader to deserialize the block. See Block. | [
"NewBlockFromReader",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"block",
"given",
"a",
"Reader",
"to",
"deserialize",
"the",
"block",
".",
"See",
"Block",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/block.go#L242-L255 |
149,604 | btcsuite/btcutil | block.go | NewBlockFromBlockAndBytes | func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block {
return &Block{
msgBlock: msgBlock,
serializedBlock: serializedBlock,
blockHeight: BlockHeightUnknown,
}
} | go | func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block {
return &Block{
msgBlock: msgBlock,
serializedBlock: serializedBlock,
blockHeight: BlockHeightUnknown,
}
} | [
"func",
"NewBlockFromBlockAndBytes",
"(",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
",",
"serializedBlock",
"[",
"]",
"byte",
")",
"*",
"Block",
"{",
"return",
"&",
"Block",
"{",
"msgBlock",
":",
"msgBlock",
",",
"serializedBlock",
":",
"serializedBlock",
",",... | // NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given
// an underlying wire.MsgBlock and the serialized bytes for it. See Block. | [
"NewBlockFromBlockAndBytes",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"block",
"given",
"an",
"underlying",
"wire",
".",
"MsgBlock",
"and",
"the",
"serialized",
"bytes",
"for",
"it",
".",
"See",
"Block",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/block.go#L259-L265 |
149,605 | btcsuite/btcutil | base58/base58.go | Decode | func Decode(b string) []byte {
answer := big.NewInt(0)
j := big.NewInt(1)
scratch := new(big.Int)
for i := len(b) - 1; i >= 0; i-- {
tmp := b58[b[i]]
if tmp == 255 {
return []byte("")
}
scratch.SetInt64(int64(tmp))
scratch.Mul(j, scratch)
answer.Add(answer, scratch)
j.Mul(j, bigRadix)
}
tmpval ... | go | func Decode(b string) []byte {
answer := big.NewInt(0)
j := big.NewInt(1)
scratch := new(big.Int)
for i := len(b) - 1; i >= 0; i-- {
tmp := b58[b[i]]
if tmp == 255 {
return []byte("")
}
scratch.SetInt64(int64(tmp))
scratch.Mul(j, scratch)
answer.Add(answer, scratch)
j.Mul(j, bigRadix)
}
tmpval ... | [
"func",
"Decode",
"(",
"b",
"string",
")",
"[",
"]",
"byte",
"{",
"answer",
":=",
"big",
".",
"NewInt",
"(",
"0",
")",
"\n",
"j",
":=",
"big",
".",
"NewInt",
"(",
"1",
")",
"\n\n",
"scratch",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"f... | // Decode decodes a modified base58 string to a byte slice. | [
"Decode",
"decodes",
"a",
"modified",
"base58",
"string",
"to",
"a",
"byte",
"slice",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/base58/base58.go#L17-L46 |
149,606 | btcsuite/btcutil | wif.go | NewWIF | func NewWIF(privKey *btcec.PrivateKey, net *chaincfg.Params, compress bool) (*WIF, error) {
if net == nil {
return nil, errors.New("no network")
}
return &WIF{privKey, compress, net.PrivateKeyID}, nil
} | go | func NewWIF(privKey *btcec.PrivateKey, net *chaincfg.Params, compress bool) (*WIF, error) {
if net == nil {
return nil, errors.New("no network")
}
return &WIF{privKey, compress, net.PrivateKeyID}, nil
} | [
"func",
"NewWIF",
"(",
"privKey",
"*",
"btcec",
".",
"PrivateKey",
",",
"net",
"*",
"chaincfg",
".",
"Params",
",",
"compress",
"bool",
")",
"(",
"*",
"WIF",
",",
"error",
")",
"{",
"if",
"net",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
"."... | // NewWIF creates a new WIF structure to export an address and its private key
// as a string encoded in the Wallet Import Format. The compress argument
// specifies whether the address intended to be imported or exported was created
// by serializing the public key compressed rather than uncompressed. | [
"NewWIF",
"creates",
"a",
"new",
"WIF",
"structure",
"to",
"export",
"an",
"address",
"and",
"its",
"private",
"key",
"as",
"a",
"string",
"encoded",
"in",
"the",
"Wallet",
"Import",
"Format",
".",
"The",
"compress",
"argument",
"specifies",
"whether",
"the"... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/wif.go#L52-L57 |
149,607 | btcsuite/btcutil | wif.go | IsForNet | func (w *WIF) IsForNet(net *chaincfg.Params) bool {
return w.netID == net.PrivateKeyID
} | go | func (w *WIF) IsForNet(net *chaincfg.Params) bool {
return w.netID == net.PrivateKeyID
} | [
"func",
"(",
"w",
"*",
"WIF",
")",
"IsForNet",
"(",
"net",
"*",
"chaincfg",
".",
"Params",
")",
"bool",
"{",
"return",
"w",
".",
"netID",
"==",
"net",
".",
"PrivateKeyID",
"\n",
"}"
] | // IsForNet returns whether or not the decoded WIF structure is associated
// with the passed bitcoin network. | [
"IsForNet",
"returns",
"whether",
"or",
"not",
"the",
"decoded",
"WIF",
"structure",
"is",
"associated",
"with",
"the",
"passed",
"bitcoin",
"network",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/wif.go#L61-L63 |
149,608 | btcsuite/btcutil | wif.go | SerializePubKey | func (w *WIF) SerializePubKey() []byte {
pk := (*btcec.PublicKey)(&w.PrivKey.PublicKey)
if w.CompressPubKey {
return pk.SerializeCompressed()
}
return pk.SerializeUncompressed()
} | go | func (w *WIF) SerializePubKey() []byte {
pk := (*btcec.PublicKey)(&w.PrivKey.PublicKey)
if w.CompressPubKey {
return pk.SerializeCompressed()
}
return pk.SerializeUncompressed()
} | [
"func",
"(",
"w",
"*",
"WIF",
")",
"SerializePubKey",
"(",
")",
"[",
"]",
"byte",
"{",
"pk",
":=",
"(",
"*",
"btcec",
".",
"PublicKey",
")",
"(",
"&",
"w",
".",
"PrivKey",
".",
"PublicKey",
")",
"\n",
"if",
"w",
".",
"CompressPubKey",
"{",
"retur... | // SerializePubKey serializes the associated public key of the imported or
// exported private key in either a compressed or uncompressed format. The
// serialization format chosen depends on the value of w.CompressPubKey. | [
"SerializePubKey",
"serializes",
"the",
"associated",
"public",
"key",
"of",
"the",
"imported",
"or",
"exported",
"private",
"key",
"in",
"either",
"a",
"compressed",
"or",
"uncompressed",
"format",
".",
"The",
"serialization",
"format",
"chosen",
"depends",
"on",... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/wif.go#L153-L159 |
149,609 | btcsuite/btcutil | bech32/bech32.go | Decode | func Decode(bech string) (string, []byte, error) {
// The maximum allowed length for a bech32 string is 90. It must also
// be at least 8 characters, since it needs a non-empty HRP, a
// separator, and a 6 character checksum.
if len(bech) < 8 || len(bech) > 90 {
return "", nil, fmt.Errorf("invalid bech32 string l... | go | func Decode(bech string) (string, []byte, error) {
// The maximum allowed length for a bech32 string is 90. It must also
// be at least 8 characters, since it needs a non-empty HRP, a
// separator, and a 6 character checksum.
if len(bech) < 8 || len(bech) > 90 {
return "", nil, fmt.Errorf("invalid bech32 string l... | [
"func",
"Decode",
"(",
"bech",
"string",
")",
"(",
"string",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// The maximum allowed length for a bech32 string is 90. It must also",
"// be at least 8 characters, since it needs a non-empty HRP, a",
"// separator, and a 6 character ... | // Decode decodes a bech32 encoded string, returning the human-readable
// part and the data part excluding the checksum. | [
"Decode",
"decodes",
"a",
"bech32",
"encoded",
"string",
"returning",
"the",
"human",
"-",
"readable",
"part",
"and",
"the",
"data",
"part",
"excluding",
"the",
"checksum",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/bech32/bech32.go#L18-L80 |
149,610 | btcsuite/btcutil | bech32/bech32.go | ConvertBits | func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error) {
if fromBits < 1 || fromBits > 8 || toBits < 1 || toBits > 8 {
return nil, fmt.Errorf("only bit groups between 1 and 8 allowed")
}
// The final bytes, each byte encoding toBits bits.
var regrouped []byte
// Keep track of the next ... | go | func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error) {
if fromBits < 1 || fromBits > 8 || toBits < 1 || toBits > 8 {
return nil, fmt.Errorf("only bit groups between 1 and 8 allowed")
}
// The final bytes, each byte encoding toBits bits.
var regrouped []byte
// Keep track of the next ... | [
"func",
"ConvertBits",
"(",
"data",
"[",
"]",
"byte",
",",
"fromBits",
",",
"toBits",
"uint8",
",",
"pad",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"fromBits",
"<",
"1",
"||",
"fromBits",
">",
"8",
"||",
"toBits",
"<",
"1... | // ConvertBits converts a byte slice where each byte is encoding fromBits bits,
// to a byte slice where each byte is encoding toBits bits. | [
"ConvertBits",
"converts",
"a",
"byte",
"slice",
"where",
"each",
"byte",
"is",
"encoding",
"fromBits",
"bits",
"to",
"a",
"byte",
"slice",
"where",
"each",
"byte",
"is",
"encoding",
"toBits",
"bits",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/bech32/bech32.go#L131-L196 |
149,611 | btcsuite/btcutil | tx.go | Hash | func (t *Tx) Hash() *chainhash.Hash {
// Return the cached hash if it has already been generated.
if t.txHash != nil {
return t.txHash
}
// Cache the hash and return it.
hash := t.msgTx.TxHash()
t.txHash = &hash
return &hash
} | go | func (t *Tx) Hash() *chainhash.Hash {
// Return the cached hash if it has already been generated.
if t.txHash != nil {
return t.txHash
}
// Cache the hash and return it.
hash := t.msgTx.TxHash()
t.txHash = &hash
return &hash
} | [
"func",
"(",
"t",
"*",
"Tx",
")",
"Hash",
"(",
")",
"*",
"chainhash",
".",
"Hash",
"{",
"// Return the cached hash if it has already been generated.",
"if",
"t",
".",
"txHash",
"!=",
"nil",
"{",
"return",
"t",
".",
"txHash",
"\n",
"}",
"\n\n",
"// Cache the ... | // Hash returns the hash of the transaction. This is equivalent to
// calling TxHash on the underlying wire.MsgTx, however it caches the
// result so subsequent calls are more efficient. | [
"Hash",
"returns",
"the",
"hash",
"of",
"the",
"transaction",
".",
"This",
"is",
"equivalent",
"to",
"calling",
"TxHash",
"on",
"the",
"underlying",
"wire",
".",
"MsgTx",
"however",
"it",
"caches",
"the",
"result",
"so",
"subsequent",
"calls",
"are",
"more",... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/tx.go#L41-L51 |
149,612 | btcsuite/btcutil | tx.go | HasWitness | func (t *Tx) HasWitness() bool {
if t.txHashWitness != nil {
return *t.txHasWitness
}
hasWitness := t.msgTx.HasWitness()
t.txHasWitness = &hasWitness
return hasWitness
} | go | func (t *Tx) HasWitness() bool {
if t.txHashWitness != nil {
return *t.txHasWitness
}
hasWitness := t.msgTx.HasWitness()
t.txHasWitness = &hasWitness
return hasWitness
} | [
"func",
"(",
"t",
"*",
"Tx",
")",
"HasWitness",
"(",
")",
"bool",
"{",
"if",
"t",
".",
"txHashWitness",
"!=",
"nil",
"{",
"return",
"*",
"t",
".",
"txHasWitness",
"\n",
"}",
"\n\n",
"hasWitness",
":=",
"t",
".",
"msgTx",
".",
"HasWitness",
"(",
")"... | // HasWitness returns false if none of the inputs within the transaction
// contain witness data, true false otherwise. This equivalent to calling
// HasWitness on the underlying wire.MsgTx, however it caches the result so
// subsequent calls are more efficient. | [
"HasWitness",
"returns",
"false",
"if",
"none",
"of",
"the",
"inputs",
"within",
"the",
"transaction",
"contain",
"witness",
"data",
"true",
"false",
"otherwise",
".",
"This",
"equivalent",
"to",
"calling",
"HasWitness",
"on",
"the",
"underlying",
"wire",
".",
... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/tx.go#L72-L80 |
149,613 | btcsuite/btcutil | tx.go | NewTx | func NewTx(msgTx *wire.MsgTx) *Tx {
return &Tx{
msgTx: msgTx,
txIndex: TxIndexUnknown,
}
} | go | func NewTx(msgTx *wire.MsgTx) *Tx {
return &Tx{
msgTx: msgTx,
txIndex: TxIndexUnknown,
}
} | [
"func",
"NewTx",
"(",
"msgTx",
"*",
"wire",
".",
"MsgTx",
")",
"*",
"Tx",
"{",
"return",
"&",
"Tx",
"{",
"msgTx",
":",
"msgTx",
",",
"txIndex",
":",
"TxIndexUnknown",
",",
"}",
"\n",
"}"
] | // NewTx returns a new instance of a bitcoin transaction given an underlying
// wire.MsgTx. See Tx. | [
"NewTx",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"transaction",
"given",
"an",
"underlying",
"wire",
".",
"MsgTx",
".",
"See",
"Tx",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/tx.go#L95-L100 |
149,614 | btcsuite/btcutil | tx.go | NewTxFromBytes | func NewTxFromBytes(serializedTx []byte) (*Tx, error) {
br := bytes.NewReader(serializedTx)
return NewTxFromReader(br)
} | go | func NewTxFromBytes(serializedTx []byte) (*Tx, error) {
br := bytes.NewReader(serializedTx)
return NewTxFromReader(br)
} | [
"func",
"NewTxFromBytes",
"(",
"serializedTx",
"[",
"]",
"byte",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"br",
":=",
"bytes",
".",
"NewReader",
"(",
"serializedTx",
")",
"\n",
"return",
"NewTxFromReader",
"(",
"br",
")",
"\n",
"}"
] | // NewTxFromBytes returns a new instance of a bitcoin transaction given the
// serialized bytes. See Tx. | [
"NewTxFromBytes",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"transaction",
"given",
"the",
"serialized",
"bytes",
".",
"See",
"Tx",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/tx.go#L104-L107 |
149,615 | btcsuite/btcutil | tx.go | NewTxFromReader | func NewTxFromReader(r io.Reader) (*Tx, error) {
// Deserialize the bytes into a MsgTx.
var msgTx wire.MsgTx
err := msgTx.Deserialize(r)
if err != nil {
return nil, err
}
t := Tx{
msgTx: &msgTx,
txIndex: TxIndexUnknown,
}
return &t, nil
} | go | func NewTxFromReader(r io.Reader) (*Tx, error) {
// Deserialize the bytes into a MsgTx.
var msgTx wire.MsgTx
err := msgTx.Deserialize(r)
if err != nil {
return nil, err
}
t := Tx{
msgTx: &msgTx,
txIndex: TxIndexUnknown,
}
return &t, nil
} | [
"func",
"NewTxFromReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"// Deserialize the bytes into a MsgTx.",
"var",
"msgTx",
"wire",
".",
"MsgTx",
"\n",
"err",
":=",
"msgTx",
".",
"Deserialize",
"(",
"r",
")",
"\n",
"i... | // NewTxFromReader returns a new instance of a bitcoin transaction given a
// Reader to deserialize the transaction. See Tx. | [
"NewTxFromReader",
"returns",
"a",
"new",
"instance",
"of",
"a",
"bitcoin",
"transaction",
"given",
"a",
"Reader",
"to",
"deserialize",
"the",
"transaction",
".",
"See",
"Tx",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/tx.go#L111-L124 |
149,616 | btcsuite/btcutil | txsort/txsort.go | Sort | func Sort(tx *wire.MsgTx) *wire.MsgTx {
txCopy := tx.Copy()
sort.Sort(sortableInputSlice(txCopy.TxIn))
sort.Sort(sortableOutputSlice(txCopy.TxOut))
return txCopy
} | go | func Sort(tx *wire.MsgTx) *wire.MsgTx {
txCopy := tx.Copy()
sort.Sort(sortableInputSlice(txCopy.TxIn))
sort.Sort(sortableOutputSlice(txCopy.TxOut))
return txCopy
} | [
"func",
"Sort",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"*",
"wire",
".",
"MsgTx",
"{",
"txCopy",
":=",
"tx",
".",
"Copy",
"(",
")",
"\n",
"sort",
".",
"Sort",
"(",
"sortableInputSlice",
"(",
"txCopy",
".",
"TxIn",
")",
")",
"\n",
"sort",
".",... | // Sort returns a new transaction with the inputs and outputs sorted based on
// BIP 69. The passed transaction is not modified and the new transaction
// might have a different hash if any sorting was done. | [
"Sort",
"returns",
"a",
"new",
"transaction",
"with",
"the",
"inputs",
"and",
"outputs",
"sorted",
"based",
"on",
"BIP",
"69",
".",
"The",
"passed",
"transaction",
"is",
"not",
"modified",
"and",
"the",
"new",
"transaction",
"might",
"have",
"a",
"different"... | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/txsort/txsort.go#L38-L43 |
149,617 | btcsuite/btcutil | txsort/txsort.go | IsSorted | func IsSorted(tx *wire.MsgTx) bool {
if !sort.IsSorted(sortableInputSlice(tx.TxIn)) {
return false
}
if !sort.IsSorted(sortableOutputSlice(tx.TxOut)) {
return false
}
return true
} | go | func IsSorted(tx *wire.MsgTx) bool {
if !sort.IsSorted(sortableInputSlice(tx.TxIn)) {
return false
}
if !sort.IsSorted(sortableOutputSlice(tx.TxOut)) {
return false
}
return true
} | [
"func",
"IsSorted",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"bool",
"{",
"if",
"!",
"sort",
".",
"IsSorted",
"(",
"sortableInputSlice",
"(",
"tx",
".",
"TxIn",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"sort",
".",
"IsSorted"... | // IsSorted checks whether tx has inputs and outputs sorted according to BIP
// 69. | [
"IsSorted",
"checks",
"whether",
"tx",
"has",
"inputs",
"and",
"outputs",
"sorted",
"according",
"to",
"BIP",
"69",
"."
] | 9e5f4b9a998d263e3ce9c56664a7816001ac8000 | https://github.com/btcsuite/btcutil/blob/9e5f4b9a998d263e3ce9c56664a7816001ac8000/txsort/txsort.go#L47-L55 |
149,618 | logpacker/PayPal-Go-SDK | types.go | MarshalJSON | func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil
} | go | func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil
} | [
"func",
"(",
"t",
"JSONTime",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"stamp",
":=",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"time",
".",
"Time",
"(",
"t",
")",
".",
"UTC",
"(",
")",
".",
"Format",
"(",... | // MarshalJSON for JSONTime | [
"MarshalJSON",
"for",
"JSONTime"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/types.go#L607-L610 |
149,619 | logpacker/PayPal-Go-SDK | client.go | NewClient | func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
if clientID == "" || secret == "" || APIBase == "" {
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
}
return &Client{
Client: &http.Client{},
ClientID: clientID,
Secret: secret,
AP... | go | func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
if clientID == "" || secret == "" || APIBase == "" {
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
}
return &Client{
Client: &http.Client{},
ClientID: clientID,
Secret: secret,
AP... | [
"func",
"NewClient",
"(",
"clientID",
"string",
",",
"secret",
"string",
",",
"APIBase",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"clientID",
"==",
"\"",
"\"",
"||",
"secret",
"==",
"\"",
"\"",
"||",
"APIBase",
"==",
"\"",
"\"... | // NewClient returns new Client struct
// APIBase is a base API URL, for testing you can use paypalsdk.APIBaseSandBox | [
"NewClient",
"returns",
"new",
"Client",
"struct",
"APIBase",
"is",
"a",
"base",
"API",
"URL",
"for",
"testing",
"you",
"can",
"use",
"paypalsdk",
".",
"APIBaseSandBox"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L17-L28 |
149,620 | logpacker/PayPal-Go-SDK | client.go | SetAccessToken | func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{
Token: token,
}
c.tokenExpiresAt = time.Time{}
} | go | func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{
Token: token,
}
c.tokenExpiresAt = time.Time{}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetAccessToken",
"(",
"token",
"string",
")",
"{",
"c",
".",
"Token",
"=",
"&",
"TokenResponse",
"{",
"Token",
":",
"token",
",",
"}",
"\n",
"c",
".",
"tokenExpiresAt",
"=",
"time",
".",
"Time",
"{",
"}",
"\n"... | // SetAccessToken sets saved token to current client | [
"SetAccessToken",
"sets",
"saved",
"token",
"to",
"current",
"client"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L60-L65 |
149,621 | logpacker/PayPal-Go-SDK | client.go | Send | func (c *Client) Send(req *http.Request, v interface{}) error {
var (
err error
resp *http.Response
data []byte
)
// Set default headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept-Language", "en_US")
// Default values for headers
if req.Header.Get("Content-type") == "" {
req.H... | go | func (c *Client) Send(req *http.Request, v interface{}) error {
var (
err error
resp *http.Response
data []byte
)
// Set default headers
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept-Language", "en_US")
// Default values for headers
if req.Header.Get("Content-type") == "" {
req.H... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"(",
"err",
"error",
"\n",
"resp",
"*",
"http",
".",
"Response",
"\n",
"data",
"[",
"]",
"byte",
"... | // Send makes a request to the API, the response body will be
// unmarshaled into v, or if v is an io.Writer, the response will
// be written to it without decoding | [
"Send",
"makes",
"a",
"request",
"to",
"the",
"API",
"the",
"response",
"body",
"will",
"be",
"unmarshaled",
"into",
"v",
"or",
"if",
"v",
"is",
"an",
"io",
".",
"Writer",
"the",
"response",
"will",
"be",
"written",
"to",
"it",
"without",
"decoding"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L76-L121 |
149,622 | logpacker/PayPal-Go-SDK | client.go | SendWithAuth | func (c *Client) SendWithAuth(req *http.Request, v interface{}) error {
c.Lock()
// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`
// to happen outside of the locked section.
if c.Token != nil {
if !c.tokenExpiresAt.IsZero() && c.tokenExpiresAt.Sub(time.Now()) < RequestNewTokenBefo... | go | func (c *Client) SendWithAuth(req *http.Request, v interface{}) error {
c.Lock()
// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`
// to happen outside of the locked section.
if c.Token != nil {
if !c.tokenExpiresAt.IsZero() && c.tokenExpiresAt.Sub(time.Now()) < RequestNewTokenBefo... | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendWithAuth",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`... | // SendWithAuth makes a request to the API and apply OAuth2 header automatically.
// If the access token soon to be expired or already expired, it will try to get a new one before
// making the main request
// client.Token will be updated when changed | [
"SendWithAuth",
"makes",
"a",
"request",
"to",
"the",
"API",
"and",
"apply",
"OAuth2",
"header",
"automatically",
".",
"If",
"the",
"access",
"token",
"soon",
"to",
"be",
"expired",
"or",
"already",
"expired",
"it",
"will",
"try",
"to",
"get",
"a",
"new",
... | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L127-L148 |
149,623 | logpacker/PayPal-Go-SDK | client.go | NewRequest | func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Request, error) {
var buf io.Reader
if payload != nil {
var b []byte
b, err := json.Marshal(&payload)
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(b)
}
return http.NewRequest(method, url, buf)
} | go | func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Request, error) {
var buf io.Reader
if payload != nil {
var b []byte
b, err := json.Marshal(&payload)
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(b)
}
return http.NewRequest(method, url, buf)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewRequest",
"(",
"method",
",",
"url",
"string",
",",
"payload",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"var",
"buf",
"io",
".",
"Reader",
"\n",
"if",
"payload",... | // NewRequest constructs a request
// Convert payload to a JSON | [
"NewRequest",
"constructs",
"a",
"request",
"Convert",
"payload",
"to",
"a",
"JSON"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L159-L170 |
149,624 | logpacker/PayPal-Go-SDK | client.go | log | func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil {
var (
reqDump string
respDump []byte
)
if r != nil {
reqDump = fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
}
if resp != nil {
respDump, _ = httputil.DumpResponse(resp, true)
}
c.Log... | go | func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil {
var (
reqDump string
respDump []byte
)
if r != nil {
reqDump = fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
}
if resp != nil {
respDump, _ = httputil.DumpResponse(resp, true)
}
c.Log... | [
"func",
"(",
"c",
"*",
"Client",
")",
"log",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"{",
"if",
"c",
".",
"Log",
"!=",
"nil",
"{",
"var",
"(",
"reqDump",
"string",
"\n",
"respDump",
"[",
"]",
"byte... | // log will dump request and response to the log file | [
"log",
"will",
"dump",
"request",
"and",
"response",
"to",
"the",
"log",
"file"
] | 17ba889ca032031de3a3317087493307ca801dd9 | https://github.com/logpacker/PayPal-Go-SDK/blob/17ba889ca032031de3a3317087493307ca801dd9/client.go#L173-L189 |
149,625 | didip/tollbooth | libstring/libstring.go | StringInSlice | func StringInSlice(sliceString []string, needle string) bool {
for _, b := range sliceString {
if b == needle {
return true
}
}
return false
} | go | func StringInSlice(sliceString []string, needle string) bool {
for _, b := range sliceString {
if b == needle {
return true
}
}
return false
} | [
"func",
"StringInSlice",
"(",
"sliceString",
"[",
"]",
"string",
",",
"needle",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"sliceString",
"{",
"if",
"b",
"==",
"needle",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return... | // StringInSlice finds needle in a slice of strings. | [
"StringInSlice",
"finds",
"needle",
"in",
"a",
"slice",
"of",
"strings",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/libstring/libstring.go#L11-L18 |
149,626 | didip/tollbooth | tollbooth.go | setResponseHeaders | func setResponseHeaders(lmt *limiter.Limiter, w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Rate-Limit-Limit", fmt.Sprintf("%.2f", lmt.GetMax()))
w.Header().Add("X-Rate-Limit-Duration", "1")
w.Header().Add("X-Rate-Limit-Request-Forwarded-For", r.Header.Get("X-Forwarded-For"))
w.Header().Add("X-Rate-Li... | go | func setResponseHeaders(lmt *limiter.Limiter, w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Rate-Limit-Limit", fmt.Sprintf("%.2f", lmt.GetMax()))
w.Header().Add("X-Rate-Limit-Duration", "1")
w.Header().Add("X-Rate-Limit-Request-Forwarded-For", r.Header.Get("X-Forwarded-For"))
w.Header().Add("X-Rate-Li... | [
"func",
"setResponseHeaders",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Add",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf... | // setResponseHeaders configures X-Rate-Limit-Limit and X-Rate-Limit-Duration | [
"setResponseHeaders",
"configures",
"X",
"-",
"Rate",
"-",
"Limit",
"-",
"Limit",
"and",
"X",
"-",
"Rate",
"-",
"Limit",
"-",
"Duration"
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L16-L21 |
149,627 | didip/tollbooth | tollbooth.go | NewLimiter | func NewLimiter(max float64, tbOptions *limiter.ExpirableOptions) *limiter.Limiter {
return limiter.New(tbOptions).SetMax(max).SetBurst(int(math.Max(1, max)))
} | go | func NewLimiter(max float64, tbOptions *limiter.ExpirableOptions) *limiter.Limiter {
return limiter.New(tbOptions).SetMax(max).SetBurst(int(math.Max(1, max)))
} | [
"func",
"NewLimiter",
"(",
"max",
"float64",
",",
"tbOptions",
"*",
"limiter",
".",
"ExpirableOptions",
")",
"*",
"limiter",
".",
"Limiter",
"{",
"return",
"limiter",
".",
"New",
"(",
"tbOptions",
")",
".",
"SetMax",
"(",
"max",
")",
".",
"SetBurst",
"("... | // NewLimiter is a convenience function to limiter.New. | [
"NewLimiter",
"is",
"a",
"convenience",
"function",
"to",
"limiter",
".",
"New",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L24-L26 |
149,628 | didip/tollbooth | tollbooth.go | LimitHandler | func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler {
middle := func(w http.ResponseWriter, r *http.Request) {
httpError := LimitByRequest(lmt, w, r)
if httpError != nil {
lmt.ExecOnLimitReached(w, r)
w.Header().Add("Content-Type", lmt.GetMessageContentType())
w.WriteHeader(httpError.S... | go | func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler {
middle := func(w http.ResponseWriter, r *http.Request) {
httpError := LimitByRequest(lmt, w, r)
if httpError != nil {
lmt.ExecOnLimitReached(w, r)
w.Header().Add("Content-Type", lmt.GetMessageContentType())
w.WriteHeader(httpError.S... | [
"func",
"LimitHandler",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"middle",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{... | // LimitHandler is a middleware that performs rate-limiting given http.Handler struct. | [
"LimitHandler",
"is",
"a",
"middleware",
"that",
"performs",
"rate",
"-",
"limiting",
"given",
"http",
".",
"Handler",
"struct",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L159-L175 |
149,629 | didip/tollbooth | tollbooth.go | LimitFuncHandler | func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler {
return LimitHandler(lmt, http.HandlerFunc(nextFunc))
} | go | func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler {
return LimitHandler(lmt, http.HandlerFunc(nextFunc))
} | [
"func",
"LimitFuncHandler",
"(",
"lmt",
"*",
"limiter",
".",
"Limiter",
",",
"nextFunc",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
")",
"http",
".",
"Handler",
"{",
"return",
"LimitHandler",
"(",
"lmt",
",",
"http... | // LimitFuncHandler is a middleware that performs rate-limiting given request handler function. | [
"LimitFuncHandler",
"is",
"a",
"middleware",
"that",
"performs",
"rate",
"-",
"limiting",
"given",
"request",
"handler",
"function",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/tollbooth.go#L178-L180 |
149,630 | didip/tollbooth | errors/errors.go | Error | func (httperror *HTTPError) Error() string {
return fmt.Sprintf("%v: %v", httperror.StatusCode, httperror.Message)
} | go | func (httperror *HTTPError) Error() string {
return fmt.Sprintf("%v: %v", httperror.StatusCode, httperror.Message)
} | [
"func",
"(",
"httperror",
"*",
"HTTPError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"httperror",
".",
"StatusCode",
",",
"httperror",
".",
"Message",
")",
"\n",
"}"
] | // Error returns error message. | [
"Error",
"returns",
"error",
"message",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/errors/errors.go#L13-L15 |
149,631 | didip/tollbooth | limiter/limiter.go | New | func New(generalExpirableOptions *ExpirableOptions) *Limiter {
lmt := &Limiter{}
lmt.SetMessageContentType("text/plain; charset=utf-8").
SetMessage("You have reached maximum request limit.").
SetStatusCode(429).
SetOnLimitReached(nil).
SetIPLookups([]string{"RemoteAddr", "X-Forwarded-For", "X-Real-IP"}).
S... | go | func New(generalExpirableOptions *ExpirableOptions) *Limiter {
lmt := &Limiter{}
lmt.SetMessageContentType("text/plain; charset=utf-8").
SetMessage("You have reached maximum request limit.").
SetStatusCode(429).
SetOnLimitReached(nil).
SetIPLookups([]string{"RemoteAddr", "X-Forwarded-For", "X-Real-IP"}).
S... | [
"func",
"New",
"(",
"generalExpirableOptions",
"*",
"ExpirableOptions",
")",
"*",
"Limiter",
"{",
"lmt",
":=",
"&",
"Limiter",
"{",
"}",
"\n\n",
"lmt",
".",
"SetMessageContentType",
"(",
"\"",
"\"",
")",
".",
"SetMessage",
"(",
"\"",
"\"",
")",
".",
"Set... | // New is a constructor for Limiter. | [
"New",
"is",
"a",
"constructor",
"for",
"Limiter",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L14-L52 |
149,632 | didip/tollbooth | limiter/limiter.go | SetTokenBucketExpirationTTL | func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.tokenBucketExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.tokenBucketExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetTokenBucketExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"tokenBucketExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",... | // SetTokenBucketExpirationTTL is thread-safe way of setting custom token bucket expiration TTL. | [
"SetTokenBucketExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"token",
"bucket",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L106-L112 |
149,633 | didip/tollbooth | limiter/limiter.go | GetTokenBucketExpirationTTL | func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.tokenBucketExpirationTTL
} | go | func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.tokenBucketExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetTokenBucketExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"tokenBucketExpirationTTL",
"\n",
"}"
] | // GettokenBucketExpirationTTL is thread-safe way of getting custom token bucket expiration TTL. | [
"GettokenBucketExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"token",
"bucket",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L115-L119 |
149,634 | didip/tollbooth | limiter/limiter.go | SetBasicAuthExpirationTTL | func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.basicAuthExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.basicAuthExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBasicAuthExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"basicAuthExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",
"... | // SetBasicAuthExpirationTTL is thread-safe way of setting custom basic auth expiration TTL. | [
"SetBasicAuthExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L122-L128 |
149,635 | didip/tollbooth | limiter/limiter.go | GetBasicAuthExpirationTTL | func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.basicAuthExpirationTTL
} | go | func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.basicAuthExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBasicAuthExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"basicAuthExpirationTTL",
"\n",
"}"
] | // GetBasicAuthExpirationTTL is thread-safe way of getting custom basic auth expiration TTL. | [
"GetBasicAuthExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L131-L135 |
149,636 | didip/tollbooth | limiter/limiter.go | SetHeaderEntryExpirationTTL | func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.headerEntryExpirationTTL = ttl
l.Unlock()
return l
} | go | func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter {
l.Lock()
l.headerEntryExpirationTTL = ttl
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeaderEntryExpirationTTL",
"(",
"ttl",
"time",
".",
"Duration",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"headerEntryExpirationTTL",
"=",
"ttl",
"\n",
"l",
".",
"Unlock",
"(",
")",... | // SetHeaderEntryExpirationTTL is thread-safe way of setting custom basic auth expiration TTL. | [
"SetHeaderEntryExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L138-L144 |
149,637 | didip/tollbooth | limiter/limiter.go | GetHeaderEntryExpirationTTL | func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.headerEntryExpirationTTL
} | go | func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration {
l.RLock()
defer l.RUnlock()
return l.headerEntryExpirationTTL
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeaderEntryExpirationTTL",
"(",
")",
"time",
".",
"Duration",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"headerEntryExpirationTTL",
"\n",
"}"
] | // GetHeaderEntryExpirationTTL is thread-safe way of getting custom basic auth expiration TTL. | [
"GetHeaderEntryExpirationTTL",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"custom",
"basic",
"auth",
"expiration",
"TTL",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L147-L151 |
149,638 | didip/tollbooth | limiter/limiter.go | SetMax | func (l *Limiter) SetMax(max float64) *Limiter {
l.Lock()
l.max = max
l.Unlock()
return l
} | go | func (l *Limiter) SetMax(max float64) *Limiter {
l.Lock()
l.max = max
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMax",
"(",
"max",
"float64",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"max",
"=",
"max",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetMax is thread-safe way of setting maximum number of requests to limit per duration. | [
"SetMax",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"number",
"of",
"requests",
"to",
"limit",
"per",
"duration",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L154-L160 |
149,639 | didip/tollbooth | limiter/limiter.go | GetMax | func (l *Limiter) GetMax() float64 {
l.RLock()
defer l.RUnlock()
return l.max
} | go | func (l *Limiter) GetMax() float64 {
l.RLock()
defer l.RUnlock()
return l.max
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMax",
"(",
")",
"float64",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"max",
"\n",
"}"
] | // GetMax is thread-safe way of getting maximum number of requests to limit per duration. | [
"GetMax",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"maximum",
"number",
"of",
"requests",
"to",
"limit",
"per",
"duration",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L163-L167 |
149,640 | didip/tollbooth | limiter/limiter.go | SetBurst | func (l *Limiter) SetBurst(burst int) *Limiter {
l.Lock()
l.burst = burst
l.Unlock()
return l
} | go | func (l *Limiter) SetBurst(burst int) *Limiter {
l.Lock()
l.burst = burst
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBurst",
"(",
"burst",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"burst",
"=",
"burst",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetBurst is thread-safe way of setting maximum burst size. | [
"SetBurst",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"burst",
"size",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L170-L176 |
149,641 | didip/tollbooth | limiter/limiter.go | GetBurst | func (l *Limiter) GetBurst() int {
l.RLock()
defer l.RUnlock()
return l.burst
} | go | func (l *Limiter) GetBurst() int {
l.RLock()
defer l.RUnlock()
return l.burst
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBurst",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"l",
".",
"burst",
"\n",
"}"
] | // GetBurst is thread-safe way of setting maximum burst size. | [
"GetBurst",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"maximum",
"burst",
"size",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L179-L184 |
149,642 | didip/tollbooth | limiter/limiter.go | SetMessage | func (l *Limiter) SetMessage(msg string) *Limiter {
l.Lock()
l.message = msg
l.Unlock()
return l
} | go | func (l *Limiter) SetMessage(msg string) *Limiter {
l.Lock()
l.message = msg
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMessage",
"(",
"msg",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"message",
"=",
"msg",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // SetMessage is thread-safe way of setting HTTP message when limit is reached. | [
"SetMessage",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"message",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L187-L193 |
149,643 | didip/tollbooth | limiter/limiter.go | GetMessage | func (l *Limiter) GetMessage() string {
l.RLock()
defer l.RUnlock()
return l.message
} | go | func (l *Limiter) GetMessage() string {
l.RLock()
defer l.RUnlock()
return l.message
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMessage",
"(",
")",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"message",
"\n",
"}"
] | // GetMessage is thread-safe way of getting HTTP message when limit is reached. | [
"GetMessage",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"message",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L196-L200 |
149,644 | didip/tollbooth | limiter/limiter.go | SetMessageContentType | func (l *Limiter) SetMessageContentType(contentType string) *Limiter {
l.Lock()
l.messageContentType = contentType
l.Unlock()
return l
} | go | func (l *Limiter) SetMessageContentType(contentType string) *Limiter {
l.Lock()
l.messageContentType = contentType
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetMessageContentType",
"(",
"contentType",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"messageContentType",
"=",
"contentType",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"r... | // SetMessageContentType is thread-safe way of setting HTTP message Content-Type when limit is reached. | [
"SetMessageContentType",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"message",
"Content",
"-",
"Type",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L203-L209 |
149,645 | didip/tollbooth | limiter/limiter.go | GetMessageContentType | func (l *Limiter) GetMessageContentType() string {
l.RLock()
defer l.RUnlock()
return l.messageContentType
} | go | func (l *Limiter) GetMessageContentType() string {
l.RLock()
defer l.RUnlock()
return l.messageContentType
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetMessageContentType",
"(",
")",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"messageContentType",
"\n",
"}"
] | // GetMessageContentType is thread-safe way of getting HTTP message Content-Type when limit is reached. | [
"GetMessageContentType",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"message",
"Content",
"-",
"Type",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L212-L216 |
149,646 | didip/tollbooth | limiter/limiter.go | SetStatusCode | func (l *Limiter) SetStatusCode(statusCode int) *Limiter {
l.Lock()
l.statusCode = statusCode
l.Unlock()
return l
} | go | func (l *Limiter) SetStatusCode(statusCode int) *Limiter {
l.Lock()
l.statusCode = statusCode
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetStatusCode",
"(",
"statusCode",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"statusCode",
"=",
"statusCode",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"l",
"\n"... | // SetStatusCode is thread-safe way of setting HTTP status code when limit is reached. | [
"SetStatusCode",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"HTTP",
"status",
"code",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L219-L225 |
149,647 | didip/tollbooth | limiter/limiter.go | GetStatusCode | func (l *Limiter) GetStatusCode() int {
l.RLock()
defer l.RUnlock()
return l.statusCode
} | go | func (l *Limiter) GetStatusCode() int {
l.RLock()
defer l.RUnlock()
return l.statusCode
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetStatusCode",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"statusCode",
"\n",
"}"
] | // GetStatusCode is thread-safe way of getting HTTP status code when limit is reached. | [
"GetStatusCode",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"HTTP",
"status",
"code",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L228-L232 |
149,648 | didip/tollbooth | limiter/limiter.go | SetOnLimitReached | func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter {
l.Lock()
l.onLimitReached = fn
l.Unlock()
return l
} | go | func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter {
l.Lock()
l.onLimitReached = fn
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetOnLimitReached",
"(",
"fn",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"onLimitReache... | // SetOnLimitReached is thread-safe way of setting after-rejection function when limit is reached. | [
"SetOnLimitReached",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"after",
"-",
"rejection",
"function",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L235-L241 |
149,649 | didip/tollbooth | limiter/limiter.go | ExecOnLimitReached | func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request) {
l.RLock()
defer l.RUnlock()
fn := l.onLimitReached
if fn != nil {
fn(w, r)
}
} | go | func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request) {
l.RLock()
defer l.RUnlock()
fn := l.onLimitReached
if fn != nil {
fn(w, r)
}
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"ExecOnLimitReached",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n\n",
"fn",
":=",
... | // ExecOnLimitReached is thread-safe way of executing after-rejection function when limit is reached. | [
"ExecOnLimitReached",
"is",
"thread",
"-",
"safe",
"way",
"of",
"executing",
"after",
"-",
"rejection",
"function",
"when",
"limit",
"is",
"reached",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L244-L252 |
149,650 | didip/tollbooth | limiter/limiter.go | SetIPLookups | func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter {
l.Lock()
l.ipLookups = ipLookups
l.Unlock()
return l
} | go | func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter {
l.Lock()
l.ipLookups = ipLookups
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetIPLookups",
"(",
"ipLookups",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"ipLookups",
"=",
"ipLookups",
"\n",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
... | // SetIPLookups is thread-safe way of setting list of places to look up IP address. | [
"SetIPLookups",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"list",
"of",
"places",
"to",
"look",
"up",
"IP",
"address",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L255-L261 |
149,651 | didip/tollbooth | limiter/limiter.go | GetIPLookups | func (l *Limiter) GetIPLookups() []string {
l.RLock()
defer l.RUnlock()
return l.ipLookups
} | go | func (l *Limiter) GetIPLookups() []string {
l.RLock()
defer l.RUnlock()
return l.ipLookups
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetIPLookups",
"(",
")",
"[",
"]",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"ipLookups",
"\n",
"}"
] | // GetIPLookups is thread-safe way of getting list of places to look up IP address. | [
"GetIPLookups",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"list",
"of",
"places",
"to",
"look",
"up",
"IP",
"address",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L264-L268 |
149,652 | didip/tollbooth | limiter/limiter.go | SetForwardedForIndexFromBehind | func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter {
l.Lock()
l.forwardedForIndex = forwardedForIndex
l.Unlock()
return l
} | go | func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter {
l.Lock()
l.forwardedForIndex = forwardedForIndex
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetForwardedForIndexFromBehind",
"(",
"forwardedForIndex",
"int",
")",
"*",
"Limiter",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"l",
".",
"forwardedForIndex",
"=",
"forwardedForIndex",
"\n",
"l",
".",
"Unlock",
"(",
")... | // SetForwardedForIndexFromBehind is thread-safe way of setting which X-Forwarded-For index to choose. | [
"SetForwardedForIndexFromBehind",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"which",
"X",
"-",
"Forwarded",
"-",
"For",
"index",
"to",
"choose",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L271-L277 |
149,653 | didip/tollbooth | limiter/limiter.go | GetForwardedForIndexFromBehind | func (l *Limiter) GetForwardedForIndexFromBehind() int {
l.RLock()
defer l.RUnlock()
return l.forwardedForIndex
} | go | func (l *Limiter) GetForwardedForIndexFromBehind() int {
l.RLock()
defer l.RUnlock()
return l.forwardedForIndex
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetForwardedForIndexFromBehind",
"(",
")",
"int",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"forwardedForIndex",
"\n",
"}"
] | // GetForwardedForIndexFromBehind is thread-safe way of getting which X-Forwarded-For index to choose. | [
"GetForwardedForIndexFromBehind",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"which",
"X",
"-",
"Forwarded",
"-",
"For",
"index",
"to",
"choose",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L280-L284 |
149,654 | didip/tollbooth | limiter/limiter.go | SetBasicAuthUsers | func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter {
ttl := l.GetBasicAuthExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
for _, basicAuthUser := range basicAuthUsers {
l.basicAuthUsers.Set(basicAuthUser, true, ttl)
}
return l
} | go | func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter {
ttl := l.GetBasicAuthExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
for _, basicAuthUser := range basicAuthUsers {
l.basicAuthUsers.Set(basicAuthUser, true, ttl)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetBasicAuthUsers",
"(",
"basicAuthUsers",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"ttl",
":=",
"l",
".",
"GetBasicAuthExpirationTTL",
"(",
")",
"\n",
"if",
"ttl",
"<=",
"0",
"{",
"ttl",
"=",
"l",
".",
"g... | // SetBasicAuthUsers is thread-safe way of setting list of basic auth usernames to limit. | [
"SetBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"list",
"of",
"basic",
"auth",
"usernames",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L303-L314 |
149,655 | didip/tollbooth | limiter/limiter.go | GetBasicAuthUsers | func (l *Limiter) GetBasicAuthUsers() []string {
asMap := l.basicAuthUsers.Items()
var basicAuthUsers []string
for basicAuthUser, _ := range asMap {
basicAuthUsers = append(basicAuthUsers, basicAuthUser)
}
return basicAuthUsers
} | go | func (l *Limiter) GetBasicAuthUsers() []string {
asMap := l.basicAuthUsers.Items()
var basicAuthUsers []string
for basicAuthUser, _ := range asMap {
basicAuthUsers = append(basicAuthUsers, basicAuthUser)
}
return basicAuthUsers
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetBasicAuthUsers",
"(",
")",
"[",
"]",
"string",
"{",
"asMap",
":=",
"l",
".",
"basicAuthUsers",
".",
"Items",
"(",
")",
"\n\n",
"var",
"basicAuthUsers",
"[",
"]",
"string",
"\n",
"for",
"basicAuthUser",
",",
"_... | // GetBasicAuthUsers is thread-safe way of getting list of basic auth usernames to limit. | [
"GetBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"list",
"of",
"basic",
"auth",
"usernames",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L317-L326 |
149,656 | didip/tollbooth | limiter/limiter.go | RemoveBasicAuthUsers | func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter {
for _, toBeRemoved := range basicAuthUsers {
l.basicAuthUsers.Delete(toBeRemoved)
}
return l
} | go | func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter {
for _, toBeRemoved := range basicAuthUsers {
l.basicAuthUsers.Delete(toBeRemoved)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveBasicAuthUsers",
"(",
"basicAuthUsers",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"for",
"_",
",",
"toBeRemoved",
":=",
"range",
"basicAuthUsers",
"{",
"l",
".",
"basicAuthUsers",
".",
"Delete",
"(",
"toBeR... | // RemoveBasicAuthUsers is thread-safe way of removing basic auth usernames from existing list. | [
"RemoveBasicAuthUsers",
"is",
"thread",
"-",
"safe",
"way",
"of",
"removing",
"basic",
"auth",
"usernames",
"from",
"existing",
"list",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L329-L335 |
149,657 | didip/tollbooth | limiter/limiter.go | SetHeaders | func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter {
if l.headers == nil {
l.headers = make(map[string]*gocache.Cache)
}
for header, entries := range headers {
l.SetHeader(header, entries)
}
return l
} | go | func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter {
if l.headers == nil {
l.headers = make(map[string]*gocache.Cache)
}
for header, entries := range headers {
l.SetHeader(header, entries)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"if",
"l",
".",
"headers",
"==",
"nil",
"{",
"l",
".",
"headers",
"=",
"make",
"(",
"map",
"[",
"string"... | // SetHeaders is thread-safe way of setting map of HTTP headers to limit. | [
"SetHeaders",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"map",
"of",
"HTTP",
"headers",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L338-L348 |
149,658 | didip/tollbooth | limiter/limiter.go | GetHeaders | func (l *Limiter) GetHeaders() map[string][]string {
results := make(map[string][]string)
l.RLock()
defer l.RUnlock()
for header, entriesAsGoCache := range l.headers {
entries := make([]string, 0)
for entry, _ := range entriesAsGoCache.Items() {
entries = append(entries, entry)
}
results[header] = en... | go | func (l *Limiter) GetHeaders() map[string][]string {
results := make(map[string][]string)
l.RLock()
defer l.RUnlock()
for header, entriesAsGoCache := range l.headers {
entries := make([]string, 0)
for entry, _ := range entriesAsGoCache.Items() {
entries = append(entries, entry)
}
results[header] = en... | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeaders",
"(",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"results",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n\n",
"l",
".",
"RLock",
"(",
")",
"\n",
"def... | // GetHeaders is thread-safe way of getting map of HTTP headers to limit. | [
"GetHeaders",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"map",
"of",
"HTTP",
"headers",
"to",
"limit",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L351-L368 |
149,659 | didip/tollbooth | limiter/limiter.go | SetHeader | func (l *Limiter) SetHeader(header string, entries []string) *Limiter {
l.RLock()
existing, found := l.headers[header]
l.RUnlock()
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
if !found {
existing = gocache.New(ttl, l.generalExpirableOptions.Ex... | go | func (l *Limiter) SetHeader(header string, entries []string) *Limiter {
l.RLock()
existing, found := l.headers[header]
l.RUnlock()
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
if !found {
existing = gocache.New(ttl, l.generalExpirableOptions.Ex... | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"SetHeader",
"(",
"header",
"string",
",",
"entries",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"existing",
",",
"found",
":=",
"l",
".",
"headers",
"[",
"header",
"]",
... | // SetHeader is thread-safe way of setting entries of 1 HTTP header. | [
"SetHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"setting",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L371-L394 |
149,660 | didip/tollbooth | limiter/limiter.go | GetHeader | func (l *Limiter) GetHeader(header string) []string {
l.RLock()
entriesAsGoCache := l.headers[header]
l.RUnlock()
entriesAsMap := entriesAsGoCache.Items()
entries := make([]string, 0)
for entry, _ := range entriesAsMap {
entries = append(entries, entry)
}
return entries
} | go | func (l *Limiter) GetHeader(header string) []string {
l.RLock()
entriesAsGoCache := l.headers[header]
l.RUnlock()
entriesAsMap := entriesAsGoCache.Items()
entries := make([]string, 0)
for entry, _ := range entriesAsMap {
entries = append(entries, entry)
}
return entries
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"GetHeader",
"(",
"header",
"string",
")",
"[",
"]",
"string",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"entriesAsGoCache",
":=",
"l",
".",
"headers",
"[",
"header",
"]",
"\n",
"l",
".",
"RUnlock",
"(",
")",
... | // GetHeader is thread-safe way of getting entries of 1 HTTP header. | [
"GetHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"getting",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L397-L410 |
149,661 | didip/tollbooth | limiter/limiter.go | RemoveHeader | func (l *Limiter) RemoveHeader(header string) *Limiter {
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
l.Lock()
l.headers[header] = gocache.New(ttl, l.generalExpirableOptions.ExpireJobInterval)
l.Unlock()
return l
} | go | func (l *Limiter) RemoveHeader(header string) *Limiter {
ttl := l.GetHeaderEntryExpirationTTL()
if ttl <= 0 {
ttl = l.generalExpirableOptions.DefaultExpirationTTL
}
l.Lock()
l.headers[header] = gocache.New(ttl, l.generalExpirableOptions.ExpireJobInterval)
l.Unlock()
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveHeader",
"(",
"header",
"string",
")",
"*",
"Limiter",
"{",
"ttl",
":=",
"l",
".",
"GetHeaderEntryExpirationTTL",
"(",
")",
"\n",
"if",
"ttl",
"<=",
"0",
"{",
"ttl",
"=",
"l",
".",
"generalExpirableOptions",
... | // RemoveHeader is thread-safe way of removing entries of 1 HTTP header. | [
"RemoveHeader",
"is",
"thread",
"-",
"safe",
"way",
"of",
"removing",
"entries",
"of",
"1",
"HTTP",
"header",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L413-L424 |
149,662 | didip/tollbooth | limiter/limiter.go | RemoveHeaderEntries | func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter {
l.RLock()
entries, found := l.headers[header]
l.RUnlock()
if !found {
return l
}
for _, toBeRemoved := range entriesForRemoval {
entries.Delete(toBeRemoved)
}
return l
} | go | func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter {
l.RLock()
entries, found := l.headers[header]
l.RUnlock()
if !found {
return l
}
for _, toBeRemoved := range entriesForRemoval {
entries.Delete(toBeRemoved)
}
return l
} | [
"func",
"(",
"l",
"*",
"Limiter",
")",
"RemoveHeaderEntries",
"(",
"header",
"string",
",",
"entriesForRemoval",
"[",
"]",
"string",
")",
"*",
"Limiter",
"{",
"l",
".",
"RLock",
"(",
")",
"\n",
"entries",
",",
"found",
":=",
"l",
".",
"headers",
"[",
... | // RemoveHeaderEntries is thread-safe way of adding new entries to 1 HTTP header rule. | [
"RemoveHeaderEntries",
"is",
"thread",
"-",
"safe",
"way",
"of",
"adding",
"new",
"entries",
"to",
"1",
"HTTP",
"header",
"rule",
"."
] | b10a036da5f05864224ee09432e489b32a6b2d1d | https://github.com/didip/tollbooth/blob/b10a036da5f05864224ee09432e489b32a6b2d1d/limiter/limiter.go#L427-L441 |
149,663 | AlecAivazis/survey | survey.go | WithStdio | func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) AskOpt {
return func(options *AskOptions) error {
options.Stdio.In = in
options.Stdio.Out = out
options.Stdio.Err = err
return nil
}
} | go | func WithStdio(in terminal.FileReader, out terminal.FileWriter, err io.Writer) AskOpt {
return func(options *AskOptions) error {
options.Stdio.In = in
options.Stdio.Out = out
options.Stdio.Err = err
return nil
}
} | [
"func",
"WithStdio",
"(",
"in",
"terminal",
".",
"FileReader",
",",
"out",
"terminal",
".",
"FileWriter",
",",
"err",
"io",
".",
"Writer",
")",
"AskOpt",
"{",
"return",
"func",
"(",
"options",
"*",
"AskOptions",
")",
"error",
"{",
"options",
".",
"Stdio"... | // WithStdio specifies the standard input, output and error files survey
// interacts with. By default, these are os.Stdin, os.Stdout, and os.Stderr. | [
"WithStdio",
"specifies",
"the",
"standard",
"input",
"output",
"and",
"error",
"files",
"survey",
"interacts",
"with",
".",
"By",
"default",
"these",
"are",
"os",
".",
"Stdin",
"os",
".",
"Stdout",
"and",
"os",
".",
"Stderr",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/survey.go#L67-L74 |
149,664 | AlecAivazis/survey | survey.go | paginate | func paginate(page int, choices []string, sel int) ([]string, int) {
// the number of elements to show in a single page
var pageSize int
// if the select has a specific page size
if page != 0 {
// use the specified one
pageSize = page
// otherwise the select does not have a page size
} else {
// use the pa... | go | func paginate(page int, choices []string, sel int) ([]string, int) {
// the number of elements to show in a single page
var pageSize int
// if the select has a specific page size
if page != 0 {
// use the specified one
pageSize = page
// otherwise the select does not have a page size
} else {
// use the pa... | [
"func",
"paginate",
"(",
"page",
"int",
",",
"choices",
"[",
"]",
"string",
",",
"sel",
"int",
")",
"(",
"[",
"]",
"string",
",",
"int",
")",
"{",
"// the number of elements to show in a single page",
"var",
"pageSize",
"int",
"\n",
"// if the select has a speci... | // paginate returns a single page of choices given the page size, the total list of
// possible choices, and the current selected index in the total list. | [
"paginate",
"returns",
"a",
"single",
"page",
"of",
"choices",
"given",
"the",
"page",
"size",
"the",
"total",
"list",
"of",
"possible",
"choices",
"and",
"the",
"current",
"selected",
"index",
"in",
"the",
"total",
"list",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/survey.go#L210-L255 |
149,665 | AlecAivazis/survey | transform.go | ComposeTransformers | func ComposeTransformers(transformers ...Transformer) Transformer {
// return a transformer that calls each one sequentially
return func(ans interface{}) interface{} {
// execute each transformer
for _, t := range transformers {
ans = t(ans)
}
return ans
}
} | go | func ComposeTransformers(transformers ...Transformer) Transformer {
// return a transformer that calls each one sequentially
return func(ans interface{}) interface{} {
// execute each transformer
for _, t := range transformers {
ans = t(ans)
}
return ans
}
} | [
"func",
"ComposeTransformers",
"(",
"transformers",
"...",
"Transformer",
")",
"Transformer",
"{",
"// return a transformer that calls each one sequentially",
"return",
"func",
"(",
"ans",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"// execute each transforme... | // ComposeTransformers is a variadic function used to create one transformer from many. | [
"ComposeTransformers",
"is",
"a",
"variadic",
"function",
"used",
"to",
"create",
"one",
"transformer",
"from",
"many",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/transform.go#L67-L76 |
149,666 | AlecAivazis/survey | validate.go | Required | func Required(val interface{}) error {
// the reflect value of the result
value := reflect.ValueOf(val)
// if the value passed in is the zero value of the appropriate type
if isZero(value) && value.Kind() != reflect.Bool {
return errors.New("Value is required")
}
return nil
} | go | func Required(val interface{}) error {
// the reflect value of the result
value := reflect.ValueOf(val)
// if the value passed in is the zero value of the appropriate type
if isZero(value) && value.Kind() != reflect.Bool {
return errors.New("Value is required")
}
return nil
} | [
"func",
"Required",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// the reflect value of the result",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n\n",
"// if the value passed in is the zero value of the appropriate type",
"if",
"isZero",
"(",... | // Required does not allow an empty value | [
"Required",
"does",
"not",
"allow",
"an",
"empty",
"value"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L10-L19 |
149,667 | AlecAivazis/survey | validate.go | MaxLength | func MaxLength(length int) Validator {
// return a validator that checks the length of the string
return func(val interface{}) error {
if str, ok := val.(string); ok {
// if the string is longer than the given value
if len([]rune(str)) > length {
// yell loudly
return fmt.Errorf("value is too long. Ma... | go | func MaxLength(length int) Validator {
// return a validator that checks the length of the string
return func(val interface{}) error {
if str, ok := val.(string); ok {
// if the string is longer than the given value
if len([]rune(str)) > length {
// yell loudly
return fmt.Errorf("value is too long. Ma... | [
"func",
"MaxLength",
"(",
"length",
"int",
")",
"Validator",
"{",
"// return a validator that checks the length of the string",
"return",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"str",
",",
"ok",
":=",
"val",
".",
"(",
"string",
")"... | // MaxLength requires that the string is no longer than the specified value | [
"MaxLength",
"requires",
"that",
"the",
"string",
"is",
"no",
"longer",
"than",
"the",
"specified",
"value"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L22-L39 |
149,668 | AlecAivazis/survey | validate.go | ComposeValidators | func ComposeValidators(validators ...Validator) Validator {
// return a validator that calls each one sequentially
return func(val interface{}) error {
// execute each validator
for _, validator := range validators {
// if the answer's value is not valid
if err := validator(val); err != nil {
// return ... | go | func ComposeValidators(validators ...Validator) Validator {
// return a validator that calls each one sequentially
return func(val interface{}) error {
// execute each validator
for _, validator := range validators {
// if the answer's value is not valid
if err := validator(val); err != nil {
// return ... | [
"func",
"ComposeValidators",
"(",
"validators",
"...",
"Validator",
")",
"Validator",
"{",
"// return a validator that calls each one sequentially",
"return",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// execute each validator",
"for",
"_",
",",
"... | // ComposeValidators is a variadic function used to create one validator from many. | [
"ComposeValidators",
"is",
"a",
"variadic",
"function",
"used",
"to",
"create",
"one",
"validator",
"from",
"many",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L62-L76 |
149,669 | AlecAivazis/survey | validate.go | isZero | func isZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Slice, reflect.Map:
return v.Len() == 0
}
// compare the types directly with more general coverage
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
} | go | func isZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Slice, reflect.Map:
return v.Len() == 0
}
// compare the types directly with more general coverage
return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface())
} | [
"func",
"isZero",
"(",
"v",
"reflect",
".",
"Value",
")",
"bool",
"{",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
":",
"return",
"v",
".",
"Len",
"(",
")",
"==",
"0",
"\n",
"}",
"\n\n... | // isZero returns true if the passed value is the zero object | [
"isZero",
"returns",
"true",
"if",
"the",
"passed",
"value",
"is",
"the",
"zero",
"object"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/validate.go#L79-L87 |
149,670 | AlecAivazis/survey | terminal/cursor.go | Up | func (c *Cursor) Up(n int) {
fmt.Fprintf(c.Out, "\x1b[%dA", n)
} | go | func (c *Cursor) Up(n int) {
fmt.Fprintf(c.Out, "\x1b[%dA", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Up",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Up moves the cursor n cells to up. | [
"Up",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"up",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L23-L25 |
149,671 | AlecAivazis/survey | terminal/cursor.go | Down | func (c *Cursor) Down(n int) {
fmt.Fprintf(c.Out, "\x1b[%dB", n)
} | go | func (c *Cursor) Down(n int) {
fmt.Fprintf(c.Out, "\x1b[%dB", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Down",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Down moves the cursor n cells to down. | [
"Down",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"down",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L28-L30 |
149,672 | AlecAivazis/survey | terminal/cursor.go | Forward | func (c *Cursor) Forward(n int) {
fmt.Fprintf(c.Out, "\x1b[%dC", n)
} | go | func (c *Cursor) Forward(n int) {
fmt.Fprintf(c.Out, "\x1b[%dC", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Forward",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Forward moves the cursor n cells to right. | [
"Forward",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"right",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L33-L35 |
149,673 | AlecAivazis/survey | terminal/cursor.go | Back | func (c *Cursor) Back(n int) {
fmt.Fprintf(c.Out, "\x1b[%dD", n)
} | go | func (c *Cursor) Back(n int) {
fmt.Fprintf(c.Out, "\x1b[%dD", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Back",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // Back moves the cursor n cells to left. | [
"Back",
"moves",
"the",
"cursor",
"n",
"cells",
"to",
"left",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L38-L40 |
149,674 | AlecAivazis/survey | terminal/cursor.go | NextLine | func (c *Cursor) NextLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dE", n)
} | go | func (c *Cursor) NextLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dE", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"NextLine",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // NextLine moves cursor to beginning of the line n lines down. | [
"NextLine",
"moves",
"cursor",
"to",
"beginning",
"of",
"the",
"line",
"n",
"lines",
"down",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L43-L45 |
149,675 | AlecAivazis/survey | terminal/cursor.go | PreviousLine | func (c *Cursor) PreviousLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dF", n)
} | go | func (c *Cursor) PreviousLine(n int) {
fmt.Fprintf(c.Out, "\x1b[%dF", n)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"PreviousLine",
"(",
"n",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"n",
")",
"\n",
"}"
] | // PreviousLine moves cursor to beginning of the line n lines up. | [
"PreviousLine",
"moves",
"cursor",
"to",
"beginning",
"of",
"the",
"line",
"n",
"lines",
"up",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L48-L50 |
149,676 | AlecAivazis/survey | terminal/cursor.go | HorizontalAbsolute | func (c *Cursor) HorizontalAbsolute(x int) {
fmt.Fprintf(c.Out, "\x1b[%dG", x)
} | go | func (c *Cursor) HorizontalAbsolute(x int) {
fmt.Fprintf(c.Out, "\x1b[%dG", x)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"HorizontalAbsolute",
"(",
"x",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"x",
")",
"\n",
"}"
] | // HorizontalAbsolute moves cursor horizontally to x. | [
"HorizontalAbsolute",
"moves",
"cursor",
"horizontally",
"to",
"x",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L53-L55 |
149,677 | AlecAivazis/survey | terminal/cursor.go | Move | func (c *Cursor) Move(x int, y int) {
fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y)
} | go | func (c *Cursor) Move(x int, y int) {
fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Move",
"(",
"x",
"int",
",",
"y",
"int",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"Out",
",",
"\"",
"\\x1b",
"\"",
",",
"x",
",",
"y",
")",
"\n",
"}"
] | // Move moves the cursor to a specific x,y location. | [
"Move",
"moves",
"the",
"cursor",
"to",
"a",
"specific",
"x",
"y",
"location",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L68-L70 |
149,678 | AlecAivazis/survey | terminal/cursor.go | MoveNextLine | func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) {
if cur.Y == terminalSize.Y {
fmt.Fprintln(c.Out)
}
c.NextLine(1)
} | go | func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) {
if cur.Y == terminalSize.Y {
fmt.Fprintln(c.Out)
}
c.NextLine(1)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"MoveNextLine",
"(",
"cur",
"*",
"Coord",
",",
"terminalSize",
"*",
"Coord",
")",
"{",
"if",
"cur",
".",
"Y",
"==",
"terminalSize",
".",
"Y",
"{",
"fmt",
".",
"Fprintln",
"(",
"c",
".",
"Out",
")",
"\n",
"}",... | // for comparability purposes between windows
// in unix we need to print out a new line on some terminals | [
"for",
"comparability",
"purposes",
"between",
"windows",
"in",
"unix",
"we",
"need",
"to",
"print",
"out",
"a",
"new",
"line",
"on",
"some",
"terminals"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L84-L89 |
149,679 | AlecAivazis/survey | terminal/cursor.go | Location | func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) {
// ANSI escape sequence for DSR - Device Status Report
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
fmt.Fprint(c.Out, "\x1b[6n")
// There may be input in Stdin prior to CursorLocation so make sure we don't
// drop those bytes.
var ... | go | func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) {
// ANSI escape sequence for DSR - Device Status Report
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
fmt.Fprint(c.Out, "\x1b[6n")
// There may be input in Stdin prior to CursorLocation so make sure we don't
// drop those bytes.
var ... | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Location",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"(",
"*",
"Coord",
",",
"error",
")",
"{",
"// ANSI escape sequence for DSR - Device Status Report",
"// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences",
"fmt",... | // Location returns the current location of the cursor in the terminal | [
"Location",
"returns",
"the",
"current",
"location",
"of",
"the",
"cursor",
"in",
"the",
"terminal"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L92-L136 |
149,680 | AlecAivazis/survey | terminal/cursor.go | Size | func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) {
// the general approach here is to move the cursor to the very bottom
// of the terminal, ask for the current location and then move the
// cursor back where we started
// hide the cursor (so it doesn't blink when getting the size of the terminal)
c.Hide(... | go | func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) {
// the general approach here is to move the cursor to the very bottom
// of the terminal, ask for the current location and then move the
// cursor back where we started
// hide the cursor (so it doesn't blink when getting the size of the terminal)
c.Hide(... | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Size",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"(",
"*",
"Coord",
",",
"error",
")",
"{",
"// the general approach here is to move the cursor to the very bottom",
"// of the terminal, ask for the current location and then move ... | // Size returns the height and width of the terminal. | [
"Size",
"returns",
"the",
"height",
"and",
"width",
"of",
"the",
"terminal",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/cursor.go#L147-L174 |
149,681 | AlecAivazis/survey | multiselect.go | Cleanup | func (m *MultiSelect) Cleanup(val interface{}) error {
// execute the output summary template with the answer
return m.Render(
MultiSelectQuestionTemplate,
MultiSelectTemplateData{
MultiSelect: *m,
SelectedIndex: m.selectedIndex,
Checked: m.checked,
Answer: strings.Join(val.([]string), ... | go | func (m *MultiSelect) Cleanup(val interface{}) error {
// execute the output summary template with the answer
return m.Render(
MultiSelectQuestionTemplate,
MultiSelectTemplateData{
MultiSelect: *m,
SelectedIndex: m.selectedIndex,
Checked: m.checked,
Answer: strings.Join(val.([]string), ... | [
"func",
"(",
"m",
"*",
"MultiSelect",
")",
"Cleanup",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// execute the output summary template with the answer",
"return",
"m",
".",
"Render",
"(",
"MultiSelectQuestionTemplate",
",",
"MultiSelectTemplateData",
"{",... | // Cleanup removes the options section, and renders the ask like a normal question. | [
"Cleanup",
"removes",
"the",
"options",
"section",
"and",
"renders",
"the",
"ask",
"like",
"a",
"normal",
"question",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/multiselect.go#L236-L248 |
149,682 | AlecAivazis/survey | terminal/runereader_posix.go | SetTermMode | func (rr *RuneReader) SetTermMode() error {
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(rr.stdio.In.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&rr.state.term)), 0, 0, 0); err != 0 {
return err
}
newState := rr.state.term
newState.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | sys... | go | func (rr *RuneReader) SetTermMode() error {
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(rr.stdio.In.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&rr.state.term)), 0, 0, 0); err != 0 {
return err
}
newState := rr.state.term
newState.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | sys... | [
"func",
"(",
"rr",
"*",
"RuneReader",
")",
"SetTermMode",
"(",
")",
"error",
"{",
"if",
"_",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall6",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"uintptr",
"(",
"rr",
".",
"stdio",
".",
"In",
".",
"Fd",
... | // For reading runes we just want to disable echo. | [
"For",
"reading",
"runes",
"we",
"just",
"want",
"to",
"disable",
"echo",
"."
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/terminal/runereader_posix.go#L41-L54 |
149,683 | AlecAivazis/survey | confirm.go | Cleanup | func (c *Confirm) Cleanup(val interface{}) error {
// if the value was previously true
ans := yesNo(val.(bool))
// render the template
return c.Render(
ConfirmQuestionTemplate,
ConfirmTemplateData{Confirm: *c, Answer: ans},
)
} | go | func (c *Confirm) Cleanup(val interface{}) error {
// if the value was previously true
ans := yesNo(val.(bool))
// render the template
return c.Render(
ConfirmQuestionTemplate,
ConfirmTemplateData{Confirm: *c, Answer: ans},
)
} | [
"func",
"(",
"c",
"*",
"Confirm",
")",
"Cleanup",
"(",
"val",
"interface",
"{",
"}",
")",
"error",
"{",
"// if the value was previously true",
"ans",
":=",
"yesNo",
"(",
"val",
".",
"(",
"bool",
")",
")",
"\n",
"// render the template",
"return",
"c",
".",... | // Cleanup overwrite the line with the finalized formatted version | [
"Cleanup",
"overwrite",
"the",
"line",
"with",
"the",
"finalized",
"formatted",
"version"
] | a84846dc69f1fbe032f4534f92e937684b9a3710 | https://github.com/AlecAivazis/survey/blob/a84846dc69f1fbe032f4534f92e937684b9a3710/confirm.go#L130-L138 |
149,684 | golang/gddo | httputil/respbuf.go | Write | func (rb *ResponseBuffer) Write(p []byte) (int, error) {
return rb.buf.Write(p)
} | go | func (rb *ResponseBuffer) Write(p []byte) (int, error) {
return rb.buf.Write(p)
} | [
"func",
"(",
"rb",
"*",
"ResponseBuffer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"rb",
".",
"buf",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // Write implements the http.ResponseWriter interface. | [
"Write",
"implements",
"the",
"http",
".",
"ResponseWriter",
"interface",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/respbuf.go#L24-L26 |
149,685 | golang/gddo | httputil/respbuf.go | Header | func (rb *ResponseBuffer) Header() http.Header {
if rb.header == nil {
rb.header = make(http.Header)
}
return rb.header
} | go | func (rb *ResponseBuffer) Header() http.Header {
if rb.header == nil {
rb.header = make(http.Header)
}
return rb.header
} | [
"func",
"(",
"rb",
"*",
"ResponseBuffer",
")",
"Header",
"(",
")",
"http",
".",
"Header",
"{",
"if",
"rb",
".",
"header",
"==",
"nil",
"{",
"rb",
".",
"header",
"=",
"make",
"(",
"http",
".",
"Header",
")",
"\n",
"}",
"\n",
"return",
"rb",
".",
... | // Header implements the http.ResponseWriter interface. | [
"Header",
"implements",
"the",
"http",
".",
"ResponseWriter",
"interface",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/respbuf.go#L34-L39 |
149,686 | golang/gddo | httputil/httputil.go | StripPort | func StripPort(s string) string {
if h, _, err := net.SplitHostPort(s); err == nil {
s = h
}
return s
} | go | func StripPort(s string) string {
if h, _, err := net.SplitHostPort(s); err == nil {
s = h
}
return s
} | [
"func",
"StripPort",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"h",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"s",
")",
";",
"err",
"==",
"nil",
"{",
"s",
"=",
"h",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // StripPort removes the port specification from an address. | [
"StripPort",
"removes",
"the",
"port",
"specification",
"from",
"an",
"address",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/httputil.go#L16-L21 |
149,687 | golang/gddo | doc/builder.go | synopsis | func synopsis(s string) string {
parts := strings.SplitN(s, "\n\n", 2)
s = parts[0]
var buf []byte
const (
other = iota
period
space
)
last := space
Loop:
for i := 0; i < len(s); i++ {
b := s[i]
switch b {
case ' ', '\t', '\r', '\n':
switch last {
case period:
break Loop
case other:
... | go | func synopsis(s string) string {
parts := strings.SplitN(s, "\n\n", 2)
s = parts[0]
var buf []byte
const (
other = iota
period
space
)
last := space
Loop:
for i := 0; i < len(s); i++ {
b := s[i]
switch b {
case ' ', '\t', '\r', '\n':
switch last {
case period:
break Loop
case other:
... | [
"func",
"synopsis",
"(",
"s",
"string",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"2",
")",
"\n",
"s",
"=",
"parts",
"[",
"0",
"]",
"\n\n",
"var",
"buf",
"[",
"]",
"byte",
"\n",
... | // synopsis extracts the first sentence from s. All runs of whitespace are
// replaced by a single space. | [
"synopsis",
"extracts",
"the",
"first",
"sentence",
"from",
"s",
".",
"All",
"runs",
"of",
"whitespace",
"are",
"replaced",
"by",
"a",
"single",
"space",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L46-L105 |
149,688 | golang/gddo | doc/builder.go | addReferences | func addReferences(references map[string]bool, s []byte) {
for _, pat := range referencesPats {
for _, m := range pat.FindAllSubmatch(s, -1) {
p := string(m[1])
if gosrc.IsValidRemotePath(p) {
references[p] = true
}
}
}
} | go | func addReferences(references map[string]bool, s []byte) {
for _, pat := range referencesPats {
for _, m := range pat.FindAllSubmatch(s, -1) {
p := string(m[1])
if gosrc.IsValidRemotePath(p) {
references[p] = true
}
}
}
} | [
"func",
"addReferences",
"(",
"references",
"map",
"[",
"string",
"]",
"bool",
",",
"s",
"[",
"]",
"byte",
")",
"{",
"for",
"_",
",",
"pat",
":=",
"range",
"referencesPats",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"pat",
".",
"FindAllSubmatch",
"("... | // addReferences adds packages referenced in plain text s. | [
"addReferences",
"adds",
"packages",
"referenced",
"in",
"plain",
"text",
"s",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L121-L130 |
149,689 | golang/gddo | doc/builder.go | SetDefaultGOOS | func SetDefaultGOOS(goos string) {
if goos == "" {
return
}
var i int
for ; i < len(goEnvs); i++ {
if goEnvs[i].GOOS == goos {
break
}
}
switch i {
case 0:
return
case len(goEnvs):
env := goEnvs[0]
env.GOOS = goos
goEnvs = append(goEnvs, env)
}
goEnvs[0], goEnvs[i] = goEnvs[i], goEnvs[0]
} | go | func SetDefaultGOOS(goos string) {
if goos == "" {
return
}
var i int
for ; i < len(goEnvs); i++ {
if goEnvs[i].GOOS == goos {
break
}
}
switch i {
case 0:
return
case len(goEnvs):
env := goEnvs[0]
env.GOOS = goos
goEnvs = append(goEnvs, env)
}
goEnvs[0], goEnvs[i] = goEnvs[i], goEnvs[0]
} | [
"func",
"SetDefaultGOOS",
"(",
"goos",
"string",
")",
"{",
"if",
"goos",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"var",
"i",
"int",
"\n",
"for",
";",
"i",
"<",
"len",
"(",
"goEnvs",
")",
";",
"i",
"++",
"{",
"if",
"goEnvs",
"[",
"i",
... | // SetDefaultGOOS sets given GOOS value as default one to use when building
// package documents. SetDefaultGOOS has no effect on some windows-only
// packages. | [
"SetDefaultGOOS",
"sets",
"given",
"GOOS",
"value",
"as",
"default",
"one",
"to",
"use",
"when",
"building",
"package",
"documents",
".",
"SetDefaultGOOS",
"has",
"no",
"effect",
"on",
"some",
"windows",
"-",
"only",
"packages",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/doc/builder.go#L475-L494 |
149,690 | golang/gddo | httputil/header/header.go | Copy | func Copy(header http.Header) http.Header {
h := make(http.Header)
for k, vs := range header {
h[k] = vs
}
return h
} | go | func Copy(header http.Header) http.Header {
h := make(http.Header)
for k, vs := range header {
h[k] = vs
}
return h
} | [
"func",
"Copy",
"(",
"header",
"http",
".",
"Header",
")",
"http",
".",
"Header",
"{",
"h",
":=",
"make",
"(",
"http",
".",
"Header",
")",
"\n",
"for",
"k",
",",
"vs",
":=",
"range",
"header",
"{",
"h",
"[",
"k",
"]",
"=",
"vs",
"\n",
"}",
"\... | // Copy returns a shallow copy of the header. | [
"Copy",
"returns",
"a",
"shallow",
"copy",
"of",
"the",
"header",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L59-L65 |
149,691 | golang/gddo | httputil/header/header.go | ParseTime | func ParseTime(header http.Header, key string) time.Time {
if s := header.Get(key); s != "" {
for _, layout := range timeLayouts {
if t, err := time.Parse(layout, s); err == nil {
return t.UTC()
}
}
}
return time.Time{}
} | go | func ParseTime(header http.Header, key string) time.Time {
if s := header.Get(key); s != "" {
for _, layout := range timeLayouts {
if t, err := time.Parse(layout, s); err == nil {
return t.UTC()
}
}
}
return time.Time{}
} | [
"func",
"ParseTime",
"(",
"header",
"http",
".",
"Header",
",",
"key",
"string",
")",
"time",
".",
"Time",
"{",
"if",
"s",
":=",
"header",
".",
"Get",
"(",
"key",
")",
";",
"s",
"!=",
"\"",
"\"",
"{",
"for",
"_",
",",
"layout",
":=",
"range",
"... | // ParseTime parses the header as time. The zero value is returned if the
// header is not present or there is an error parsing the
// header. | [
"ParseTime",
"parses",
"the",
"header",
"as",
"time",
".",
"The",
"zero",
"value",
"is",
"returned",
"if",
"the",
"header",
"is",
"not",
"present",
"or",
"there",
"is",
"an",
"error",
"parsing",
"the",
"header",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L72-L81 |
149,692 | golang/gddo | httputil/header/header.go | ParseList | func ParseList(header http.Header, key string) []string {
var result []string
for _, s := range header[http.CanonicalHeaderKey(key)] {
begin := 0
end := 0
escape := false
quote := false
for i := 0; i < len(s); i++ {
b := s[i]
switch {
case escape:
escape = false
end = i + 1
case quote:
... | go | func ParseList(header http.Header, key string) []string {
var result []string
for _, s := range header[http.CanonicalHeaderKey(key)] {
begin := 0
end := 0
escape := false
quote := false
for i := 0; i < len(s); i++ {
b := s[i]
switch {
case escape:
escape = false
end = i + 1
case quote:
... | [
"func",
"ParseList",
"(",
"header",
"http",
".",
"Header",
",",
"key",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"header",
"[",
"http",
".",
"CanonicalHeaderKey",
"(",
"key... | // ParseList parses a comma separated list of values. Commas are ignored in
// quoted strings. Quoted values are not unescaped or unquoted. Whitespace is
// trimmed. | [
"ParseList",
"parses",
"a",
"comma",
"separated",
"list",
"of",
"values",
".",
"Commas",
"are",
"ignored",
"in",
"quoted",
"strings",
".",
"Quoted",
"values",
"are",
"not",
"unescaped",
"or",
"unquoted",
".",
"Whitespace",
"is",
"trimmed",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/header/header.go#L86-L130 |
149,693 | golang/gddo | httputil/static.go | FileHandler | func (ss *StaticServer) FileHandler(fileName string) http.Handler {
id := fileName
fileName = ss.resolve(fileName)
return &staticHandler{
ss: ss,
id: func(_ string) string { return id },
open: func(_ string) (io.ReadCloser, int64, string, error) { return ss.openFile(fileName) },
}
} | go | func (ss *StaticServer) FileHandler(fileName string) http.Handler {
id := fileName
fileName = ss.resolve(fileName)
return &staticHandler{
ss: ss,
id: func(_ string) string { return id },
open: func(_ string) (io.ReadCloser, int64, string, error) { return ss.openFile(fileName) },
}
} | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"FileHandler",
"(",
"fileName",
"string",
")",
"http",
".",
"Handler",
"{",
"id",
":=",
"fileName",
"\n",
"fileName",
"=",
"ss",
".",
"resolve",
"(",
"fileName",
")",
"\n",
"return",
"&",
"staticHandler",
"{",... | // FileHandler returns a handler that serves a single file. The file is
// specified by a slash separated path relative to the static server's Dir
// field. | [
"FileHandler",
"returns",
"a",
"handler",
"that",
"serves",
"a",
"single",
"file",
".",
"The",
"file",
"is",
"specified",
"by",
"a",
"slash",
"separated",
"path",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"field",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L96-L104 |
149,694 | golang/gddo | httputil/static.go | DirectoryHandler | func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
if !strings.HasSuffix(prefix, "/") {
prefix += "/"
}
idBase := dirName
dirName = ss.resolve(dirName)
return &staticHandler{
ss: ss,
id: func(p string) string {
if !strings.HasPrefix(p, prefix) {
return "."
}
return p... | go | func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
if !strings.HasSuffix(prefix, "/") {
prefix += "/"
}
idBase := dirName
dirName = ss.resolve(dirName)
return &staticHandler{
ss: ss,
id: func(p string) string {
if !strings.HasPrefix(p, prefix) {
return "."
}
return p... | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"DirectoryHandler",
"(",
"prefix",
",",
"dirName",
"string",
")",
"http",
".",
"Handler",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"prefix",
",",
"\"",
"\"",
")",
"{",
"prefix",
"+=",
"\"",
"\"",
... | // DirectoryHandler returns a handler that serves files from a directory tree.
// The directory is specified by a slash separated path relative to the static
// server's Dir field. | [
"DirectoryHandler",
"returns",
"a",
"handler",
"that",
"serves",
"files",
"from",
"a",
"directory",
"tree",
".",
"The",
"directory",
"is",
"specified",
"by",
"a",
"slash",
"separated",
"path",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"field",
... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L109-L131 |
149,695 | golang/gddo | httputil/static.go | FilesHandler | func (ss *StaticServer) FilesHandler(fileNames ...string) http.Handler {
// todo: cache concatenated files on disk and serve from there.
mimeType := ss.mimeType(fileNames[0])
var buf []byte
var openErr error
for _, fileName := range fileNames {
p, err := ioutil.ReadFile(ss.resolve(fileName))
if err != nil {... | go | func (ss *StaticServer) FilesHandler(fileNames ...string) http.Handler {
// todo: cache concatenated files on disk and serve from there.
mimeType := ss.mimeType(fileNames[0])
var buf []byte
var openErr error
for _, fileName := range fileNames {
p, err := ioutil.ReadFile(ss.resolve(fileName))
if err != nil {... | [
"func",
"(",
"ss",
"*",
"StaticServer",
")",
"FilesHandler",
"(",
"fileNames",
"...",
"string",
")",
"http",
".",
"Handler",
"{",
"// todo: cache concatenated files on disk and serve from there.",
"mimeType",
":=",
"ss",
".",
"mimeType",
"(",
"fileNames",
"[",
"0",
... | // FilesHandler returns a handler that serves the concatentation of the
// specified files. The files are specified by slash separated paths relative
// to the static server's Dir field. | [
"FilesHandler",
"returns",
"a",
"handler",
"that",
"serves",
"the",
"concatentation",
"of",
"the",
"specified",
"files",
".",
"The",
"files",
"are",
"specified",
"by",
"slash",
"separated",
"paths",
"relative",
"to",
"the",
"static",
"server",
"s",
"Dir",
"fie... | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/httputil/static.go#L136-L163 |
149,696 | golang/gddo | database/database.go | New | func New(serverURI string, idleTimeout time.Duration, logConn bool, gaeEndpoint string) (*Database, error) {
pool := &redis.Pool{
Dial: newDBDialer(serverURI, logConn),
MaxIdle: 10,
IdleTimeout: idleTimeout,
}
var rc *remote_api.Client
if gaeEndpoint != "" {
var err error
if rc, err = newRemot... | go | func New(serverURI string, idleTimeout time.Duration, logConn bool, gaeEndpoint string) (*Database, error) {
pool := &redis.Pool{
Dial: newDBDialer(serverURI, logConn),
MaxIdle: 10,
IdleTimeout: idleTimeout,
}
var rc *remote_api.Client
if gaeEndpoint != "" {
var err error
if rc, err = newRemot... | [
"func",
"New",
"(",
"serverURI",
"string",
",",
"idleTimeout",
"time",
".",
"Duration",
",",
"logConn",
"bool",
",",
"gaeEndpoint",
"string",
")",
"(",
"*",
"Database",
",",
"error",
")",
"{",
"pool",
":=",
"&",
"redis",
".",
"Pool",
"{",
"Dial",
":",
... | // New creates a gddo database. serverURI, idleTimeout, and logConn configure
// the use of redis. gaeEndpoint is the target of the App Engine remoteapi
// endpoint. | [
"New",
"creates",
"a",
"gddo",
"database",
".",
"serverURI",
"idleTimeout",
"and",
"logConn",
"configure",
"the",
"use",
"of",
"redis",
".",
"gaeEndpoint",
"is",
"the",
"target",
"of",
"the",
"App",
"Engine",
"remoteapi",
"endpoint",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L140-L158 |
149,697 | golang/gddo | database/database.go | pkgIDAndImportCount | func pkgIDAndImportCount(c redis.Conn, path string) (id string, numImported int, err error) {
numImported, err = redis.Int(c.Do("SCARD", "index:import:"+path))
if err != nil {
return
}
id, err = redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return "", 0, nil
} else if err != nil {
return ... | go | func pkgIDAndImportCount(c redis.Conn, path string) (id string, numImported int, err error) {
numImported, err = redis.Int(c.Do("SCARD", "index:import:"+path))
if err != nil {
return
}
id, err = redis.String(c.Do("HGET", "ids", path))
if err == redis.ErrNil {
return "", 0, nil
} else if err != nil {
return ... | [
"func",
"pkgIDAndImportCount",
"(",
"c",
"redis",
".",
"Conn",
",",
"path",
"string",
")",
"(",
"id",
"string",
",",
"numImported",
"int",
",",
"err",
"error",
")",
"{",
"numImported",
",",
"err",
"=",
"redis",
".",
"Int",
"(",
"c",
".",
"Do",
"(",
... | // pkgIDAndImportCount returns the ID and import count of a specified package. | [
"pkgIDAndImportCount",
"returns",
"the",
"ID",
"and",
"import",
"count",
"of",
"a",
"specified",
"package",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L363-L375 |
149,698 | golang/gddo | database/database.go | SetNextCrawl | func (db *Database) SetNextCrawl(path string, t time.Time) error {
c := db.Pool.Get()
defer c.Close()
_, err := setNextCrawlScript.Do(c, path, t.Unix())
return err
} | go | func (db *Database) SetNextCrawl(path string, t time.Time) error {
c := db.Pool.Get()
defer c.Close()
_, err := setNextCrawlScript.Do(c, path, t.Unix())
return err
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"SetNextCrawl",
"(",
"path",
"string",
",",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"c",
":=",
"db",
".",
"Pool",
".",
"Get",
"(",
")",
"\n",
"defer",
"c",
".",
"Close",
"(",
")",
"\n",
"_",
",",
... | // SetNextCrawl sets the next crawl time for a package. | [
"SetNextCrawl",
"sets",
"the",
"next",
"crawl",
"time",
"for",
"a",
"package",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L422-L427 |
149,699 | golang/gddo | database/database.go | Get | func (db *Database) Get(ctx context.Context, path string) (*doc.Package, []Package, time.Time, error) {
c := db.Pool.Get()
defer c.Close()
pdoc, nextCrawl, err := db.getDoc(ctx, c, path)
if err != nil {
return nil, nil, time.Time{}, err
}
if pdoc != nil {
// fixup for speclal "-" path.
path = pdoc.ImportP... | go | func (db *Database) Get(ctx context.Context, path string) (*doc.Package, []Package, time.Time, error) {
c := db.Pool.Get()
defer c.Close()
pdoc, nextCrawl, err := db.getDoc(ctx, c, path)
if err != nil {
return nil, nil, time.Time{}, err
}
if pdoc != nil {
// fixup for speclal "-" path.
path = pdoc.ImportP... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"(",
"*",
"doc",
".",
"Package",
",",
"[",
"]",
"Package",
",",
"time",
".",
"Time",
",",
"error",
")",
"{",
"c",
":=",
"db",
"."... | // Get gets the package documentation and sub-directories for the the given
// import path. | [
"Get",
"gets",
"the",
"package",
"documentation",
"and",
"sub",
"-",
"directories",
"for",
"the",
"the",
"given",
"import",
"path",
"."
] | af0f2af80721261f4d211b2c9563f7b46b2aab06 | https://github.com/golang/gddo/blob/af0f2af80721261f4d211b2c9563f7b46b2aab06/database/database.go#L588-L607 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.