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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
27,200 | square/certstrap | depot/pkix.go | CheckCertificateSigningRequest | func CheckCertificateSigningRequest(d Depot, name string) bool {
return d.Check(CsrTag(name))
} | go | func CheckCertificateSigningRequest(d Depot, name string) bool {
return d.Check(CsrTag(name))
} | [
"func",
"CheckCertificateSigningRequest",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"bool",
"{",
"return",
"d",
".",
"Check",
"(",
"CsrTag",
"(",
"name",
")",
")",
"\n",
"}"
] | // CheckCertificateSigningRequest checks the depot for existence of a certificate signing request file for a given host name | [
"CheckCertificateSigningRequest",
"checks",
"the",
"depot",
"for",
"existence",
"of",
"a",
"certificate",
"signing",
"request",
"file",
"for",
"a",
"given",
"host",
"name"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L105-L107 |
27,201 | square/certstrap | depot/pkix.go | GetCertificateSigningRequest | func GetCertificateSigningRequest(d Depot, name string) (crt *pkix.CertificateSigningRequest, err error) {
b, err := d.Get(CsrTag(name))
if err != nil {
return nil, err
}
return pkix.NewCertificateSigningRequestFromPEM(b)
} | go | func GetCertificateSigningRequest(d Depot, name string) (crt *pkix.CertificateSigningRequest, err error) {
b, err := d.Get(CsrTag(name))
if err != nil {
return nil, err
}
return pkix.NewCertificateSigningRequestFromPEM(b)
} | [
"func",
"GetCertificateSigningRequest",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"(",
"crt",
"*",
"pkix",
".",
"CertificateSigningRequest",
",",
"err",
"error",
")",
"{",
"b",
",",
"err",
":=",
"d",
".",
"Get",
"(",
"CsrTag",
"(",
"name",
")",
")... | // GetCertificateSigningRequest retrieves a certificate signing request file for a given host name from the depot | [
"GetCertificateSigningRequest",
"retrieves",
"a",
"certificate",
"signing",
"request",
"file",
"for",
"a",
"given",
"host",
"name",
"from",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L110-L116 |
27,202 | square/certstrap | depot/pkix.go | DeleteCertificateSigningRequest | func DeleteCertificateSigningRequest(d Depot, name string) error {
return d.Delete(CsrTag(name))
} | go | func DeleteCertificateSigningRequest(d Depot, name string) error {
return d.Delete(CsrTag(name))
} | [
"func",
"DeleteCertificateSigningRequest",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"error",
"{",
"return",
"d",
".",
"Delete",
"(",
"CsrTag",
"(",
"name",
")",
")",
"\n",
"}"
] | // DeleteCertificateSigningRequest removes a certificate signing request file for a given host name from the depot | [
"DeleteCertificateSigningRequest",
"removes",
"a",
"certificate",
"signing",
"request",
"file",
"for",
"a",
"given",
"host",
"name",
"from",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L119-L121 |
27,203 | square/certstrap | depot/pkix.go | PutPrivateKey | func PutPrivateKey(d Depot, name string, key *pkix.Key) error {
b, err := key.ExportPrivate()
if err != nil {
return err
}
return d.Put(PrivKeyTag(name), b)
} | go | func PutPrivateKey(d Depot, name string, key *pkix.Key) error {
b, err := key.ExportPrivate()
if err != nil {
return err
}
return d.Put(PrivKeyTag(name), b)
} | [
"func",
"PutPrivateKey",
"(",
"d",
"Depot",
",",
"name",
"string",
",",
"key",
"*",
"pkix",
".",
"Key",
")",
"error",
"{",
"b",
",",
"err",
":=",
"key",
".",
"ExportPrivate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | // PutPrivateKey creates a private key file for a given name in the depot | [
"PutPrivateKey",
"creates",
"a",
"private",
"key",
"file",
"for",
"a",
"given",
"name",
"in",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L124-L130 |
27,204 | square/certstrap | depot/pkix.go | CheckPrivateKey | func CheckPrivateKey(d Depot, name string) bool {
return d.Check(PrivKeyTag(name))
} | go | func CheckPrivateKey(d Depot, name string) bool {
return d.Check(PrivKeyTag(name))
} | [
"func",
"CheckPrivateKey",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"bool",
"{",
"return",
"d",
".",
"Check",
"(",
"PrivKeyTag",
"(",
"name",
")",
")",
"\n",
"}"
] | // CheckPrivateKey checks the depot for existence of a private key file for a given name | [
"CheckPrivateKey",
"checks",
"the",
"depot",
"for",
"existence",
"of",
"a",
"private",
"key",
"file",
"for",
"a",
"given",
"name"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L133-L135 |
27,205 | square/certstrap | depot/pkix.go | GetPrivateKey | func GetPrivateKey(d Depot, name string) (key *pkix.Key, err error) {
b, err := d.Get(PrivKeyTag(name))
if err != nil {
return nil, err
}
return pkix.NewKeyFromPrivateKeyPEM(b)
} | go | func GetPrivateKey(d Depot, name string) (key *pkix.Key, err error) {
b, err := d.Get(PrivKeyTag(name))
if err != nil {
return nil, err
}
return pkix.NewKeyFromPrivateKeyPEM(b)
} | [
"func",
"GetPrivateKey",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"(",
"key",
"*",
"pkix",
".",
"Key",
",",
"err",
"error",
")",
"{",
"b",
",",
"err",
":=",
"d",
".",
"Get",
"(",
"PrivKeyTag",
"(",
"name",
")",
")",
"\n",
"if",
"err",
"!=... | // GetPrivateKey retrieves a private key file for a given name from the depot | [
"GetPrivateKey",
"retrieves",
"a",
"private",
"key",
"file",
"for",
"a",
"given",
"name",
"from",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L138-L144 |
27,206 | square/certstrap | depot/pkix.go | PutEncryptedPrivateKey | func PutEncryptedPrivateKey(d Depot, name string, key *pkix.Key, passphrase []byte) error {
b, err := key.ExportEncryptedPrivate(passphrase)
if err != nil {
return err
}
return d.Put(PrivKeyTag(name), b)
} | go | func PutEncryptedPrivateKey(d Depot, name string, key *pkix.Key, passphrase []byte) error {
b, err := key.ExportEncryptedPrivate(passphrase)
if err != nil {
return err
}
return d.Put(PrivKeyTag(name), b)
} | [
"func",
"PutEncryptedPrivateKey",
"(",
"d",
"Depot",
",",
"name",
"string",
",",
"key",
"*",
"pkix",
".",
"Key",
",",
"passphrase",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
",",
"err",
":=",
"key",
".",
"ExportEncryptedPrivate",
"(",
"passphrase",
")",
... | // PutEncryptedPrivateKey creates an encrypted private key file for a given name in the depot | [
"PutEncryptedPrivateKey",
"creates",
"an",
"encrypted",
"private",
"key",
"file",
"for",
"a",
"given",
"name",
"in",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L147-L153 |
27,207 | square/certstrap | depot/pkix.go | GetEncryptedPrivateKey | func GetEncryptedPrivateKey(d Depot, name string, passphrase []byte) (key *pkix.Key, err error) {
b, err := d.Get(PrivKeyTag(name))
if err != nil {
return nil, err
}
return pkix.NewKeyFromEncryptedPrivateKeyPEM(b, passphrase)
} | go | func GetEncryptedPrivateKey(d Depot, name string, passphrase []byte) (key *pkix.Key, err error) {
b, err := d.Get(PrivKeyTag(name))
if err != nil {
return nil, err
}
return pkix.NewKeyFromEncryptedPrivateKeyPEM(b, passphrase)
} | [
"func",
"GetEncryptedPrivateKey",
"(",
"d",
"Depot",
",",
"name",
"string",
",",
"passphrase",
"[",
"]",
"byte",
")",
"(",
"key",
"*",
"pkix",
".",
"Key",
",",
"err",
"error",
")",
"{",
"b",
",",
"err",
":=",
"d",
".",
"Get",
"(",
"PrivKeyTag",
"("... | // GetEncryptedPrivateKey retrieves an encrypted private key file for a given name from the depot | [
"GetEncryptedPrivateKey",
"retrieves",
"an",
"encrypted",
"private",
"key",
"file",
"for",
"a",
"given",
"name",
"from",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L156-L162 |
27,208 | square/certstrap | depot/pkix.go | PutCertificateRevocationList | func PutCertificateRevocationList(d Depot, name string, crl *pkix.CertificateRevocationList) error {
b, err := crl.Export()
if err != nil {
return err
}
return d.Put(CrlTag(name), b)
} | go | func PutCertificateRevocationList(d Depot, name string, crl *pkix.CertificateRevocationList) error {
b, err := crl.Export()
if err != nil {
return err
}
return d.Put(CrlTag(name), b)
} | [
"func",
"PutCertificateRevocationList",
"(",
"d",
"Depot",
",",
"name",
"string",
",",
"crl",
"*",
"pkix",
".",
"CertificateRevocationList",
")",
"error",
"{",
"b",
",",
"err",
":=",
"crl",
".",
"Export",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // PutCertificateRevocationList creates a CRL file for a given name and ca in the depot | [
"PutCertificateRevocationList",
"creates",
"a",
"CRL",
"file",
"for",
"a",
"given",
"name",
"and",
"ca",
"in",
"the",
"depot"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L165-L171 |
27,209 | square/certstrap | depot/pkix.go | GetCertificateRevocationList | func GetCertificateRevocationList(d Depot, name string) (*pkix.CertificateRevocationList, error) {
b, err := d.Get(CrlTag(name))
if err != nil {
return nil, err
}
return pkix.NewCertificateRevocationListFromPEM(b)
} | go | func GetCertificateRevocationList(d Depot, name string) (*pkix.CertificateRevocationList, error) {
b, err := d.Get(CrlTag(name))
if err != nil {
return nil, err
}
return pkix.NewCertificateRevocationListFromPEM(b)
} | [
"func",
"GetCertificateRevocationList",
"(",
"d",
"Depot",
",",
"name",
"string",
")",
"(",
"*",
"pkix",
".",
"CertificateRevocationList",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"d",
".",
"Get",
"(",
"CrlTag",
"(",
"name",
")",
")",
"\n",
"if",... | //GetCertificateRevocationList gets a CRL file for a given name and ca in the depot. | [
"GetCertificateRevocationList",
"gets",
"a",
"CRL",
"file",
"for",
"a",
"given",
"name",
"and",
"ca",
"in",
"the",
"depot",
"."
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/depot/pkix.go#L174-L180 |
27,210 | square/certstrap | cmd/init.go | NewInitCommand | func NewInitCommand() cli.Command {
return cli.Command{
Name: "init",
Usage: "Create Certificate Authority",
Description: "Create Certificate Authority, including certificate, key and extra information file.",
Flags: []cli.Flag{
cli.StringFlag{
Name: "passphrase",
Usage: "Passphrase to... | go | func NewInitCommand() cli.Command {
return cli.Command{
Name: "init",
Usage: "Create Certificate Authority",
Description: "Create Certificate Authority, including certificate, key and extra information file.",
Flags: []cli.Flag{
cli.StringFlag{
Name: "passphrase",
Usage: "Passphrase to... | [
"func",
"NewInitCommand",
"(",
")",
"cli",
".",
"Command",
"{",
"return",
"cli",
".",
"Command",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Description",
":",
"\"",
"\"",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{... | // NewInitCommand sets up an "init" command to initialize a new CA | [
"NewInitCommand",
"sets",
"up",
"an",
"init",
"command",
"to",
"initialize",
"a",
"new",
"CA"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/cmd/init.go#L32-L91 |
27,211 | square/certstrap | pkix/cert_info.go | NewCertificateAuthorityInfoFromJSON | func NewCertificateAuthorityInfoFromJSON(data []byte) (*CertificateAuthorityInfo, error) {
i := big.NewInt(0)
if err := i.UnmarshalJSON(data); err != nil {
return nil, err
}
return &CertificateAuthorityInfo{i}, nil
} | go | func NewCertificateAuthorityInfoFromJSON(data []byte) (*CertificateAuthorityInfo, error) {
i := big.NewInt(0)
if err := i.UnmarshalJSON(data); err != nil {
return nil, err
}
return &CertificateAuthorityInfo{i}, nil
} | [
"func",
"NewCertificateAuthorityInfoFromJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"CertificateAuthorityInfo",
",",
"error",
")",
"{",
"i",
":=",
"big",
".",
"NewInt",
"(",
"0",
")",
"\n\n",
"if",
"err",
":=",
"i",
".",
"UnmarshalJSON",
"(",
"d... | // NewCertificateAuthorityInfoFromJSON creates a new CertifaceAuthorityInfo with the given JSON information | [
"NewCertificateAuthorityInfoFromJSON",
"creates",
"a",
"new",
"CertifaceAuthorityInfo",
"with",
"the",
"given",
"JSON",
"information"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/cert_info.go#L37-L45 |
27,212 | square/certstrap | pkix/cert_info.go | IncSerialNumber | func (n *CertificateAuthorityInfo) IncSerialNumber() {
n.SerialNumber.Add(n.SerialNumber, big.NewInt(1))
} | go | func (n *CertificateAuthorityInfo) IncSerialNumber() {
n.SerialNumber.Add(n.SerialNumber, big.NewInt(1))
} | [
"func",
"(",
"n",
"*",
"CertificateAuthorityInfo",
")",
"IncSerialNumber",
"(",
")",
"{",
"n",
".",
"SerialNumber",
".",
"Add",
"(",
"n",
".",
"SerialNumber",
",",
"big",
".",
"NewInt",
"(",
"1",
")",
")",
"\n",
"}"
] | // IncSerialNumber increments the given CA Info's serial number | [
"IncSerialNumber",
"increments",
"the",
"given",
"CA",
"Info",
"s",
"serial",
"number"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/cert_info.go#L48-L50 |
27,213 | square/certstrap | pkix/key.go | CreateRSAKey | func CreateRSAKey(rsaBits int) (*Key, error) {
priv, err := rsa.GenerateKey(rand.Reader, rsaBits)
if err != nil {
return nil, err
}
return NewKey(&priv.PublicKey, priv), nil
} | go | func CreateRSAKey(rsaBits int) (*Key, error) {
priv, err := rsa.GenerateKey(rand.Reader, rsaBits)
if err != nil {
return nil, err
}
return NewKey(&priv.PublicKey, priv), nil
} | [
"func",
"CreateRSAKey",
"(",
"rsaBits",
"int",
")",
"(",
"*",
"Key",
",",
"error",
")",
"{",
"priv",
",",
"err",
":=",
"rsa",
".",
"GenerateKey",
"(",
"rand",
".",
"Reader",
",",
"rsaBits",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",... | // CreateRSAKey creates a new Key using RSA algorithm | [
"CreateRSAKey",
"creates",
"a",
"new",
"Key",
"using",
"RSA",
"algorithm"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L38-L45 |
27,214 | square/certstrap | pkix/key.go | NewKey | func NewKey(pub crypto.PublicKey, priv crypto.PrivateKey) *Key {
return &Key{Public: pub, Private: priv}
} | go | func NewKey(pub crypto.PublicKey, priv crypto.PrivateKey) *Key {
return &Key{Public: pub, Private: priv}
} | [
"func",
"NewKey",
"(",
"pub",
"crypto",
".",
"PublicKey",
",",
"priv",
"crypto",
".",
"PrivateKey",
")",
"*",
"Key",
"{",
"return",
"&",
"Key",
"{",
"Public",
":",
"pub",
",",
"Private",
":",
"priv",
"}",
"\n",
"}"
] | // NewKey returns a new public-private keypair Key type | [
"NewKey",
"returns",
"a",
"new",
"public",
"-",
"private",
"keypair",
"Key",
"type"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L54-L56 |
27,215 | square/certstrap | pkix/key.go | NewKeyFromPrivateKeyPEM | func NewKeyFromPrivateKeyPEM(data []byte) (*Key, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if pemBlock.Type != rsaPrivateKeyPEMBlockType || len(pemBlock.Headers) != 0 {
return nil, errors.New("unmatched type or headers")
}... | go | func NewKeyFromPrivateKeyPEM(data []byte) (*Key, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if pemBlock.Type != rsaPrivateKeyPEMBlockType || len(pemBlock.Headers) != 0 {
return nil, errors.New("unmatched type or headers")
}... | [
"func",
"NewKeyFromPrivateKeyPEM",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Key",
",",
"error",
")",
"{",
"pemBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"data",
")",
"\n",
"if",
"pemBlock",
"==",
"nil",
"{",
"return",
"nil",
",",
"err... | // NewKeyFromPrivateKeyPEM inits Key from PEM-format rsa private key bytes | [
"NewKeyFromPrivateKeyPEM",
"inits",
"Key",
"from",
"PEM",
"-",
"format",
"rsa",
"private",
"key",
"bytes"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L59-L74 |
27,216 | square/certstrap | pkix/key.go | NewKeyFromEncryptedPrivateKeyPEM | func NewKeyFromEncryptedPrivateKeyPEM(data []byte, password []byte) (*Key, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if pemBlock.Type != rsaPrivateKeyPEMBlockType {
return nil, errors.New("unmatched type or headers")
}
b... | go | func NewKeyFromEncryptedPrivateKeyPEM(data []byte, password []byte) (*Key, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if pemBlock.Type != rsaPrivateKeyPEMBlockType {
return nil, errors.New("unmatched type or headers")
}
b... | [
"func",
"NewKeyFromEncryptedPrivateKeyPEM",
"(",
"data",
"[",
"]",
"byte",
",",
"password",
"[",
"]",
"byte",
")",
"(",
"*",
"Key",
",",
"error",
")",
"{",
"pemBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"data",
")",
"\n",
"if",
"pemBlock",
"=... | // NewKeyFromEncryptedPrivateKeyPEM inits Key from encrypted PEM-format rsa private key bytes | [
"NewKeyFromEncryptedPrivateKeyPEM",
"inits",
"Key",
"from",
"encrypted",
"PEM",
"-",
"format",
"rsa",
"private",
"key",
"bytes"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L77-L97 |
27,217 | square/certstrap | pkix/key.go | ExportPrivate | func (k *Key) ExportPrivate() ([]byte, error) {
var privPEMBlock *pem.Block
switch priv := k.Private.(type) {
case *rsa.PrivateKey:
privBytes := x509.MarshalPKCS1PrivateKey(priv)
privPEMBlock = &pem.Block{
Type: rsaPrivateKeyPEMBlockType,
Bytes: privBytes,
}
default:
return nil, errors.New("only RSA ... | go | func (k *Key) ExportPrivate() ([]byte, error) {
var privPEMBlock *pem.Block
switch priv := k.Private.(type) {
case *rsa.PrivateKey:
privBytes := x509.MarshalPKCS1PrivateKey(priv)
privPEMBlock = &pem.Block{
Type: rsaPrivateKeyPEMBlockType,
Bytes: privBytes,
}
default:
return nil, errors.New("only RSA ... | [
"func",
"(",
"k",
"*",
"Key",
")",
"ExportPrivate",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"privPEMBlock",
"*",
"pem",
".",
"Block",
"\n",
"switch",
"priv",
":=",
"k",
".",
"Private",
".",
"(",
"type",
")",
"{",
"case",
... | // ExportPrivate exports PEM-format private key | [
"ExportPrivate",
"exports",
"PEM",
"-",
"format",
"private",
"key"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L100-L118 |
27,218 | square/certstrap | pkix/key.go | ExportEncryptedPrivate | func (k *Key) ExportEncryptedPrivate(password []byte) ([]byte, error) {
var privBytes []byte
switch priv := k.Private.(type) {
case *rsa.PrivateKey:
privBytes = x509.MarshalPKCS1PrivateKey(priv)
default:
return nil, errors.New("only RSA private key is supported")
}
privPEMBlock, err := x509.EncryptPEMBlock(r... | go | func (k *Key) ExportEncryptedPrivate(password []byte) ([]byte, error) {
var privBytes []byte
switch priv := k.Private.(type) {
case *rsa.PrivateKey:
privBytes = x509.MarshalPKCS1PrivateKey(priv)
default:
return nil, errors.New("only RSA private key is supported")
}
privPEMBlock, err := x509.EncryptPEMBlock(r... | [
"func",
"(",
"k",
"*",
"Key",
")",
"ExportEncryptedPrivate",
"(",
"password",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"privBytes",
"[",
"]",
"byte",
"\n",
"switch",
"priv",
":=",
"k",
".",
"Private",
".",
"(",
... | // ExportEncryptedPrivate exports encrypted PEM-format private key | [
"ExportEncryptedPrivate",
"exports",
"encrypted",
"PEM",
"-",
"format",
"private",
"key"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L121-L140 |
27,219 | square/certstrap | pkix/key.go | GenerateSubjectKeyID | func GenerateSubjectKeyID(pub crypto.PublicKey) ([]byte, error) {
var pubBytes []byte
var err error
switch pub := pub.(type) {
case *rsa.PublicKey:
pubBytes, err = asn1.Marshal(rsaPublicKey{
N: pub.N,
E: pub.E,
})
if err != nil {
return nil, err
}
default:
return nil, errors.New("only RSA public... | go | func GenerateSubjectKeyID(pub crypto.PublicKey) ([]byte, error) {
var pubBytes []byte
var err error
switch pub := pub.(type) {
case *rsa.PublicKey:
pubBytes, err = asn1.Marshal(rsaPublicKey{
N: pub.N,
E: pub.E,
})
if err != nil {
return nil, err
}
default:
return nil, errors.New("only RSA public... | [
"func",
"GenerateSubjectKeyID",
"(",
"pub",
"crypto",
".",
"PublicKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"pubBytes",
"[",
"]",
"byte",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"pub",
":=",
"pub",
".",
"(",
"type",
")",
... | // GenerateSubjectKeyID generates SubjectKeyId used in Certificate
// Id is 160-bit SHA-1 hash of the value of the BIT STRING subjectPublicKey | [
"GenerateSubjectKeyID",
"generates",
"SubjectKeyId",
"used",
"in",
"Certificate",
"Id",
"is",
"160",
"-",
"bit",
"SHA",
"-",
"1",
"hash",
"of",
"the",
"value",
"of",
"the",
"BIT",
"STRING",
"subjectPublicKey"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/key.go#L150-L169 |
27,220 | square/certstrap | pkix/csr.go | ParseAndValidateIPs | func ParseAndValidateIPs(ipList string) (res []net.IP, err error) {
// IP list can potentially be a blank string, ""
if len(ipList) > 0 {
ips := strings.Split(ipList, ",")
for _, ip := range ips {
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return nil, fmt.Errorf("Invalid IP address: %s", ip)
}
... | go | func ParseAndValidateIPs(ipList string) (res []net.IP, err error) {
// IP list can potentially be a blank string, ""
if len(ipList) > 0 {
ips := strings.Split(ipList, ",")
for _, ip := range ips {
parsedIP := net.ParseIP(ip)
if parsedIP == nil {
return nil, fmt.Errorf("Invalid IP address: %s", ip)
}
... | [
"func",
"ParseAndValidateIPs",
"(",
"ipList",
"string",
")",
"(",
"res",
"[",
"]",
"net",
".",
"IP",
",",
"err",
"error",
")",
"{",
"// IP list can potentially be a blank string, \"\"",
"if",
"len",
"(",
"ipList",
")",
">",
"0",
"{",
"ips",
":=",
"strings",
... | // ParseAndValidateIPs parses a comma-delimited list of IP addresses into an array of IP addresses | [
"ParseAndValidateIPs",
"parses",
"a",
"comma",
"-",
"delimited",
"list",
"of",
"IP",
"addresses",
"into",
"an",
"array",
"of",
"IP",
"addresses"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L58-L71 |
27,221 | square/certstrap | pkix/csr.go | ParseAndValidateURIs | func ParseAndValidateURIs(uriList string) (res []*url.URL, err error) {
if len(uriList) > 0 {
uris := strings.Split(uriList, ",")
for _, uri := range uris {
parsedURI, err := url.Parse(uri)
if err != nil {
parsedURI = nil
}
if parsedURI == nil {
return nil, fmt.Errorf("Invalid URI: %s", uri)
... | go | func ParseAndValidateURIs(uriList string) (res []*url.URL, err error) {
if len(uriList) > 0 {
uris := strings.Split(uriList, ",")
for _, uri := range uris {
parsedURI, err := url.Parse(uri)
if err != nil {
parsedURI = nil
}
if parsedURI == nil {
return nil, fmt.Errorf("Invalid URI: %s", uri)
... | [
"func",
"ParseAndValidateURIs",
"(",
"uriList",
"string",
")",
"(",
"res",
"[",
"]",
"*",
"url",
".",
"URL",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"uriList",
")",
">",
"0",
"{",
"uris",
":=",
"strings",
".",
"Split",
"(",
"uriList",
",",... | // ParseAndValidateURIs parses a comma-delimited list of URIs into an array of url.URLs | [
"ParseAndValidateURIs",
"parses",
"a",
"comma",
"-",
"delimited",
"list",
"of",
"URIs",
"into",
"an",
"array",
"of",
"url",
".",
"URLs"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L74-L92 |
27,222 | square/certstrap | pkix/csr.go | CreateCertificateSigningRequest | func CreateCertificateSigningRequest(key *Key, organizationalUnit string, ipList []net.IP, domainList []string, uriList []*url.URL, organization string, country string, province string, locality string, commonName string) (*CertificateSigningRequest, error) {
csrPkixName.CommonName = commonName
if len(organizationa... | go | func CreateCertificateSigningRequest(key *Key, organizationalUnit string, ipList []net.IP, domainList []string, uriList []*url.URL, organization string, country string, province string, locality string, commonName string) (*CertificateSigningRequest, error) {
csrPkixName.CommonName = commonName
if len(organizationa... | [
"func",
"CreateCertificateSigningRequest",
"(",
"key",
"*",
"Key",
",",
"organizationalUnit",
"string",
",",
"ipList",
"[",
"]",
"net",
".",
"IP",
",",
"domainList",
"[",
"]",
"string",
",",
"uriList",
"[",
"]",
"*",
"url",
".",
"URL",
",",
"organization",... | // CreateCertificateSigningRequest sets up a request to create a csr file with the given parameters | [
"CreateCertificateSigningRequest",
"sets",
"up",
"a",
"request",
"to",
"create",
"a",
"csr",
"file",
"with",
"the",
"given",
"parameters"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L95-L126 |
27,223 | square/certstrap | pkix/csr.go | NewCertificateSigningRequestFromPEM | func NewCertificateSigningRequestFromPEM(data []byte) (*CertificateSigningRequest, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if (pemBlock.Type != csrPEMBlockType && pemBlock.Type != oldCsrPEMBlockType) || len(pemBlock.Headers... | go | func NewCertificateSigningRequestFromPEM(data []byte) (*CertificateSigningRequest, error) {
pemBlock, _ := pem.Decode(data)
if pemBlock == nil {
return nil, errors.New("cannot find the next PEM formatted block")
}
if (pemBlock.Type != csrPEMBlockType && pemBlock.Type != oldCsrPEMBlockType) || len(pemBlock.Headers... | [
"func",
"NewCertificateSigningRequestFromPEM",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"CertificateSigningRequest",
",",
"error",
")",
"{",
"pemBlock",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"data",
")",
"\n",
"if",
"pemBlock",
"==",
"nil",
"{",
... | // NewCertificateSigningRequestFromPEM inits CertificateSigningRequest from PEM-format bytes
// data should contain at most one certificate | [
"NewCertificateSigningRequestFromPEM",
"inits",
"CertificateSigningRequest",
"from",
"PEM",
"-",
"format",
"bytes",
"data",
"should",
"contain",
"at",
"most",
"one",
"certificate"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L143-L152 |
27,224 | square/certstrap | pkix/csr.go | buildPKCS10CertificateSigningRequest | func (c *CertificateSigningRequest) buildPKCS10CertificateSigningRequest() error {
if c.cr != nil {
return nil
}
var err error
c.cr, err = x509.ParseCertificateRequest(c.derBytes)
if err != nil {
return err
}
return nil
} | go | func (c *CertificateSigningRequest) buildPKCS10CertificateSigningRequest() error {
if c.cr != nil {
return nil
}
var err error
c.cr, err = x509.ParseCertificateRequest(c.derBytes)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"CertificateSigningRequest",
")",
"buildPKCS10CertificateSigningRequest",
"(",
")",
"error",
"{",
"if",
"c",
".",
"cr",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"c",
".",
"cr",
",",
"err",
... | // build cr field if needed | [
"build",
"cr",
"field",
"if",
"needed"
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L155-L166 |
27,225 | square/certstrap | pkix/csr.go | GetRawCertificateSigningRequest | func (c *CertificateSigningRequest) GetRawCertificateSigningRequest() (*x509.CertificateRequest, error) {
if err := c.buildPKCS10CertificateSigningRequest(); err != nil {
return nil, err
}
return c.cr, nil
} | go | func (c *CertificateSigningRequest) GetRawCertificateSigningRequest() (*x509.CertificateRequest, error) {
if err := c.buildPKCS10CertificateSigningRequest(); err != nil {
return nil, err
}
return c.cr, nil
} | [
"func",
"(",
"c",
"*",
"CertificateSigningRequest",
")",
"GetRawCertificateSigningRequest",
"(",
")",
"(",
"*",
"x509",
".",
"CertificateRequest",
",",
"error",
")",
"{",
"if",
"err",
":=",
"c",
".",
"buildPKCS10CertificateSigningRequest",
"(",
")",
";",
"err",
... | // GetRawCertificateSigningRequest returns a copy of this certificate request as an x509.CertificateRequest. | [
"GetRawCertificateSigningRequest",
"returns",
"a",
"copy",
"of",
"this",
"certificate",
"request",
"as",
"an",
"x509",
".",
"CertificateRequest",
"."
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L169-L174 |
27,226 | square/certstrap | pkix/csr.go | CheckSignature | func (c *CertificateSigningRequest) CheckSignature() error {
if err := c.buildPKCS10CertificateSigningRequest(); err != nil {
return err
}
return checkSignature(c.cr, c.cr.SignatureAlgorithm, c.cr.RawTBSCertificateRequest, c.cr.Signature)
} | go | func (c *CertificateSigningRequest) CheckSignature() error {
if err := c.buildPKCS10CertificateSigningRequest(); err != nil {
return err
}
return checkSignature(c.cr, c.cr.SignatureAlgorithm, c.cr.RawTBSCertificateRequest, c.cr.Signature)
} | [
"func",
"(",
"c",
"*",
"CertificateSigningRequest",
")",
"CheckSignature",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"buildPKCS10CertificateSigningRequest",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"che... | // CheckSignature verifies that the signature is a valid signature
// using the public key in CertificateSigningRequest. | [
"CheckSignature",
"verifies",
"that",
"the",
"signature",
"is",
"a",
"valid",
"signature",
"using",
"the",
"public",
"key",
"in",
"CertificateSigningRequest",
"."
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L178-L183 |
27,227 | square/certstrap | pkix/csr.go | checkSignature | func checkSignature(csr *x509.CertificateRequest, algo x509.SignatureAlgorithm, signed, signature []byte) error {
var hashType crypto.Hash
switch algo {
case x509.SHA1WithRSA, x509.ECDSAWithSHA1:
hashType = crypto.SHA1
case x509.SHA256WithRSA, x509.ECDSAWithSHA256:
hashType = crypto.SHA256
case x509.SHA384With... | go | func checkSignature(csr *x509.CertificateRequest, algo x509.SignatureAlgorithm, signed, signature []byte) error {
var hashType crypto.Hash
switch algo {
case x509.SHA1WithRSA, x509.ECDSAWithSHA1:
hashType = crypto.SHA1
case x509.SHA256WithRSA, x509.ECDSAWithSHA256:
hashType = crypto.SHA256
case x509.SHA384With... | [
"func",
"checkSignature",
"(",
"csr",
"*",
"x509",
".",
"CertificateRequest",
",",
"algo",
"x509",
".",
"SignatureAlgorithm",
",",
"signed",
",",
"signature",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"hashType",
"crypto",
".",
"Hash",
"\n",
"switch",
"a... | // checkSignature verifies a signature made by the key on a CSR, such
// as on the CSR itself. | [
"checkSignature",
"verifies",
"a",
"signature",
"made",
"by",
"the",
"key",
"on",
"a",
"CSR",
"such",
"as",
"on",
"the",
"CSR",
"itself",
"."
] | 350df15b3713d535548735ea754726228b00c742 | https://github.com/square/certstrap/blob/350df15b3713d535548735ea754726228b00c742/pkix/csr.go#L187-L224 |
27,228 | rylio/ytdl | video_info.go | GetVideoInfo | func GetVideoInfo(value interface{}) (*VideoInfo, error) {
switch t := value.(type) {
case *url.URL:
return GetVideoInfoFromURL(t)
case string:
u, err := url.ParseRequestURI(t)
if err != nil {
return GetVideoInfoFromID(t)
}
if u.Host == "youtu.be" {
return GetVideoInfoFromShortURL(u)
}
return Get... | go | func GetVideoInfo(value interface{}) (*VideoInfo, error) {
switch t := value.(type) {
case *url.URL:
return GetVideoInfoFromURL(t)
case string:
u, err := url.ParseRequestURI(t)
if err != nil {
return GetVideoInfoFromID(t)
}
if u.Host == "youtu.be" {
return GetVideoInfoFromShortURL(u)
}
return Get... | [
"func",
"GetVideoInfo",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"*",
"VideoInfo",
",",
"error",
")",
"{",
"switch",
"t",
":=",
"value",
".",
"(",
"type",
")",
"{",
"case",
"*",
"url",
".",
"URL",
":",
"return",
"GetVideoInfoFromURL",
"(",
"t",... | // GetVideoInfo fetches info from a url string, url object, or a url string | [
"GetVideoInfo",
"fetches",
"info",
"from",
"a",
"url",
"string",
"url",
"object",
"or",
"a",
"url",
"string"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L51-L67 |
27,229 | rylio/ytdl | video_info.go | GetVideoInfoFromURL | func GetVideoInfoFromURL(u *url.URL) (*VideoInfo, error) {
videoID := u.Query().Get("v")
if len(videoID) == 0 {
return nil, fmt.Errorf("Invalid youtube url, no video id")
}
return GetVideoInfoFromID(videoID)
} | go | func GetVideoInfoFromURL(u *url.URL) (*VideoInfo, error) {
videoID := u.Query().Get("v")
if len(videoID) == 0 {
return nil, fmt.Errorf("Invalid youtube url, no video id")
}
return GetVideoInfoFromID(videoID)
} | [
"func",
"GetVideoInfoFromURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"VideoInfo",
",",
"error",
")",
"{",
"videoID",
":=",
"u",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"videoID",
")",
"==",
"... | // GetVideoInfoFromURL fetches video info from a youtube url | [
"GetVideoInfoFromURL",
"fetches",
"video",
"info",
"from",
"a",
"youtube",
"url"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L70-L76 |
27,230 | rylio/ytdl | video_info.go | GetVideoInfoFromShortURL | func GetVideoInfoFromShortURL(u *url.URL) (*VideoInfo, error) {
if len(u.Path) >= 1 {
if path := u.Path[1:]; path != "" {
return GetVideoInfoFromID(path)
}
}
return nil, errors.New("Could not parse short URL")
} | go | func GetVideoInfoFromShortURL(u *url.URL) (*VideoInfo, error) {
if len(u.Path) >= 1 {
if path := u.Path[1:]; path != "" {
return GetVideoInfoFromID(path)
}
}
return nil, errors.New("Could not parse short URL")
} | [
"func",
"GetVideoInfoFromShortURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"VideoInfo",
",",
"error",
")",
"{",
"if",
"len",
"(",
"u",
".",
"Path",
")",
">=",
"1",
"{",
"if",
"path",
":=",
"u",
".",
"Path",
"[",
"1",
":",
"]",
";",
... | // GetVideoInfoFromShortURL fetches video info from a short youtube url | [
"GetVideoInfoFromShortURL",
"fetches",
"video",
"info",
"from",
"a",
"short",
"youtube",
"url"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L79-L86 |
27,231 | rylio/ytdl | video_info.go | GetVideoInfoFromID | func GetVideoInfoFromID(id string) (*VideoInfo, error) {
u, _ := url.ParseRequestURI(youtubeBaseURL)
values := u.Query()
values.Set("v", id)
u.RawQuery = values.Encode()
resp, err := http.Get(u.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.... | go | func GetVideoInfoFromID(id string) (*VideoInfo, error) {
u, _ := url.ParseRequestURI(youtubeBaseURL)
values := u.Query()
values.Set("v", id)
u.RawQuery = values.Encode()
resp, err := http.Get(u.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.... | [
"func",
"GetVideoInfoFromID",
"(",
"id",
"string",
")",
"(",
"*",
"VideoInfo",
",",
"error",
")",
"{",
"u",
",",
"_",
":=",
"url",
".",
"ParseRequestURI",
"(",
"youtubeBaseURL",
")",
"\n",
"values",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"values",
... | // GetVideoInfoFromID fetches video info from a youtube video id | [
"GetVideoInfoFromID",
"fetches",
"video",
"info",
"from",
"a",
"youtube",
"video",
"id"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L89-L108 |
27,232 | rylio/ytdl | video_info.go | GetDownloadURL | func (info *VideoInfo) GetDownloadURL(format Format) (*url.URL, error) {
return getDownloadURL(format, info.htmlPlayerFile)
} | go | func (info *VideoInfo) GetDownloadURL(format Format) (*url.URL, error) {
return getDownloadURL(format, info.htmlPlayerFile)
} | [
"func",
"(",
"info",
"*",
"VideoInfo",
")",
"GetDownloadURL",
"(",
"format",
"Format",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"return",
"getDownloadURL",
"(",
"format",
",",
"info",
".",
"htmlPlayerFile",
")",
"\n",
"}"
] | // GetDownloadURL gets the download url for a format | [
"GetDownloadURL",
"gets",
"the",
"download",
"url",
"for",
"a",
"format"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L111-L113 |
27,233 | rylio/ytdl | video_info.go | GetThumbnailURL | func (info *VideoInfo) GetThumbnailURL(quality ThumbnailQuality) *url.URL {
u, _ := url.Parse(fmt.Sprintf("http://img.youtube.com/vi/%s/%s.jpg",
info.ID, quality))
return u
} | go | func (info *VideoInfo) GetThumbnailURL(quality ThumbnailQuality) *url.URL {
u, _ := url.Parse(fmt.Sprintf("http://img.youtube.com/vi/%s/%s.jpg",
info.ID, quality))
return u
} | [
"func",
"(",
"info",
"*",
"VideoInfo",
")",
"GetThumbnailURL",
"(",
"quality",
"ThumbnailQuality",
")",
"*",
"url",
".",
"URL",
"{",
"u",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"info",
".",
"ID",
",",... | // GetThumbnailURL returns a url for the thumbnail image
// with the given quality | [
"GetThumbnailURL",
"returns",
"a",
"url",
"for",
"the",
"thumbnail",
"image",
"with",
"the",
"given",
"quality"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L117-L121 |
27,234 | rylio/ytdl | video_info.go | Download | func (info *VideoInfo) Download(format Format, dest io.Writer) error {
u, err := info.GetDownloadURL(format)
if err != nil {
return err
}
resp, err := http.Get(u.String())
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("Invalid st... | go | func (info *VideoInfo) Download(format Format, dest io.Writer) error {
u, err := info.GetDownloadURL(format)
if err != nil {
return err
}
resp, err := http.Get(u.String())
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("Invalid st... | [
"func",
"(",
"info",
"*",
"VideoInfo",
")",
"Download",
"(",
"format",
"Format",
",",
"dest",
"io",
".",
"Writer",
")",
"error",
"{",
"u",
",",
"err",
":=",
"info",
".",
"GetDownloadURL",
"(",
"format",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // Download is a convenience method to download a format to an io.Writer | [
"Download",
"is",
"a",
"convenience",
"method",
"to",
"download",
"a",
"format",
"to",
"an",
"io",
".",
"Writer"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/video_info.go#L124-L139 |
27,235 | rylio/ytdl | format.go | ValueForKey | func (f Format) ValueForKey(key FormatKey) interface{} {
switch key {
case FormatItagKey:
return f.Itag
case FormatExtensionKey:
return f.Extension
case FormatResolutionKey:
return f.Resolution
case FormatVideoEncodingKey:
return f.VideoEncoding
case FormatAudioEncodingKey:
return f.AudioEncoding
case ... | go | func (f Format) ValueForKey(key FormatKey) interface{} {
switch key {
case FormatItagKey:
return f.Itag
case FormatExtensionKey:
return f.Extension
case FormatResolutionKey:
return f.Resolution
case FormatVideoEncodingKey:
return f.VideoEncoding
case FormatAudioEncodingKey:
return f.AudioEncoding
case ... | [
"func",
"(",
"f",
"Format",
")",
"ValueForKey",
"(",
"key",
"FormatKey",
")",
"interface",
"{",
"}",
"{",
"switch",
"key",
"{",
"case",
"FormatItagKey",
":",
"return",
"f",
".",
"Itag",
"\n",
"case",
"FormatExtensionKey",
":",
"return",
"f",
".",
"Extens... | // ValueForKey gets the format value for a format key, used for filtering | [
"ValueForKey",
"gets",
"the",
"format",
"value",
"for",
"a",
"format",
"key",
"used",
"for",
"filtering"
] | 1f14ef2e151a8f8a1af2f318f518f26ff0980b31 | https://github.com/rylio/ytdl/blob/1f14ef2e151a8f8a1af2f318f518f26ff0980b31/format.go#L39-L59 |
27,236 | mmcdole/gofeed | translator.go | Translate | func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error) {
rss, found := feed.(*rss.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *rss.Feed")
}
result := &Feed{}
result.Title = t.translateFeedTitle(rss)
result.Description = t.translateFeedDescription(rss)
resul... | go | func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error) {
rss, found := feed.(*rss.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *rss.Feed")
}
result := &Feed{}
result.Title = t.translateFeedTitle(rss)
result.Description = t.translateFeedDescription(rss)
resul... | [
"func",
"(",
"t",
"*",
"DefaultRSSTranslator",
")",
"Translate",
"(",
"feed",
"interface",
"{",
"}",
")",
"(",
"*",
"Feed",
",",
"error",
")",
"{",
"rss",
",",
"found",
":=",
"feed",
".",
"(",
"*",
"rss",
".",
"Feed",
")",
"\n",
"if",
"!",
"found... | // Translate converts an RSS feed into the universal
// feed type. | [
"Translate",
"converts",
"an",
"RSS",
"feed",
"into",
"the",
"universal",
"feed",
"type",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/translator.go#L30-L58 |
27,237 | mmcdole/gofeed | translator.go | Translate | func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error) {
atom, found := feed.(*atom.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *atom.Feed")
}
result := &Feed{}
result.Title = t.translateFeedTitle(atom)
result.Description = t.translateFeedDescription(atom)
... | go | func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error) {
atom, found := feed.(*atom.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *atom.Feed")
}
result := &Feed{}
result.Title = t.translateFeedTitle(atom)
result.Description = t.translateFeedDescription(atom)
... | [
"func",
"(",
"t",
"*",
"DefaultAtomTranslator",
")",
"Translate",
"(",
"feed",
"interface",
"{",
"}",
")",
"(",
"*",
"Feed",
",",
"error",
")",
"{",
"atom",
",",
"found",
":=",
"feed",
".",
"(",
"*",
"atom",
".",
"Feed",
")",
"\n",
"if",
"!",
"fo... | // Translate converts an Atom feed into the universal
// feed type. | [
"Translate",
"converts",
"an",
"Atom",
"feed",
"into",
"the",
"universal",
"feed",
"type",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/translator.go#L440-L464 |
27,238 | mmcdole/gofeed | internal/shared/xmlsanitizer.go | NewXMLSanitizerReader | func NewXMLSanitizerReader(xml io.Reader) io.Reader {
isIllegal := func(r rune) bool {
return !(r == 0x09 ||
r == 0x0A ||
r == 0x0D ||
r >= 0x20 && r <= 0xDF77 ||
r >= 0xE000 && r <= 0xFFFD ||
r >= 0x10000 && r <= 0x10FFFF)
}
t := transform.Chain(transform.RemoveFunc(isIllegal))
return transform.Ne... | go | func NewXMLSanitizerReader(xml io.Reader) io.Reader {
isIllegal := func(r rune) bool {
return !(r == 0x09 ||
r == 0x0A ||
r == 0x0D ||
r >= 0x20 && r <= 0xDF77 ||
r >= 0xE000 && r <= 0xFFFD ||
r >= 0x10000 && r <= 0x10FFFF)
}
t := transform.Chain(transform.RemoveFunc(isIllegal))
return transform.Ne... | [
"func",
"NewXMLSanitizerReader",
"(",
"xml",
"io",
".",
"Reader",
")",
"io",
".",
"Reader",
"{",
"isIllegal",
":=",
"func",
"(",
"r",
"rune",
")",
"bool",
"{",
"return",
"!",
"(",
"r",
"==",
"0x09",
"||",
"r",
"==",
"0x0A",
"||",
"r",
"==",
"0x0D",... | // NewXMLSanitizerReader creates an io.Reader that
// wraps another io.Reader and removes illegal xml
// characters from the io stream. | [
"NewXMLSanitizerReader",
"creates",
"an",
"io",
".",
"Reader",
"that",
"wraps",
"another",
"io",
".",
"Reader",
"and",
"removes",
"illegal",
"xml",
"characters",
"from",
"the",
"io",
"stream",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/xmlsanitizer.go#L12-L23 |
27,239 | mmcdole/gofeed | internal/shared/parseutils.go | ParseText | func ParseText(p *xpp.XMLPullParser) (string, error) {
var text struct {
Type string `xml:"type,attr"`
InnerXML string `xml:",innerxml"`
}
err := p.DecodeElement(&text)
if err != nil {
return "", err
}
result := text.InnerXML
result = strings.TrimSpace(result)
if strings.Contains(result, CDATA_STAR... | go | func ParseText(p *xpp.XMLPullParser) (string, error) {
var text struct {
Type string `xml:"type,attr"`
InnerXML string `xml:",innerxml"`
}
err := p.DecodeElement(&text)
if err != nil {
return "", err
}
result := text.InnerXML
result = strings.TrimSpace(result)
if strings.Contains(result, CDATA_STAR... | [
"func",
"ParseText",
"(",
"p",
"*",
"xpp",
".",
"XMLPullParser",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"text",
"struct",
"{",
"Type",
"string",
"`xml:\"type,attr\"`",
"\n",
"InnerXML",
"string",
"`xml:\",innerxml\"`",
"\n",
"}",
"\n\n",
"err",
... | // ParseText is a helper function for parsing the text
// from the current element of the XMLPullParser.
// This function can handle parsing naked XML text from
// an element. | [
"ParseText",
"is",
"a",
"helper",
"function",
"for",
"parsing",
"the",
"text",
"from",
"the",
"current",
"element",
"of",
"the",
"XMLPullParser",
".",
"This",
"function",
"can",
"handle",
"parsing",
"naked",
"XML",
"text",
"from",
"an",
"element",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/parseutils.go#L31-L50 |
27,240 | mmcdole/gofeed | internal/shared/parseutils.go | StripCDATA | func StripCDATA(str string) string {
buf := bytes.NewBuffer([]byte{})
curr := 0
for curr < len(str) {
start := indexAt(str, CDATA_START, curr)
if start == -1 {
dec, _ := DecodeEntities(str[curr:])
buf.Write([]byte(dec))
return buf.String()
}
end := indexAt(str, CDATA_END, start)
if end == -1... | go | func StripCDATA(str string) string {
buf := bytes.NewBuffer([]byte{})
curr := 0
for curr < len(str) {
start := indexAt(str, CDATA_START, curr)
if start == -1 {
dec, _ := DecodeEntities(str[curr:])
buf.Write([]byte(dec))
return buf.String()
}
end := indexAt(str, CDATA_END, start)
if end == -1... | [
"func",
"StripCDATA",
"(",
"str",
"string",
")",
"string",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
"\n\n",
"curr",
":=",
"0",
"\n\n",
"for",
"curr",
"<",
"len",
"(",
"str",
")",
"{",
"start",
":=",
"inde... | // StripCDATA removes CDATA tags from the string
// content outside of CDATA tags is passed via DecodeEntities | [
"StripCDATA",
"removes",
"CDATA",
"tags",
"from",
"the",
"string",
"content",
"outside",
"of",
"CDATA",
"tags",
"is",
"passed",
"via",
"DecodeEntities"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/parseutils.go#L54-L83 |
27,241 | mmcdole/gofeed | internal/shared/parseutils.go | DecodeEntities | func DecodeEntities(str string) (string, error) {
data := []byte(str)
buf := bytes.NewBuffer([]byte{})
for len(data) > 0 {
// Find the next entity
idx := bytes.IndexByte(data, '&')
if idx == -1 {
buf.Write(data)
break
}
// Write and skip everything before it
buf.Write(data[:idx])
data = data[id... | go | func DecodeEntities(str string) (string, error) {
data := []byte(str)
buf := bytes.NewBuffer([]byte{})
for len(data) > 0 {
// Find the next entity
idx := bytes.IndexByte(data, '&')
if idx == -1 {
buf.Write(data)
break
}
// Write and skip everything before it
buf.Write(data[:idx])
data = data[id... | [
"func",
"DecodeEntities",
"(",
"str",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
":=",
"[",
"]",
"byte",
"(",
"str",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
"\n\n",
"for",
"len",... | // DecodeEntities decodes escaped XML entities
// in a string and returns the unescaped string | [
"DecodeEntities",
"decodes",
"escaped",
"XML",
"entities",
"in",
"a",
"string",
"and",
"returns",
"the",
"unescaped",
"string"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/parseutils.go#L87-L160 |
27,242 | mmcdole/gofeed | extensions/itunes.go | NewITunesFeedExtension | func NewITunesFeedExtension(extensions map[string][]Extension) *ITunesFeedExtension {
feed := &ITunesFeedExtension{}
feed.Author = parseTextExtension("author", extensions)
feed.Block = parseTextExtension("block", extensions)
feed.Explicit = parseTextExtension("explicit", extensions)
feed.Keywords = parseTextExtens... | go | func NewITunesFeedExtension(extensions map[string][]Extension) *ITunesFeedExtension {
feed := &ITunesFeedExtension{}
feed.Author = parseTextExtension("author", extensions)
feed.Block = parseTextExtension("block", extensions)
feed.Explicit = parseTextExtension("explicit", extensions)
feed.Keywords = parseTextExtens... | [
"func",
"NewITunesFeedExtension",
"(",
"extensions",
"map",
"[",
"string",
"]",
"[",
"]",
"Extension",
")",
"*",
"ITunesFeedExtension",
"{",
"feed",
":=",
"&",
"ITunesFeedExtension",
"{",
"}",
"\n",
"feed",
".",
"Author",
"=",
"parseTextExtension",
"(",
"\"",
... | // NewITunesFeedExtension creates an ITunesFeedExtension given an
// extension map for the "itunes" key. | [
"NewITunesFeedExtension",
"creates",
"an",
"ITunesFeedExtension",
"given",
"an",
"extension",
"map",
"for",
"the",
"itunes",
"key",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/extensions/itunes.go#L49-L64 |
27,243 | mmcdole/gofeed | extensions/itunes.go | NewITunesItemExtension | func NewITunesItemExtension(extensions map[string][]Extension) *ITunesItemExtension {
entry := &ITunesItemExtension{}
entry.Author = parseTextExtension("author", extensions)
entry.Block = parseTextExtension("block", extensions)
entry.Duration = parseTextExtension("duration", extensions)
entry.Explicit = parseTextE... | go | func NewITunesItemExtension(extensions map[string][]Extension) *ITunesItemExtension {
entry := &ITunesItemExtension{}
entry.Author = parseTextExtension("author", extensions)
entry.Block = parseTextExtension("block", extensions)
entry.Duration = parseTextExtension("duration", extensions)
entry.Explicit = parseTextE... | [
"func",
"NewITunesItemExtension",
"(",
"extensions",
"map",
"[",
"string",
"]",
"[",
"]",
"Extension",
")",
"*",
"ITunesItemExtension",
"{",
"entry",
":=",
"&",
"ITunesItemExtension",
"{",
"}",
"\n",
"entry",
".",
"Author",
"=",
"parseTextExtension",
"(",
"\""... | // NewITunesItemExtension creates an ITunesItemExtension given an
// extension map for the "itunes" key. | [
"NewITunesItemExtension",
"creates",
"an",
"ITunesItemExtension",
"given",
"an",
"extension",
"map",
"for",
"the",
"itunes",
"key",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/extensions/itunes.go#L68-L81 |
27,244 | mmcdole/gofeed | internal/shared/xmlbase.go | FindRoot | func (b *XMLBase) FindRoot(p *xpp.XMLPullParser) (event xpp.XMLEventType, err error) {
for {
event, err = b.NextTag(p)
if err != nil {
return event, err
}
if event == xpp.StartTag {
break
}
if event == xpp.EndDocument {
return event, fmt.Errorf("Failed to find root node before document end.")
}... | go | func (b *XMLBase) FindRoot(p *xpp.XMLPullParser) (event xpp.XMLEventType, err error) {
for {
event, err = b.NextTag(p)
if err != nil {
return event, err
}
if event == xpp.StartTag {
break
}
if event == xpp.EndDocument {
return event, fmt.Errorf("Failed to find root node before document end.")
}... | [
"func",
"(",
"b",
"*",
"XMLBase",
")",
"FindRoot",
"(",
"p",
"*",
"xpp",
".",
"XMLPullParser",
")",
"(",
"event",
"xpp",
".",
"XMLEventType",
",",
"err",
"error",
")",
"{",
"for",
"{",
"event",
",",
"err",
"=",
"b",
".",
"NextTag",
"(",
"p",
")",... | // FindRoot iterates through the tokens of an xml document until
// it encounters its first StartTag event. It returns an error
// if it reaches EndDocument before finding a tag. | [
"FindRoot",
"iterates",
"through",
"the",
"tokens",
"of",
"an",
"xml",
"document",
"until",
"it",
"encounters",
"its",
"first",
"StartTag",
"event",
".",
"It",
"returns",
"an",
"error",
"if",
"it",
"reaches",
"EndDocument",
"before",
"finding",
"a",
"tag",
"... | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/xmlbase.go#L64-L79 |
27,245 | mmcdole/gofeed | internal/shared/xmlbase.go | pop | func (b *XMLBase) pop() string {
url := b.stack.pop()
if url != nil {
return url.String()
}
return ""
} | go | func (b *XMLBase) pop() string {
url := b.stack.pop()
if url != nil {
return url.String()
}
return ""
} | [
"func",
"(",
"b",
"*",
"XMLBase",
")",
"pop",
"(",
")",
"string",
"{",
"url",
":=",
"b",
".",
"stack",
".",
"pop",
"(",
")",
"\n",
"if",
"url",
"!=",
"nil",
"{",
"return",
"url",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",... | // returns the popped base URL | [
"returns",
"the",
"popped",
"base",
"URL"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/xmlbase.go#L155-L161 |
27,246 | mmcdole/gofeed | internal/shared/xmlbase.go | ResolveURL | func (b *XMLBase) ResolveURL(u string) (string, error) {
if b.CurrentBase() == "" {
return u, nil
}
relURL, err := url.Parse(u)
if err != nil {
return u, err
}
curr := b.CurrentBaseURL()
if curr.Path != "" && u != "" && curr.Path[len(curr.Path)-1] != '/' {
// There's no reason someone would use a path in ... | go | func (b *XMLBase) ResolveURL(u string) (string, error) {
if b.CurrentBase() == "" {
return u, nil
}
relURL, err := url.Parse(u)
if err != nil {
return u, err
}
curr := b.CurrentBaseURL()
if curr.Path != "" && u != "" && curr.Path[len(curr.Path)-1] != '/' {
// There's no reason someone would use a path in ... | [
"func",
"(",
"b",
"*",
"XMLBase",
")",
"ResolveURL",
"(",
"u",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"b",
".",
"CurrentBase",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"u",
",",
"nil",
"\n",
"}",
"\n\n",
"relURL",
",",
"e... | // resolve the given string as a URL relative to current base | [
"resolve",
"the",
"given",
"string",
"as",
"a",
"URL",
"relative",
"to",
"current",
"base"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/xmlbase.go#L175-L192 |
27,247 | mmcdole/gofeed | internal/shared/xmlbase.go | ResolveHTML | func (b *XMLBase) ResolveHTML(relHTML string) (string, error) {
if b.CurrentBase() == "" {
return relHTML, nil
}
htmlReader := strings.NewReader(relHTML)
doc, err := html.Parse(htmlReader)
if err != nil {
return relHTML, err
}
var visit func(*html.Node)
// recursively traverse HTML resolving any relativ... | go | func (b *XMLBase) ResolveHTML(relHTML string) (string, error) {
if b.CurrentBase() == "" {
return relHTML, nil
}
htmlReader := strings.NewReader(relHTML)
doc, err := html.Parse(htmlReader)
if err != nil {
return relHTML, err
}
var visit func(*html.Node)
// recursively traverse HTML resolving any relativ... | [
"func",
"(",
"b",
"*",
"XMLBase",
")",
"ResolveHTML",
"(",
"relHTML",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"b",
".",
"CurrentBase",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"relHTML",
",",
"nil",
"\n",
"}",
"\n\n",
"htmlRea... | // Transforms html by resolving any relative URIs in attributes
// if an error occurs during parsing or serialization, then the original string
// is returned along with the error. | [
"Transforms",
"html",
"by",
"resolving",
"any",
"relative",
"URIs",
"in",
"attributes",
"if",
"an",
"error",
"occurs",
"during",
"parsing",
"or",
"serialization",
"then",
"the",
"original",
"string",
"is",
"returned",
"along",
"with",
"the",
"error",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/xmlbase.go#L212-L258 |
27,248 | mmcdole/gofeed | internal/shared/dateparser.go | ParseDate | func ParseDate(ds string) (t time.Time, err error) {
d := strings.TrimSpace(ds)
if d == "" {
return t, fmt.Errorf("Date string is empty")
}
for _, f := range dateFormats {
if t, err = time.Parse(f, d); err == nil {
return
}
}
for _, f := range dateFormatsWithNamedZone {
t, err = time.Parse(f, d)
if e... | go | func ParseDate(ds string) (t time.Time, err error) {
d := strings.TrimSpace(ds)
if d == "" {
return t, fmt.Errorf("Date string is empty")
}
for _, f := range dateFormats {
if t, err = time.Parse(f, d); err == nil {
return
}
}
for _, f := range dateFormatsWithNamedZone {
t, err = time.Parse(f, d)
if e... | [
"func",
"ParseDate",
"(",
"ds",
"string",
")",
"(",
"t",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"d",
":=",
"strings",
".",
"TrimSpace",
"(",
"ds",
")",
"\n",
"if",
"d",
"==",
"\"",
"\"",
"{",
"return",
"t",
",",
"fmt",
".",
"Errorf... | // ParseDate parses a given date string using a large
// list of commonly found feed date formats. | [
"ParseDate",
"parses",
"a",
"given",
"date",
"string",
"using",
"a",
"large",
"list",
"of",
"commonly",
"found",
"feed",
"date",
"formats",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/dateparser.go#L188-L219 |
27,249 | mmcdole/gofeed | detector.go | DetectFeedType | func DetectFeedType(feed io.Reader) FeedType {
p := xpp.NewXMLPullParser(feed, false, shared.NewReaderLabel)
xmlBase := shared.XMLBase{}
_, err := xmlBase.FindRoot(p)
if err != nil {
return FeedTypeUnknown
}
name := strings.ToLower(p.Name)
switch name {
case "rdf":
return FeedTypeRSS
case "rss":
return... | go | func DetectFeedType(feed io.Reader) FeedType {
p := xpp.NewXMLPullParser(feed, false, shared.NewReaderLabel)
xmlBase := shared.XMLBase{}
_, err := xmlBase.FindRoot(p)
if err != nil {
return FeedTypeUnknown
}
name := strings.ToLower(p.Name)
switch name {
case "rdf":
return FeedTypeRSS
case "rss":
return... | [
"func",
"DetectFeedType",
"(",
"feed",
"io",
".",
"Reader",
")",
"FeedType",
"{",
"p",
":=",
"xpp",
".",
"NewXMLPullParser",
"(",
"feed",
",",
"false",
",",
"shared",
".",
"NewReaderLabel",
")",
"\n\n",
"xmlBase",
":=",
"shared",
".",
"XMLBase",
"{",
"}"... | // DetectFeedType attempts to determine the type of feed
// by looking for specific xml elements unique to the
// various feed types. | [
"DetectFeedType",
"attempts",
"to",
"determine",
"the",
"type",
"of",
"feed",
"by",
"looking",
"for",
"specific",
"xml",
"elements",
"unique",
"to",
"the",
"various",
"feed",
"types",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/detector.go#L28-L48 |
27,250 | mmcdole/gofeed | extensions/dublincore.go | NewDublinCoreExtension | func NewDublinCoreExtension(extensions map[string][]Extension) *DublinCoreExtension {
dc := &DublinCoreExtension{}
dc.Title = parseTextArrayExtension("title", extensions)
dc.Creator = parseTextArrayExtension("creator", extensions)
dc.Author = parseTextArrayExtension("author", extensions)
dc.Subject = parseTextArra... | go | func NewDublinCoreExtension(extensions map[string][]Extension) *DublinCoreExtension {
dc := &DublinCoreExtension{}
dc.Title = parseTextArrayExtension("title", extensions)
dc.Creator = parseTextArrayExtension("creator", extensions)
dc.Author = parseTextArrayExtension("author", extensions)
dc.Subject = parseTextArra... | [
"func",
"NewDublinCoreExtension",
"(",
"extensions",
"map",
"[",
"string",
"]",
"[",
"]",
"Extension",
")",
"*",
"DublinCoreExtension",
"{",
"dc",
":=",
"&",
"DublinCoreExtension",
"{",
"}",
"\n",
"dc",
".",
"Title",
"=",
"parseTextArrayExtension",
"(",
"\"",
... | // NewDublinCoreExtension creates a new DublinCoreExtension
// given the generic extension map for the "dc" prefix. | [
"NewDublinCoreExtension",
"creates",
"a",
"new",
"DublinCoreExtension",
"given",
"the",
"generic",
"extension",
"map",
"for",
"the",
"dc",
"prefix",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/extensions/dublincore.go#L26-L45 |
27,251 | mmcdole/gofeed | internal/shared/extparser.go | ParseExtension | func ParseExtension(fe ext.Extensions, p *xpp.XMLPullParser) (ext.Extensions, error) {
prefix := prefixForNamespace(p.Space, p)
result, err := parseExtensionElement(p)
if err != nil {
return nil, err
}
// Ensure the extension prefix map exists
if _, ok := fe[prefix]; !ok {
fe[prefix] = map[string][]ext.Exte... | go | func ParseExtension(fe ext.Extensions, p *xpp.XMLPullParser) (ext.Extensions, error) {
prefix := prefixForNamespace(p.Space, p)
result, err := parseExtensionElement(p)
if err != nil {
return nil, err
}
// Ensure the extension prefix map exists
if _, ok := fe[prefix]; !ok {
fe[prefix] = map[string][]ext.Exte... | [
"func",
"ParseExtension",
"(",
"fe",
"ext",
".",
"Extensions",
",",
"p",
"*",
"xpp",
".",
"XMLPullParser",
")",
"(",
"ext",
".",
"Extensions",
",",
"error",
")",
"{",
"prefix",
":=",
"prefixForNamespace",
"(",
"p",
".",
"Space",
",",
"p",
")",
"\n\n",
... | // ParseExtension parses the current element of the
// XMLPullParser as an extension element and updates
// the extension map | [
"ParseExtension",
"parses",
"the",
"current",
"element",
"of",
"the",
"XMLPullParser",
"as",
"an",
"extension",
"element",
"and",
"updates",
"the",
"extension",
"map"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/internal/shared/extparser.go#L25-L44 |
27,252 | mmcdole/gofeed | parser.go | NewParser | func NewParser() *Parser {
fp := Parser{
rp: &rss.Parser{},
ap: &atom.Parser{},
}
return &fp
} | go | func NewParser() *Parser {
fp := Parser{
rp: &rss.Parser{},
ap: &atom.Parser{},
}
return &fp
} | [
"func",
"NewParser",
"(",
")",
"*",
"Parser",
"{",
"fp",
":=",
"Parser",
"{",
"rp",
":",
"&",
"rss",
".",
"Parser",
"{",
"}",
",",
"ap",
":",
"&",
"atom",
".",
"Parser",
"{",
"}",
",",
"}",
"\n",
"return",
"&",
"fp",
"\n",
"}"
] | // NewParser creates a universal feed parser. | [
"NewParser",
"creates",
"a",
"universal",
"feed",
"parser",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/parser.go#L41-L47 |
27,253 | mmcdole/gofeed | parser.go | Parse | func (f *Parser) Parse(feed io.Reader) (*Feed, error) {
// Wrap the feed io.Reader in a io.TeeReader
// so we can capture all the bytes read by the
// DetectFeedType function and construct a new
// reader with those bytes intact for when we
// attempt to parse the feeds.
var buf bytes.Buffer
tee := io.TeeReader(... | go | func (f *Parser) Parse(feed io.Reader) (*Feed, error) {
// Wrap the feed io.Reader in a io.TeeReader
// so we can capture all the bytes read by the
// DetectFeedType function and construct a new
// reader with those bytes intact for when we
// attempt to parse the feeds.
var buf bytes.Buffer
tee := io.TeeReader(... | [
"func",
"(",
"f",
"*",
"Parser",
")",
"Parse",
"(",
"feed",
"io",
".",
"Reader",
")",
"(",
"*",
"Feed",
",",
"error",
")",
"{",
"// Wrap the feed io.Reader in a io.TeeReader",
"// so we can capture all the bytes read by the",
"// DetectFeedType function and construct a ne... | // Parse parses a RSS or Atom feed into
// the universal gofeed.Feed. It takes an
// io.Reader which should return the xml content. | [
"Parse",
"parses",
"a",
"RSS",
"or",
"Atom",
"feed",
"into",
"the",
"universal",
"gofeed",
".",
"Feed",
".",
"It",
"takes",
"an",
"io",
".",
"Reader",
"which",
"should",
"return",
"the",
"xml",
"content",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/parser.go#L52-L74 |
27,254 | mmcdole/gofeed | parser.go | ParseURL | func (f *Parser) ParseURL(feedURL string) (feed *Feed, err error) {
client := f.httpClient()
req, err := http.NewRequest("GET", feedURL, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "Gofeed/1.0")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
if resp != nil {
defe... | go | func (f *Parser) ParseURL(feedURL string) (feed *Feed, err error) {
client := f.httpClient()
req, err := http.NewRequest("GET", feedURL, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "Gofeed/1.0")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
if resp != nil {
defe... | [
"func",
"(",
"f",
"*",
"Parser",
")",
"ParseURL",
"(",
"feedURL",
"string",
")",
"(",
"feed",
"*",
"Feed",
",",
"err",
"error",
")",
"{",
"client",
":=",
"f",
".",
"httpClient",
"(",
")",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
... | // ParseURL fetches the contents of a given url and
// attempts to parse the response into the universal feed type. | [
"ParseURL",
"fetches",
"the",
"contents",
"of",
"a",
"given",
"url",
"and",
"attempts",
"to",
"parse",
"the",
"response",
"into",
"the",
"universal",
"feed",
"type",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/parser.go#L78-L109 |
27,255 | mmcdole/gofeed | parser.go | ParseString | func (f *Parser) ParseString(feed string) (*Feed, error) {
return f.Parse(strings.NewReader(feed))
} | go | func (f *Parser) ParseString(feed string) (*Feed, error) {
return f.Parse(strings.NewReader(feed))
} | [
"func",
"(",
"f",
"*",
"Parser",
")",
"ParseString",
"(",
"feed",
"string",
")",
"(",
"*",
"Feed",
",",
"error",
")",
"{",
"return",
"f",
".",
"Parse",
"(",
"strings",
".",
"NewReader",
"(",
"feed",
")",
")",
"\n",
"}"
] | // ParseString parses a feed XML string and into the
// universal feed type. | [
"ParseString",
"parses",
"a",
"feed",
"XML",
"string",
"and",
"into",
"the",
"universal",
"feed",
"type",
"."
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/parser.go#L113-L115 |
27,256 | mmcdole/gofeed | rss/parser.go | Parse | func (rp *Parser) Parse(feed io.Reader) (*Feed, error) {
p := xpp.NewXMLPullParser(feed, false, shared.NewReaderLabel)
rp.base = &shared.XMLBase{}
_, err := rp.base.FindRoot(p)
if err != nil {
return nil, err
}
return rp.parseRoot(p)
} | go | func (rp *Parser) Parse(feed io.Reader) (*Feed, error) {
p := xpp.NewXMLPullParser(feed, false, shared.NewReaderLabel)
rp.base = &shared.XMLBase{}
_, err := rp.base.FindRoot(p)
if err != nil {
return nil, err
}
return rp.parseRoot(p)
} | [
"func",
"(",
"rp",
"*",
"Parser",
")",
"Parse",
"(",
"feed",
"io",
".",
"Reader",
")",
"(",
"*",
"Feed",
",",
"error",
")",
"{",
"p",
":=",
"xpp",
".",
"NewXMLPullParser",
"(",
"feed",
",",
"false",
",",
"shared",
".",
"NewReaderLabel",
")",
"\n",
... | // Parse parses an xml feed into an rss.Feed | [
"Parse",
"parses",
"an",
"xml",
"feed",
"into",
"an",
"rss",
".",
"Feed"
] | 0e68beaf6fdf215bd1fe42a09f6de292c7032359 | https://github.com/mmcdole/gofeed/blob/0e68beaf6fdf215bd1fe42a09f6de292c7032359/rss/parser.go#L19-L29 |
27,257 | vulcand/oxy | forward/rewrite.go | Rewrite | func (rw *HeaderRewriter) Rewrite(req *http.Request) {
if !rw.TrustForwardHeader {
utils.RemoveHeaders(req.Header, XHeaders...)
}
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
clientIP = ipv6fix(clientIP)
// If not websocket, done in http.ReverseProxy
if IsWebsocketRequest(req) {
... | go | func (rw *HeaderRewriter) Rewrite(req *http.Request) {
if !rw.TrustForwardHeader {
utils.RemoveHeaders(req.Header, XHeaders...)
}
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
clientIP = ipv6fix(clientIP)
// If not websocket, done in http.ReverseProxy
if IsWebsocketRequest(req) {
... | [
"func",
"(",
"rw",
"*",
"HeaderRewriter",
")",
"Rewrite",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"!",
"rw",
".",
"TrustForwardHeader",
"{",
"utils",
".",
"RemoveHeaders",
"(",
"req",
".",
"Header",
",",
"XHeaders",
"...",
")",
"\n",
... | // Rewrite rewrite request headers | [
"Rewrite",
"rewrite",
"request",
"headers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/forward/rewrite.go#L23-L72 |
27,258 | vulcand/oxy | ratelimit/bucketset.go | NewTokenBucketSet | func NewTokenBucketSet(rates *RateSet, clock timetools.TimeProvider) *TokenBucketSet {
tbs := new(TokenBucketSet)
tbs.clock = clock
// In the majority of cases we will have only one bucket.
tbs.buckets = make(map[time.Duration]*tokenBucket, len(rates.m))
for _, rate := range rates.m {
newBucket := newTokenBucket... | go | func NewTokenBucketSet(rates *RateSet, clock timetools.TimeProvider) *TokenBucketSet {
tbs := new(TokenBucketSet)
tbs.clock = clock
// In the majority of cases we will have only one bucket.
tbs.buckets = make(map[time.Duration]*tokenBucket, len(rates.m))
for _, rate := range rates.m {
newBucket := newTokenBucket... | [
"func",
"NewTokenBucketSet",
"(",
"rates",
"*",
"RateSet",
",",
"clock",
"timetools",
".",
"TimeProvider",
")",
"*",
"TokenBucketSet",
"{",
"tbs",
":=",
"new",
"(",
"TokenBucketSet",
")",
"\n",
"tbs",
".",
"clock",
"=",
"clock",
"\n",
"// In the majority of ca... | // NewTokenBucketSet creates a `TokenBucketSet` from the specified `rates`. | [
"NewTokenBucketSet",
"creates",
"a",
"TokenBucketSet",
"from",
"the",
"specified",
"rates",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucketset.go#L20-L31 |
27,259 | vulcand/oxy | ratelimit/bucketset.go | Update | func (tbs *TokenBucketSet) Update(rates *RateSet) {
// Update existing buckets and delete those that have no corresponding spec.
for _, bucket := range tbs.buckets {
if rate, ok := rates.m[bucket.period]; ok {
bucket.update(rate)
} else {
delete(tbs.buckets, bucket.period)
}
}
// Add missing buckets.
f... | go | func (tbs *TokenBucketSet) Update(rates *RateSet) {
// Update existing buckets and delete those that have no corresponding spec.
for _, bucket := range tbs.buckets {
if rate, ok := rates.m[bucket.period]; ok {
bucket.update(rate)
} else {
delete(tbs.buckets, bucket.period)
}
}
// Add missing buckets.
f... | [
"func",
"(",
"tbs",
"*",
"TokenBucketSet",
")",
"Update",
"(",
"rates",
"*",
"RateSet",
")",
"{",
"// Update existing buckets and delete those that have no corresponding spec.",
"for",
"_",
",",
"bucket",
":=",
"range",
"tbs",
".",
"buckets",
"{",
"if",
"rate",
",... | // Update brings the buckets in the set in accordance with the provided `rates`. | [
"Update",
"brings",
"the",
"buckets",
"in",
"the",
"set",
"in",
"accordance",
"with",
"the",
"provided",
"rates",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucketset.go#L34-L55 |
27,260 | vulcand/oxy | ratelimit/bucketset.go | Consume | func (tbs *TokenBucketSet) Consume(tokens int64) (time.Duration, error) {
var maxDelay time.Duration = UndefinedDelay
var firstErr error
for _, tokenBucket := range tbs.buckets {
// We keep calling `Consume` even after a error is returned for one of
// buckets because that allows us to simplify the rollback proc... | go | func (tbs *TokenBucketSet) Consume(tokens int64) (time.Duration, error) {
var maxDelay time.Duration = UndefinedDelay
var firstErr error
for _, tokenBucket := range tbs.buckets {
// We keep calling `Consume` even after a error is returned for one of
// buckets because that allows us to simplify the rollback proc... | [
"func",
"(",
"tbs",
"*",
"TokenBucketSet",
")",
"Consume",
"(",
"tokens",
"int64",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"var",
"maxDelay",
"time",
".",
"Duration",
"=",
"UndefinedDelay",
"\n",
"var",
"firstErr",
"error",
"\n",
"for"... | // Consume consume tokens | [
"Consume",
"consume",
"tokens"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucketset.go#L58-L82 |
27,261 | vulcand/oxy | ratelimit/bucketset.go | debugState | func (tbs *TokenBucketSet) debugState() string {
periods := sort.IntSlice(make([]int, 0, len(tbs.buckets)))
for period := range tbs.buckets {
periods = append(periods, int(period))
}
sort.Sort(periods)
bucketRepr := make([]string, 0, len(tbs.buckets))
for _, period := range periods {
bucket := tbs.buckets[tim... | go | func (tbs *TokenBucketSet) debugState() string {
periods := sort.IntSlice(make([]int, 0, len(tbs.buckets)))
for period := range tbs.buckets {
periods = append(periods, int(period))
}
sort.Sort(periods)
bucketRepr := make([]string, 0, len(tbs.buckets))
for _, period := range periods {
bucket := tbs.buckets[tim... | [
"func",
"(",
"tbs",
"*",
"TokenBucketSet",
")",
"debugState",
"(",
")",
"string",
"{",
"periods",
":=",
"sort",
".",
"IntSlice",
"(",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"len",
"(",
"tbs",
".",
"buckets",
")",
")",
")",
"\n",
"for",
"per... | // debugState returns string that reflects the current state of all buckets in
// this set. It is intended to be used for debugging and testing only. | [
"debugState",
"returns",
"string",
"that",
"reflects",
"the",
"current",
"state",
"of",
"all",
"buckets",
"in",
"this",
"set",
".",
"It",
"is",
"intended",
"to",
"be",
"used",
"for",
"debugging",
"and",
"testing",
"only",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucketset.go#L91-L103 |
27,262 | vulcand/oxy | cbreaker/predicates.go | parseExpression | func parseExpression(in string) (hpredicate, error) {
p, err := predicate.NewParser(predicate.Def{
Operators: predicate.Operators{
AND: and,
OR: or,
EQ: eq,
NEQ: neq,
LT: lt,
LE: le,
GT: gt,
GE: ge,
},
Functions: map[string]interface{}{
"LatencyAtQuantileMS": latencyAtQuantile,
... | go | func parseExpression(in string) (hpredicate, error) {
p, err := predicate.NewParser(predicate.Def{
Operators: predicate.Operators{
AND: and,
OR: or,
EQ: eq,
NEQ: neq,
LT: lt,
LE: le,
GT: gt,
GE: ge,
},
Functions: map[string]interface{}{
"LatencyAtQuantileMS": latencyAtQuantile,
... | [
"func",
"parseExpression",
"(",
"in",
"string",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"predicate",
".",
"NewParser",
"(",
"predicate",
".",
"Def",
"{",
"Operators",
":",
"predicate",
".",
"Operators",
"{",
"AND",
":",
"... | // parseExpression parses expression in the go language into predicates. | [
"parseExpression",
"parses",
"expression",
"in",
"the",
"go",
"language",
"into",
"predicates",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L13-L43 |
27,263 | vulcand/oxy | cbreaker/predicates.go | or | func or(fns ...hpredicate) hpredicate {
return func(c *CircuitBreaker) bool {
for _, fn := range fns {
if fn(c) {
return true
}
}
return false
}
} | go | func or(fns ...hpredicate) hpredicate {
return func(c *CircuitBreaker) bool {
for _, fn := range fns {
if fn(c) {
return true
}
}
return false
}
} | [
"func",
"or",
"(",
"fns",
"...",
"hpredicate",
")",
"hpredicate",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"bool",
"{",
"for",
"_",
",",
"fn",
":=",
"range",
"fns",
"{",
"if",
"fn",
"(",
"c",
")",
"{",
"return",
"true",
"\n",
... | // or returns predicate by joining the passed predicates with logical 'or' | [
"or",
"returns",
"predicate",
"by",
"joining",
"the",
"passed",
"predicates",
"with",
"logical",
"or"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L72-L81 |
27,264 | vulcand/oxy | cbreaker/predicates.go | neq | func neq(m interface{}, value interface{}) (hpredicate, error) {
p, err := eq(m, value)
if err != nil {
return nil, err
}
return not(p), nil
} | go | func neq(m interface{}, value interface{}) (hpredicate, error) {
p, err := eq(m, value)
if err != nil {
return nil, err
}
return not(p), nil
} | [
"func",
"neq",
"(",
"m",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"eq",
"(",
"m",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",... | // neq returns predicate that tests for inequality of the value of the mapper and the constant | [
"neq",
"returns",
"predicate",
"that",
"tests",
"for",
"inequality",
"of",
"the",
"value",
"of",
"the",
"mapper",
"and",
"the",
"constant"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L114-L120 |
27,265 | vulcand/oxy | cbreaker/predicates.go | le | func le(m interface{}, value interface{}) (hpredicate, error) {
l, err := lt(m, value)
if err != nil {
return nil, err
}
e, err := eq(m, value)
if err != nil {
return nil, err
}
return func(c *CircuitBreaker) bool {
return l(c) || e(c)
}, nil
} | go | func le(m interface{}, value interface{}) (hpredicate, error) {
l, err := lt(m, value)
if err != nil {
return nil, err
}
e, err := eq(m, value)
if err != nil {
return nil, err
}
return func(c *CircuitBreaker) bool {
return l(c) || e(c)
}, nil
} | [
"func",
"le",
"(",
"m",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"l",
",",
"err",
":=",
"lt",
"(",
"m",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // le returns predicate that tests that value of the mapper function is less or equal than the constant | [
"le",
"returns",
"predicate",
"that",
"tests",
"that",
"value",
"of",
"the",
"mapper",
"function",
"is",
"less",
"or",
"equal",
"than",
"the",
"constant"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L134-L146 |
27,266 | vulcand/oxy | cbreaker/predicates.go | gt | func gt(m interface{}, value interface{}) (hpredicate, error) {
switch mapper := m.(type) {
case toInt:
return intGT(mapper, value)
case toFloat64:
return float64GT(mapper, value)
}
return nil, fmt.Errorf("gt: unsupported argument: %T", m)
} | go | func gt(m interface{}, value interface{}) (hpredicate, error) {
switch mapper := m.(type) {
case toInt:
return intGT(mapper, value)
case toFloat64:
return float64GT(mapper, value)
}
return nil, fmt.Errorf("gt: unsupported argument: %T", m)
} | [
"func",
"gt",
"(",
"m",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"switch",
"mapper",
":=",
"m",
".",
"(",
"type",
")",
"{",
"case",
"toInt",
":",
"return",
"intGT",
"(",
"mapper",
... | // gt returns predicate that tests that value of the mapper function is greater than the constant | [
"gt",
"returns",
"predicate",
"that",
"tests",
"that",
"value",
"of",
"the",
"mapper",
"function",
"is",
"greater",
"than",
"the",
"constant"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L149-L157 |
27,267 | vulcand/oxy | cbreaker/predicates.go | ge | func ge(m interface{}, value interface{}) (hpredicate, error) {
g, err := gt(m, value)
if err != nil {
return nil, err
}
e, err := eq(m, value)
if err != nil {
return nil, err
}
return func(c *CircuitBreaker) bool {
return g(c) || e(c)
}, nil
} | go | func ge(m interface{}, value interface{}) (hpredicate, error) {
g, err := gt(m, value)
if err != nil {
return nil, err
}
e, err := eq(m, value)
if err != nil {
return nil, err
}
return func(c *CircuitBreaker) bool {
return g(c) || e(c)
}, nil
} | [
"func",
"ge",
"(",
"m",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"hpredicate",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"gt",
"(",
"m",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // ge returns predicate that tests that value of the mapper function is less or equal than the constant | [
"ge",
"returns",
"predicate",
"that",
"tests",
"that",
"value",
"of",
"the",
"mapper",
"function",
"is",
"less",
"or",
"equal",
"than",
"the",
"constant"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/predicates.go#L160-L172 |
27,268 | vulcand/oxy | cbreaker/cbreaker.go | activateFallback | func (c *CircuitBreaker) activateFallback(w http.ResponseWriter, req *http.Request) bool {
// Quick check with read locks optimized for normal operation use-case
if c.isStandby() {
return false
}
// Circuit breaker is in tripped or recovering state
c.m.Lock()
defer c.m.Unlock()
c.log.Warnf("%v is in error sta... | go | func (c *CircuitBreaker) activateFallback(w http.ResponseWriter, req *http.Request) bool {
// Quick check with read locks optimized for normal operation use-case
if c.isStandby() {
return false
}
// Circuit breaker is in tripped or recovering state
c.m.Lock()
defer c.m.Unlock()
c.log.Warnf("%v is in error sta... | [
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"activateFallback",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"// Quick check with read locks optimized for normal operation use-case",
"if",
"c",
".",
"isStandby... | // updateState updates internal state and returns true if fallback should be used and false otherwise | [
"updateState",
"updates",
"internal",
"state",
"and",
"returns",
"true",
"if",
"fallback",
"should",
"be",
"used",
"and",
"false",
"otherwise"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L133-L168 |
27,269 | vulcand/oxy | cbreaker/cbreaker.go | String | func (c *CircuitBreaker) String() string {
switch c.state {
case stateTripped, stateRecovering:
return fmt.Sprintf("CircuitBreaker(state=%v, until=%v)", c.state, c.until)
default:
return fmt.Sprintf("CircuitBreaker(state=%v)", c.state)
}
} | go | func (c *CircuitBreaker) String() string {
switch c.state {
case stateTripped, stateRecovering:
return fmt.Sprintf("CircuitBreaker(state=%v, until=%v)", c.state, c.until)
default:
return fmt.Sprintf("CircuitBreaker(state=%v)", c.state)
}
} | [
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"c",
".",
"state",
"{",
"case",
"stateTripped",
",",
"stateRecovering",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"state",
",",
"c"... | // String returns log-friendly representation of the circuit breaker state | [
"String",
"returns",
"log",
"-",
"friendly",
"representation",
"of",
"the",
"circuit",
"breaker",
"state"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L191-L198 |
27,270 | vulcand/oxy | cbreaker/cbreaker.go | exec | func (c *CircuitBreaker) exec(s SideEffect) {
if s == nil {
return
}
go func() {
if err := s.Exec(); err != nil {
c.log.Errorf("%v side effect failure: %v", c, err)
}
}()
} | go | func (c *CircuitBreaker) exec(s SideEffect) {
if s == nil {
return
}
go func() {
if err := s.Exec(); err != nil {
c.log.Errorf("%v side effect failure: %v", c, err)
}
}()
} | [
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"exec",
"(",
"s",
"SideEffect",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"s",
".",
"Exec",
"(",
")",
";",
"err",
"!=",
"nil... | // exec executes side effect | [
"exec",
"executes",
"side",
"effect"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L201-L210 |
27,271 | vulcand/oxy | cbreaker/cbreaker.go | checkAndSet | func (c *CircuitBreaker) checkAndSet() {
if !c.timeToCheck() {
return
}
c.m.Lock()
defer c.m.Unlock()
// Other goroutine could have updated the lastCheck variable before we grabbed mutex
if !c.clock.UtcNow().After(c.lastCheck) {
return
}
c.lastCheck = c.clock.UtcNow().Add(c.checkPeriod)
if c.state == st... | go | func (c *CircuitBreaker) checkAndSet() {
if !c.timeToCheck() {
return
}
c.m.Lock()
defer c.m.Unlock()
// Other goroutine could have updated the lastCheck variable before we grabbed mutex
if !c.clock.UtcNow().After(c.lastCheck) {
return
}
c.lastCheck = c.clock.UtcNow().Add(c.checkPeriod)
if c.state == st... | [
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"checkAndSet",
"(",
")",
"{",
"if",
"!",
"c",
".",
"timeToCheck",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"m",
".",
"Unlock",
"(",
... | // Checks if tripping condition matches and sets circuit breaker to the tripped state | [
"Checks",
"if",
"tripping",
"condition",
"matches",
"and",
"sets",
"circuit",
"breaker",
"to",
"the",
"tripped",
"state"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L231-L256 |
27,272 | vulcand/oxy | cbreaker/cbreaker.go | Clock | func Clock(clock timetools.TimeProvider) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.clock = clock
return nil
}
} | go | func Clock(clock timetools.TimeProvider) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.clock = clock
return nil
}
} | [
"func",
"Clock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Clock allows you to fake che CircuitBreaker's view of the current time.
// Intended for unit tests. | [
"Clock",
"allows",
"you",
"to",
"fake",
"che",
"CircuitBreaker",
"s",
"view",
"of",
"the",
"current",
"time",
".",
"Intended",
"for",
"unit",
"tests",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L269-L274 |
27,273 | vulcand/oxy | cbreaker/cbreaker.go | FallbackDuration | func FallbackDuration(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.fallbackDuration = d
return nil
}
} | go | func FallbackDuration(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.fallbackDuration = d
return nil
}
} | [
"func",
"FallbackDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"fallbackDuration",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // FallbackDuration is how long the CircuitBreaker will remain in the Tripped
// state before trying to recover. | [
"FallbackDuration",
"is",
"how",
"long",
"the",
"CircuitBreaker",
"will",
"remain",
"in",
"the",
"Tripped",
"state",
"before",
"trying",
"to",
"recover",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L278-L283 |
27,274 | vulcand/oxy | cbreaker/cbreaker.go | RecoveryDuration | func RecoveryDuration(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.recoveryDuration = d
return nil
}
} | go | func RecoveryDuration(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.recoveryDuration = d
return nil
}
} | [
"func",
"RecoveryDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"recoveryDuration",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RecoveryDuration is how long the CircuitBreaker will take to ramp up
// requests during the Recovering state. | [
"RecoveryDuration",
"is",
"how",
"long",
"the",
"CircuitBreaker",
"will",
"take",
"to",
"ramp",
"up",
"requests",
"during",
"the",
"Recovering",
"state",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L287-L292 |
27,275 | vulcand/oxy | cbreaker/cbreaker.go | CheckPeriod | func CheckPeriod(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.checkPeriod = d
return nil
}
} | go | func CheckPeriod(d time.Duration) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.checkPeriod = d
return nil
}
} | [
"func",
"CheckPeriod",
"(",
"d",
"time",
".",
"Duration",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"checkPeriod",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CheckPeriod is how long the CircuitBreaker will wait between successive
// checks of the breaker condition. | [
"CheckPeriod",
"is",
"how",
"long",
"the",
"CircuitBreaker",
"will",
"wait",
"between",
"successive",
"checks",
"of",
"the",
"breaker",
"condition",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L296-L301 |
27,276 | vulcand/oxy | cbreaker/cbreaker.go | OnTripped | func OnTripped(s SideEffect) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.onTripped = s
return nil
}
} | go | func OnTripped(s SideEffect) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.onTripped = s
return nil
}
} | [
"func",
"OnTripped",
"(",
"s",
"SideEffect",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"onTripped",
"=",
"s",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OnTripped sets a SideEffect to run when entering the Tripped state.
// Only one SideEffect can be set for this hook. | [
"OnTripped",
"sets",
"a",
"SideEffect",
"to",
"run",
"when",
"entering",
"the",
"Tripped",
"state",
".",
"Only",
"one",
"SideEffect",
"can",
"be",
"set",
"for",
"this",
"hook",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L305-L310 |
27,277 | vulcand/oxy | cbreaker/cbreaker.go | OnStandby | func OnStandby(s SideEffect) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.onStandby = s
return nil
}
} | go | func OnStandby(s SideEffect) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.onStandby = s
return nil
}
} | [
"func",
"OnStandby",
"(",
"s",
"SideEffect",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"onStandby",
"=",
"s",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // OnStandby sets a SideEffect to run when entering the Standby state.
// Only one SideEffect can be set for this hook. | [
"OnStandby",
"sets",
"a",
"SideEffect",
"to",
"run",
"when",
"entering",
"the",
"Standby",
"state",
".",
"Only",
"one",
"SideEffect",
"can",
"be",
"set",
"for",
"this",
"hook",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L314-L319 |
27,278 | vulcand/oxy | cbreaker/cbreaker.go | Fallback | func Fallback(h http.Handler) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.fallback = h
return nil
}
} | go | func Fallback(h http.Handler) CircuitBreakerOption {
return func(c *CircuitBreaker) error {
c.fallback = h
return nil
}
} | [
"func",
"Fallback",
"(",
"h",
"http",
".",
"Handler",
")",
"CircuitBreakerOption",
"{",
"return",
"func",
"(",
"c",
"*",
"CircuitBreaker",
")",
"error",
"{",
"c",
".",
"fallback",
"=",
"h",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Fallback defines the http.Handler that the CircuitBreaker should route
// requests to when it prevents a request from taking its normal path. | [
"Fallback",
"defines",
"the",
"http",
".",
"Handler",
"that",
"the",
"CircuitBreaker",
"should",
"route",
"requests",
"to",
"when",
"it",
"prevents",
"a",
"request",
"from",
"taking",
"its",
"normal",
"path",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/cbreaker.go#L323-L328 |
27,279 | vulcand/oxy | memmetrics/ratio.go | RatioClock | func RatioClock(clock timetools.TimeProvider) ratioOptSetter {
return func(r *RatioCounter) error {
r.clock = clock
return nil
}
} | go | func RatioClock(clock timetools.TimeProvider) ratioOptSetter {
return func(r *RatioCounter) error {
r.clock = clock
return nil
}
} | [
"func",
"RatioClock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"ratioOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RatioCounter",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RatioClock sets a clock | [
"RatioClock",
"sets",
"a",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/ratio.go#L12-L17 |
27,280 | vulcand/oxy | memmetrics/ratio.go | NewRatioCounter | func NewRatioCounter(buckets int, resolution time.Duration, options ...ratioOptSetter) (*RatioCounter, error) {
rc := &RatioCounter{}
for _, o := range options {
if err := o(rc); err != nil {
return nil, err
}
}
if rc.clock == nil {
rc.clock = &timetools.RealTime{}
}
a, err := NewCounter(buckets, reso... | go | func NewRatioCounter(buckets int, resolution time.Duration, options ...ratioOptSetter) (*RatioCounter, error) {
rc := &RatioCounter{}
for _, o := range options {
if err := o(rc); err != nil {
return nil, err
}
}
if rc.clock == nil {
rc.clock = &timetools.RealTime{}
}
a, err := NewCounter(buckets, reso... | [
"func",
"NewRatioCounter",
"(",
"buckets",
"int",
",",
"resolution",
"time",
".",
"Duration",
",",
"options",
"...",
"ratioOptSetter",
")",
"(",
"*",
"RatioCounter",
",",
"error",
")",
"{",
"rc",
":=",
"&",
"RatioCounter",
"{",
"}",
"\n\n",
"for",
"_",
"... | // NewRatioCounter creates a new RatioCounter | [
"NewRatioCounter",
"creates",
"a",
"new",
"RatioCounter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/ratio.go#L27-L53 |
27,281 | vulcand/oxy | memmetrics/ratio.go | IsReady | func (r *RatioCounter) IsReady() bool {
return r.a.countedBuckets+r.b.countedBuckets >= len(r.a.values)
} | go | func (r *RatioCounter) IsReady() bool {
return r.a.countedBuckets+r.b.countedBuckets >= len(r.a.values)
} | [
"func",
"(",
"r",
"*",
"RatioCounter",
")",
"IsReady",
"(",
")",
"bool",
"{",
"return",
"r",
".",
"a",
".",
"countedBuckets",
"+",
"r",
".",
"b",
".",
"countedBuckets",
">=",
"len",
"(",
"r",
".",
"a",
".",
"values",
")",
"\n",
"}"
] | // IsReady returns true if the counter is ready | [
"IsReady",
"returns",
"true",
"if",
"the",
"counter",
"is",
"ready"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/ratio.go#L62-L64 |
27,282 | vulcand/oxy | memmetrics/ratio.go | Ratio | func (r *RatioCounter) Ratio() float64 {
a := r.a.Count()
b := r.b.Count()
// No data, return ok
if a+b == 0 {
return 0
}
return float64(a) / float64(a+b)
} | go | func (r *RatioCounter) Ratio() float64 {
a := r.a.Count()
b := r.b.Count()
// No data, return ok
if a+b == 0 {
return 0
}
return float64(a) / float64(a+b)
} | [
"func",
"(",
"r",
"*",
"RatioCounter",
")",
"Ratio",
"(",
")",
"float64",
"{",
"a",
":=",
"r",
".",
"a",
".",
"Count",
"(",
")",
"\n",
"b",
":=",
"r",
".",
"b",
".",
"Count",
"(",
")",
"\n",
"// No data, return ok",
"if",
"a",
"+",
"b",
"==",
... | // Ratio gets ratio | [
"Ratio",
"gets",
"ratio"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/ratio.go#L97-L105 |
27,283 | vulcand/oxy | connlimit/connlimit.go | New | func New(next http.Handler, extract utils.SourceExtractor, maxConnections int64, options ...ConnLimitOption) (*ConnLimiter, error) {
if extract == nil {
return nil, fmt.Errorf("Extract function can not be nil")
}
cl := &ConnLimiter{
mutex: &sync.Mutex{},
extract: extract,
maxConnections: maxC... | go | func New(next http.Handler, extract utils.SourceExtractor, maxConnections int64, options ...ConnLimitOption) (*ConnLimiter, error) {
if extract == nil {
return nil, fmt.Errorf("Extract function can not be nil")
}
cl := &ConnLimiter{
mutex: &sync.Mutex{},
extract: extract,
maxConnections: maxC... | [
"func",
"New",
"(",
"next",
"http",
".",
"Handler",
",",
"extract",
"utils",
".",
"SourceExtractor",
",",
"maxConnections",
"int64",
",",
"options",
"...",
"ConnLimitOption",
")",
"(",
"*",
"ConnLimiter",
",",
"error",
")",
"{",
"if",
"extract",
"==",
"nil... | // New creates a new ConnLimiter | [
"New",
"creates",
"a",
"new",
"ConnLimiter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/connlimit/connlimit.go#L28-L52 |
27,284 | vulcand/oxy | cbreaker/fallback.go | NewResponseFallbackWithLogger | func NewResponseFallbackWithLogger(r Response, l *log.Logger) (*ResponseFallback, error) {
if r.StatusCode == 0 {
return nil, fmt.Errorf("response code should not be 0")
}
return &ResponseFallback{r: r, log: l}, nil
} | go | func NewResponseFallbackWithLogger(r Response, l *log.Logger) (*ResponseFallback, error) {
if r.StatusCode == 0 {
return nil, fmt.Errorf("response code should not be 0")
}
return &ResponseFallback{r: r, log: l}, nil
} | [
"func",
"NewResponseFallbackWithLogger",
"(",
"r",
"Response",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"ResponseFallback",
",",
"error",
")",
"{",
"if",
"r",
".",
"StatusCode",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"("... | // NewResponseFallbackWithLogger creates a new ResponseFallback | [
"NewResponseFallbackWithLogger",
"creates",
"a",
"new",
"ResponseFallback"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/fallback.go#L28-L33 |
27,285 | vulcand/oxy | cbreaker/fallback.go | NewRedirectFallbackWithLogger | func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
u, err := url.ParseRequestURI(r.URL)
if err != nil {
return nil, err
}
return &RedirectFallback{r: r, u: u, log: l}, nil
} | go | func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
u, err := url.ParseRequestURI(r.URL)
if err != nil {
return nil, err
}
return &RedirectFallback{r: r, u: u, log: l}, nil
} | [
"func",
"NewRedirectFallbackWithLogger",
"(",
"r",
"Redirect",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"RedirectFallback",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"ParseRequestURI",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
... | // NewRedirectFallbackWithLogger creates a new RedirectFallback | [
"NewRedirectFallbackWithLogger",
"creates",
"a",
"new",
"RedirectFallback"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/fallback.go#L74-L80 |
27,286 | vulcand/oxy | ratelimit/bucket.go | newTokenBucket | func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
return &tokenBucket{
period: rate.period,
timePerToken: time.Duration(int64(rate.period) / rate.average),
burst: rate.burst,
clock: clock,
lastRefresh: clock.UtcNow(),
availableTokens: rate.burs... | go | func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
return &tokenBucket{
period: rate.period,
timePerToken: time.Duration(int64(rate.period) / rate.average),
burst: rate.burst,
clock: clock,
lastRefresh: clock.UtcNow(),
availableTokens: rate.burs... | [
"func",
"newTokenBucket",
"(",
"rate",
"*",
"rate",
",",
"clock",
"timetools",
".",
"TimeProvider",
")",
"*",
"tokenBucket",
"{",
"return",
"&",
"tokenBucket",
"{",
"period",
":",
"rate",
".",
"period",
",",
"timePerToken",
":",
"time",
".",
"Duration",
"(... | // newTokenBucket crates a `tokenBucket` instance for the specified `Rate`. | [
"newTokenBucket",
"crates",
"a",
"tokenBucket",
"instance",
"for",
"the",
"specified",
"Rate",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L46-L55 |
27,287 | vulcand/oxy | ratelimit/bucket.go | consume | func (tb *tokenBucket) consume(tokens int64) (time.Duration, error) {
tb.updateAvailableTokens()
tb.lastConsumed = 0
if tokens > tb.burst {
return UndefinedDelay, fmt.Errorf("requested tokens larger than max tokens")
}
if tb.availableTokens < tokens {
return tb.timeTillAvailable(tokens), nil
}
tb.availableTo... | go | func (tb *tokenBucket) consume(tokens int64) (time.Duration, error) {
tb.updateAvailableTokens()
tb.lastConsumed = 0
if tokens > tb.burst {
return UndefinedDelay, fmt.Errorf("requested tokens larger than max tokens")
}
if tb.availableTokens < tokens {
return tb.timeTillAvailable(tokens), nil
}
tb.availableTo... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"consume",
"(",
"tokens",
"int64",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"tb",
".",
"updateAvailableTokens",
"(",
")",
"\n",
"tb",
".",
"lastConsumed",
"=",
"0",
"\n",
"if",
"tokens",
"... | // consume makes an attempt to consume the specified number of tokens from the
// bucket. If there are enough tokens available then `0, nil` is returned; if
// tokens to consume is larger than the burst size, then an error is returned
// and the delay is not defined; otherwise returned a none zero delay that tells
// h... | [
"consume",
"makes",
"an",
"attempt",
"to",
"consume",
"the",
"specified",
"number",
"of",
"tokens",
"from",
"the",
"bucket",
".",
"If",
"there",
"are",
"enough",
"tokens",
"available",
"then",
"0",
"nil",
"is",
"returned",
";",
"if",
"tokens",
"to",
"consu... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L63-L75 |
27,288 | vulcand/oxy | ratelimit/bucket.go | update | func (tb *tokenBucket) update(rate *rate) error {
if rate.period != tb.period {
return fmt.Errorf("period mismatch: %v != %v", tb.period, rate.period)
}
tb.timePerToken = time.Duration(int64(tb.period) / rate.average)
tb.burst = rate.burst
if tb.availableTokens > rate.burst {
tb.availableTokens = rate.burst
}... | go | func (tb *tokenBucket) update(rate *rate) error {
if rate.period != tb.period {
return fmt.Errorf("period mismatch: %v != %v", tb.period, rate.period)
}
tb.timePerToken = time.Duration(int64(tb.period) / rate.average)
tb.burst = rate.burst
if tb.availableTokens > rate.burst {
tb.availableTokens = rate.burst
}... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"update",
"(",
"rate",
"*",
"rate",
")",
"error",
"{",
"if",
"rate",
".",
"period",
"!=",
"tb",
".",
"period",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tb",
".",
"period",
",",
"rate"... | // update modifies `average` and `burst` fields of the token bucket according
// to the provided `Rate` | [
"update",
"modifies",
"average",
"and",
"burst",
"fields",
"of",
"the",
"token",
"bucket",
"according",
"to",
"the",
"provided",
"Rate"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L89-L99 |
27,289 | vulcand/oxy | ratelimit/bucket.go | timeTillAvailable | func (tb *tokenBucket) timeTillAvailable(tokens int64) time.Duration {
missingTokens := tokens - tb.availableTokens
return time.Duration(missingTokens) * tb.timePerToken
} | go | func (tb *tokenBucket) timeTillAvailable(tokens int64) time.Duration {
missingTokens := tokens - tb.availableTokens
return time.Duration(missingTokens) * tb.timePerToken
} | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"timeTillAvailable",
"(",
"tokens",
"int64",
")",
"time",
".",
"Duration",
"{",
"missingTokens",
":=",
"tokens",
"-",
"tb",
".",
"availableTokens",
"\n",
"return",
"time",
".",
"Duration",
"(",
"missingTokens",
")"... | // timeTillAvailable returns the number of nanoseconds that we need to
// wait until the specified number of tokens becomes available for consumption. | [
"timeTillAvailable",
"returns",
"the",
"number",
"of",
"nanoseconds",
"that",
"we",
"need",
"to",
"wait",
"until",
"the",
"specified",
"number",
"of",
"tokens",
"becomes",
"available",
"for",
"consumption",
"."
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L103-L106 |
27,290 | vulcand/oxy | ratelimit/bucket.go | updateAvailableTokens | func (tb *tokenBucket) updateAvailableTokens() {
now := tb.clock.UtcNow()
timePassed := now.Sub(tb.lastRefresh)
tokens := tb.availableTokens + int64(timePassed/tb.timePerToken)
// If we haven't added any tokens that means that not enough time has passed,
// in this case do not adjust last refill checkpoint, other... | go | func (tb *tokenBucket) updateAvailableTokens() {
now := tb.clock.UtcNow()
timePassed := now.Sub(tb.lastRefresh)
tokens := tb.availableTokens + int64(timePassed/tb.timePerToken)
// If we haven't added any tokens that means that not enough time has passed,
// in this case do not adjust last refill checkpoint, other... | [
"func",
"(",
"tb",
"*",
"tokenBucket",
")",
"updateAvailableTokens",
"(",
")",
"{",
"now",
":=",
"tb",
".",
"clock",
".",
"UtcNow",
"(",
")",
"\n",
"timePassed",
":=",
"now",
".",
"Sub",
"(",
"tb",
".",
"lastRefresh",
")",
"\n\n",
"tokens",
":=",
"tb... | // updateAvailableTokens updates the number of tokens available for consumption.
// It is calculated based on the refill rate, the time passed since last refresh,
// and is limited by the bucket capacity. | [
"updateAvailableTokens",
"updates",
"the",
"number",
"of",
"tokens",
"available",
"for",
"consumption",
".",
"It",
"is",
"calculated",
"based",
"on",
"the",
"refill",
"rate",
"the",
"time",
"passed",
"since",
"last",
"refresh",
"and",
"is",
"limited",
"by",
"t... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/ratelimit/bucket.go#L111-L126 |
27,291 | vulcand/oxy | trace/trace.go | RequestHeaders | func RequestHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.reqHeaders = append(t.reqHeaders, headers...)
return nil
}
} | go | func RequestHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.reqHeaders = append(t.reqHeaders, headers...)
return nil
}
} | [
"func",
"RequestHeaders",
"(",
"headers",
"...",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
")",
"error",
"{",
"t",
".",
"reqHeaders",
"=",
"append",
"(",
"t",
".",
"reqHeaders",
",",
"headers",
"...",
")",
"\n",
"return",... | // RequestHeaders adds request headers to capture | [
"RequestHeaders",
"adds",
"request",
"headers",
"to",
"capture"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/trace/trace.go#L29-L34 |
27,292 | vulcand/oxy | trace/trace.go | ResponseHeaders | func ResponseHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.respHeaders = append(t.respHeaders, headers...)
return nil
}
} | go | func ResponseHeaders(headers ...string) Option {
return func(t *Tracer) error {
t.respHeaders = append(t.respHeaders, headers...)
return nil
}
} | [
"func",
"ResponseHeaders",
"(",
"headers",
"...",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"t",
"*",
"Tracer",
")",
"error",
"{",
"t",
".",
"respHeaders",
"=",
"append",
"(",
"t",
".",
"respHeaders",
",",
"headers",
"...",
")",
"\n",
"retur... | // ResponseHeaders adds response headers to capture | [
"ResponseHeaders",
"adds",
"response",
"headers",
"to",
"capture"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/trace/trace.go#L37-L42 |
27,293 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerClock | func RebalancerClock(clock timetools.TimeProvider) RebalancerOption {
return func(r *Rebalancer) error {
r.clock = clock
return nil
}
} | go | func RebalancerClock(clock timetools.TimeProvider) RebalancerOption {
return func(r *Rebalancer) error {
r.clock = clock
return nil
}
} | [
"func",
"RebalancerClock",
"(",
"clock",
"timetools",
".",
"TimeProvider",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"clock",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerClock sets a clock | [
"RebalancerClock",
"sets",
"a",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L61-L66 |
27,294 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerBackoff | func RebalancerBackoff(d time.Duration) RebalancerOption {
return func(r *Rebalancer) error {
r.backoffDuration = d
return nil
}
} | go | func RebalancerBackoff(d time.Duration) RebalancerOption {
return func(r *Rebalancer) error {
r.backoffDuration = d
return nil
}
} | [
"func",
"RebalancerBackoff",
"(",
"d",
"time",
".",
"Duration",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"backoffDuration",
"=",
"d",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerBackoff sets a beck off duration | [
"RebalancerBackoff",
"sets",
"a",
"beck",
"off",
"duration"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L69-L74 |
27,295 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerMeter | func RebalancerMeter(newMeter NewMeterFn) RebalancerOption {
return func(r *Rebalancer) error {
r.newMeter = newMeter
return nil
}
} | go | func RebalancerMeter(newMeter NewMeterFn) RebalancerOption {
return func(r *Rebalancer) error {
r.newMeter = newMeter
return nil
}
} | [
"func",
"RebalancerMeter",
"(",
"newMeter",
"NewMeterFn",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"newMeter",
"=",
"newMeter",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerMeter sets a Meter builder function | [
"RebalancerMeter",
"sets",
"a",
"Meter",
"builder",
"function"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L77-L82 |
27,296 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerErrorHandler | func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption {
return func(r *Rebalancer) error {
r.errHandler = h
return nil
}
} | go | func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption {
return func(r *Rebalancer) error {
r.errHandler = h
return nil
}
} | [
"func",
"RebalancerErrorHandler",
"(",
"h",
"utils",
".",
"ErrorHandler",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"errHandler",
"=",
"h",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // RebalancerErrorHandler is a functional argument that sets error handler of the server | [
"RebalancerErrorHandler",
"is",
"a",
"functional",
"argument",
"that",
"sets",
"error",
"handler",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L85-L90 |
27,297 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerStickySession | func RebalancerStickySession(stickySession *StickySession) RebalancerOption {
return func(r *Rebalancer) error {
r.stickySession = stickySession
return nil
}
} | go | func RebalancerStickySession(stickySession *StickySession) RebalancerOption {
return func(r *Rebalancer) error {
r.stickySession = stickySession
return nil
}
} | [
"func",
"RebalancerStickySession",
"(",
"stickySession",
"*",
"StickySession",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"stickySession",
"=",
"stickySession",
"\n",
"return",
"nil",
"\n",
"}",
"\... | // RebalancerStickySession sets a sticky session | [
"RebalancerStickySession",
"sets",
"a",
"sticky",
"session"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L93-L98 |
27,298 | vulcand/oxy | roundrobin/rebalancer.go | RebalancerRequestRewriteListener | func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption {
return func(r *Rebalancer) error {
r.requestRewriteListener = rrl
return nil
}
} | go | func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption {
return func(r *Rebalancer) error {
r.requestRewriteListener = rrl
return nil
}
} | [
"func",
"RebalancerRequestRewriteListener",
"(",
"rrl",
"RequestRewriteListener",
")",
"RebalancerOption",
"{",
"return",
"func",
"(",
"r",
"*",
"Rebalancer",
")",
"error",
"{",
"r",
".",
"requestRewriteListener",
"=",
"rrl",
"\n",
"return",
"nil",
"\n",
"}",
"\... | // RebalancerRequestRewriteListener is a functional argument that sets error handler of the server | [
"RebalancerRequestRewriteListener",
"is",
"a",
"functional",
"argument",
"that",
"sets",
"error",
"handler",
"of",
"the",
"server"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L101-L106 |
27,299 | vulcand/oxy | roundrobin/rebalancer.go | NewRebalancer | func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error) {
rb := &Rebalancer{
mtx: &sync.Mutex{},
next: handler,
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rb); err != nil {
return nil, err
}
}
if rb.clo... | go | func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error) {
rb := &Rebalancer{
mtx: &sync.Mutex{},
next: handler,
stickySession: nil,
log: log.StandardLogger(),
}
for _, o := range opts {
if err := o(rb); err != nil {
return nil, err
}
}
if rb.clo... | [
"func",
"NewRebalancer",
"(",
"handler",
"balancerHandler",
",",
"opts",
"...",
"RebalancerOption",
")",
"(",
"*",
"Rebalancer",
",",
"error",
")",
"{",
"rb",
":=",
"&",
"Rebalancer",
"{",
"mtx",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"next",
"... | // NewRebalancer creates a new Rebalancer | [
"NewRebalancer",
"creates",
"a",
"new",
"Rebalancer"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/roundrobin/rebalancer.go#L109-L145 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.