repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
libp2p/go-libp2p-crypto | ecdsa.go | Equals | func (ePriv *ECDSAPrivateKey) Equals(o Key) bool {
oPriv, ok := o.(*ECDSAPrivateKey)
if !ok {
return false
}
return ePriv.priv.D.Cmp(oPriv.priv.D) == 0
} | go | func (ePriv *ECDSAPrivateKey) Equals(o Key) bool {
oPriv, ok := o.(*ECDSAPrivateKey)
if !ok {
return false
}
return ePriv.priv.D.Cmp(oPriv.priv.D) == 0
} | [
"func",
"(",
"ePriv",
"*",
"ECDSAPrivateKey",
")",
"Equals",
"(",
"o",
"Key",
")",
"bool",
"{",
"oPriv",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"ECDSAPrivateKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"ePriv",... | // Equals compares to private keys | [
"Equals",
"compares",
"to",
"private",
"keys"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L119-L126 | test |
libp2p/go-libp2p-crypto | ecdsa.go | Sign | func (ePriv *ECDSAPrivateKey) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
r, s, err := ecdsa.Sign(rand.Reader, ePriv.priv, hash[:])
if err != nil {
return nil, err
}
return asn1.Marshal(ECDSASig{
R: r,
S: s,
})
} | go | func (ePriv *ECDSAPrivateKey) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
r, s, err := ecdsa.Sign(rand.Reader, ePriv.priv, hash[:])
if err != nil {
return nil, err
}
return asn1.Marshal(ECDSASig{
R: r,
S: s,
})
} | [
"func",
"(",
"ePriv",
"*",
"ECDSAPrivateKey",
")",
"Sign",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"hash",
":=",
"sha256",
".",
"Sum256",
"(",
"data",
")",
"\n",
"r",
",",
"s",
",",
"err",
":=",
"ecdsa... | // Sign returns the signature of the input data | [
"Sign",
"returns",
"the",
"signature",
"of",
"the",
"input",
"data"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L129-L140 | test |
libp2p/go-libp2p-crypto | ecdsa.go | Equals | func (ePub *ECDSAPublicKey) Equals(o Key) bool {
oPub, ok := o.(*ECDSAPublicKey)
if !ok {
return false
}
return ePub.pub.X != nil && ePub.pub.Y != nil && oPub.pub.X != nil && oPub.pub.Y != nil &&
0 == ePub.pub.X.Cmp(oPub.pub.X) && 0 == ePub.pub.Y.Cmp(oPub.pub.Y)
} | go | func (ePub *ECDSAPublicKey) Equals(o Key) bool {
oPub, ok := o.(*ECDSAPublicKey)
if !ok {
return false
}
return ePub.pub.X != nil && ePub.pub.Y != nil && oPub.pub.X != nil && oPub.pub.Y != nil &&
0 == ePub.pub.X.Cmp(oPub.pub.X) && 0 == ePub.pub.Y.Cmp(oPub.pub.Y)
} | [
"func",
"(",
"ePub",
"*",
"ECDSAPublicKey",
")",
"Equals",
"(",
"o",
"Key",
")",
"bool",
"{",
"oPub",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"ECDSAPublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"ePub",
".... | // Equals compares to public keys | [
"Equals",
"compares",
"to",
"public",
"keys"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L163-L171 | test |
libp2p/go-libp2p-crypto | ecdsa.go | Verify | func (ePub *ECDSAPublicKey) Verify(data, sigBytes []byte) (bool, error) {
sig := new(ECDSASig)
if _, err := asn1.Unmarshal(sigBytes, sig); err != nil {
return false, err
}
if sig == nil {
return false, ErrNilSig
}
hash := sha256.Sum256(data)
return ecdsa.Verify(ePub.pub, hash[:], sig.R, sig.S), nil
} | go | func (ePub *ECDSAPublicKey) Verify(data, sigBytes []byte) (bool, error) {
sig := new(ECDSASig)
if _, err := asn1.Unmarshal(sigBytes, sig); err != nil {
return false, err
}
if sig == nil {
return false, ErrNilSig
}
hash := sha256.Sum256(data)
return ecdsa.Verify(ePub.pub, hash[:], sig.R, sig.S), nil
} | [
"func",
"(",
"ePub",
"*",
"ECDSAPublicKey",
")",
"Verify",
"(",
"data",
",",
"sigBytes",
"[",
"]",
"byte",
")",
"(",
"bool",
",",
"error",
")",
"{",
"sig",
":=",
"new",
"(",
"ECDSASig",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"asn1",
".",
"Unmars... | // Verify compares data to a signature | [
"Verify",
"compares",
"data",
"to",
"a",
"signature"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L174-L186 | test |
libp2p/go-libp2p-crypto | secp256k1.go | GenerateSecp256k1Key | func GenerateSecp256k1Key(src io.Reader) (PrivKey, PubKey, error) {
privk, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, nil, err
}
k := (*Secp256k1PrivateKey)(privk)
return k, k.GetPublic(), nil
} | go | func GenerateSecp256k1Key(src io.Reader) (PrivKey, PubKey, error) {
privk, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return nil, nil, err
}
k := (*Secp256k1PrivateKey)(privk)
return k, k.GetPublic(), nil
} | [
"func",
"GenerateSecp256k1Key",
"(",
"src",
"io",
".",
"Reader",
")",
"(",
"PrivKey",
",",
"PubKey",
",",
"error",
")",
"{",
"privk",
",",
"err",
":=",
"btcec",
".",
"NewPrivateKey",
"(",
"btcec",
".",
"S256",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
... | // GenerateSecp256k1Key generates a new Secp256k1 private and public key pair | [
"GenerateSecp256k1Key",
"generates",
"a",
"new",
"Secp256k1",
"private",
"and",
"public",
"key",
"pair"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L20-L28 | test |
libp2p/go-libp2p-crypto | secp256k1.go | UnmarshalSecp256k1PrivateKey | func UnmarshalSecp256k1PrivateKey(data []byte) (PrivKey, error) {
if len(data) != btcec.PrivKeyBytesLen {
return nil, fmt.Errorf("expected secp256k1 data size to be %d", btcec.PrivKeyBytesLen)
}
privk, _ := btcec.PrivKeyFromBytes(btcec.S256(), data)
return (*Secp256k1PrivateKey)(privk), nil
} | go | func UnmarshalSecp256k1PrivateKey(data []byte) (PrivKey, error) {
if len(data) != btcec.PrivKeyBytesLen {
return nil, fmt.Errorf("expected secp256k1 data size to be %d", btcec.PrivKeyBytesLen)
}
privk, _ := btcec.PrivKeyFromBytes(btcec.S256(), data)
return (*Secp256k1PrivateKey)(privk), nil
} | [
"func",
"UnmarshalSecp256k1PrivateKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PrivKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"btcec",
".",
"PrivKeyBytesLen",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"expected se... | // UnmarshalSecp256k1PrivateKey returns a private key from bytes | [
"UnmarshalSecp256k1PrivateKey",
"returns",
"a",
"private",
"key",
"from",
"bytes"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L31-L38 | test |
libp2p/go-libp2p-crypto | secp256k1.go | UnmarshalSecp256k1PublicKey | func UnmarshalSecp256k1PublicKey(data []byte) (PubKey, error) {
k, err := btcec.ParsePubKey(data, btcec.S256())
if err != nil {
return nil, err
}
return (*Secp256k1PublicKey)(k), nil
} | go | func UnmarshalSecp256k1PublicKey(data []byte) (PubKey, error) {
k, err := btcec.ParsePubKey(data, btcec.S256())
if err != nil {
return nil, err
}
return (*Secp256k1PublicKey)(k), nil
} | [
"func",
"UnmarshalSecp256k1PublicKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PubKey",
",",
"error",
")",
"{",
"k",
",",
"err",
":=",
"btcec",
".",
"ParsePubKey",
"(",
"data",
",",
"btcec",
".",
"S256",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"n... | // UnmarshalSecp256k1PublicKey returns a public key from bytes | [
"UnmarshalSecp256k1PublicKey",
"returns",
"a",
"public",
"key",
"from",
"bytes"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L41-L48 | test |
libp2p/go-libp2p-crypto | secp256k1.go | Equals | func (k *Secp256k1PrivateKey) Equals(o Key) bool {
sk, ok := o.(*Secp256k1PrivateKey)
if !ok {
return false
}
return k.D.Cmp(sk.D) == 0
} | go | func (k *Secp256k1PrivateKey) Equals(o Key) bool {
sk, ok := o.(*Secp256k1PrivateKey)
if !ok {
return false
}
return k.D.Cmp(sk.D) == 0
} | [
"func",
"(",
"k",
"*",
"Secp256k1PrivateKey",
")",
"Equals",
"(",
"o",
"Key",
")",
"bool",
"{",
"sk",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"Secp256k1PrivateKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"k",
... | // Equals compares two private keys | [
"Equals",
"compares",
"two",
"private",
"keys"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L66-L73 | test |
libp2p/go-libp2p-crypto | secp256k1.go | Sign | func (k *Secp256k1PrivateKey) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
sig, err := (*btcec.PrivateKey)(k).Sign(hash[:])
if err != nil {
return nil, err
}
return sig.Serialize(), nil
} | go | func (k *Secp256k1PrivateKey) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
sig, err := (*btcec.PrivateKey)(k).Sign(hash[:])
if err != nil {
return nil, err
}
return sig.Serialize(), nil
} | [
"func",
"(",
"k",
"*",
"Secp256k1PrivateKey",
")",
"Sign",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"hash",
":=",
"sha256",
".",
"Sum256",
"(",
"data",
")",
"\n",
"sig",
",",
"err",
":=",
"(",
"*",
"btc... | // Sign returns a signature from input data | [
"Sign",
"returns",
"a",
"signature",
"from",
"input",
"data"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L76-L84 | test |
libp2p/go-libp2p-crypto | secp256k1.go | Equals | func (k *Secp256k1PublicKey) Equals(o Key) bool {
sk, ok := o.(*Secp256k1PublicKey)
if !ok {
return false
}
return (*btcec.PublicKey)(k).IsEqual((*btcec.PublicKey)(sk))
} | go | func (k *Secp256k1PublicKey) Equals(o Key) bool {
sk, ok := o.(*Secp256k1PublicKey)
if !ok {
return false
}
return (*btcec.PublicKey)(k).IsEqual((*btcec.PublicKey)(sk))
} | [
"func",
"(",
"k",
"*",
"Secp256k1PublicKey",
")",
"Equals",
"(",
"o",
"Key",
")",
"bool",
"{",
"sk",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"Secp256k1PublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"(",
"*... | // Equals compares two public keys | [
"Equals",
"compares",
"two",
"public",
"keys"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L107-L114 | test |
libp2p/go-libp2p-crypto | secp256k1.go | Verify | func (k *Secp256k1PublicKey) Verify(data []byte, sigStr []byte) (bool, error) {
sig, err := btcec.ParseDERSignature(sigStr, btcec.S256())
if err != nil {
return false, err
}
hash := sha256.Sum256(data)
return sig.Verify(hash[:], (*btcec.PublicKey)(k)), nil
} | go | func (k *Secp256k1PublicKey) Verify(data []byte, sigStr []byte) (bool, error) {
sig, err := btcec.ParseDERSignature(sigStr, btcec.S256())
if err != nil {
return false, err
}
hash := sha256.Sum256(data)
return sig.Verify(hash[:], (*btcec.PublicKey)(k)), nil
} | [
"func",
"(",
"k",
"*",
"Secp256k1PublicKey",
")",
"Verify",
"(",
"data",
"[",
"]",
"byte",
",",
"sigStr",
"[",
"]",
"byte",
")",
"(",
"bool",
",",
"error",
")",
"{",
"sig",
",",
"err",
":=",
"btcec",
".",
"ParseDERSignature",
"(",
"sigStr",
",",
"b... | // Verify compares a signature against the input data | [
"Verify",
"compares",
"a",
"signature",
"against",
"the",
"input",
"data"
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/secp256k1.go#L117-L125 | test |
libp2p/go-libp2p-crypto | ed25519.go | Raw | func (k *Ed25519PrivateKey) Raw() ([]byte, error) {
// The Ed25519 private key contains two 32-bytes curve points, the private
// key and the public key.
// It makes it more efficient to get the public key without re-computing an
// elliptic curve multiplication.
buf := make([]byte, len(k.k))
copy(buf, k.k)
ret... | go | func (k *Ed25519PrivateKey) Raw() ([]byte, error) {
// The Ed25519 private key contains two 32-bytes curve points, the private
// key and the public key.
// It makes it more efficient to get the public key without re-computing an
// elliptic curve multiplication.
buf := make([]byte, len(k.k))
copy(buf, k.k)
ret... | [
"func",
"(",
"k",
"*",
"Ed25519PrivateKey",
")",
"Raw",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"k",
".",
"k",
")",
")",
"\n",
"copy",
"(",
"buf",
",",
"k",
".",
... | // Raw private key bytes. | [
"Raw",
"private",
"key",
"bytes",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L51-L60 | test |
libp2p/go-libp2p-crypto | ed25519.go | Sign | func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error) {
return ed25519.Sign(k.k, msg), nil
} | go | func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error) {
return ed25519.Sign(k.k, msg), nil
} | [
"func",
"(",
"k",
"*",
"Ed25519PrivateKey",
")",
"Sign",
"(",
"msg",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"ed25519",
".",
"Sign",
"(",
"k",
".",
"k",
",",
"msg",
")",
",",
"nil",
"\n",
"}"
] | // Sign returns a signature from an input message. | [
"Sign",
"returns",
"a",
"signature",
"from",
"an",
"input",
"message",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L82-L84 | test |
libp2p/go-libp2p-crypto | ed25519.go | Equals | func (k *Ed25519PublicKey) Equals(o Key) bool {
edk, ok := o.(*Ed25519PublicKey)
if !ok {
return false
}
return bytes.Equal(k.k, edk.k)
} | go | func (k *Ed25519PublicKey) Equals(o Key) bool {
edk, ok := o.(*Ed25519PublicKey)
if !ok {
return false
}
return bytes.Equal(k.k, edk.k)
} | [
"func",
"(",
"k",
"*",
"Ed25519PublicKey",
")",
"Equals",
"(",
"o",
"Key",
")",
"bool",
"{",
"edk",
",",
"ok",
":=",
"o",
".",
"(",
"*",
"Ed25519PublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bytes",
"... | // Equals compares two ed25519 public keys. | [
"Equals",
"compares",
"two",
"ed25519",
"public",
"keys",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L102-L109 | test |
libp2p/go-libp2p-crypto | ed25519.go | Verify | func (k *Ed25519PublicKey) Verify(data []byte, sig []byte) (bool, error) {
return ed25519.Verify(k.k, data, sig), nil
} | go | func (k *Ed25519PublicKey) Verify(data []byte, sig []byte) (bool, error) {
return ed25519.Verify(k.k, data, sig), nil
} | [
"func",
"(",
"k",
"*",
"Ed25519PublicKey",
")",
"Verify",
"(",
"data",
"[",
"]",
"byte",
",",
"sig",
"[",
"]",
"byte",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"ed25519",
".",
"Verify",
"(",
"k",
".",
"k",
",",
"data",
",",
"sig",
")... | // Verify checks a signature agains the input data. | [
"Verify",
"checks",
"a",
"signature",
"agains",
"the",
"input",
"data",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L112-L114 | test |
libp2p/go-libp2p-crypto | ed25519.go | UnmarshalEd25519PublicKey | func UnmarshalEd25519PublicKey(data []byte) (PubKey, error) {
if len(data) != 32 {
return nil, errors.New("expect ed25519 public key data size to be 32")
}
return &Ed25519PublicKey{
k: ed25519.PublicKey(data),
}, nil
} | go | func UnmarshalEd25519PublicKey(data []byte) (PubKey, error) {
if len(data) != 32 {
return nil, errors.New("expect ed25519 public key data size to be 32")
}
return &Ed25519PublicKey{
k: ed25519.PublicKey(data),
}, nil
} | [
"func",
"UnmarshalEd25519PublicKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PubKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"!=",
"32",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"expect ed25519 public key data size to be 32\"... | // UnmarshalEd25519PublicKey returns a public key from input bytes. | [
"UnmarshalEd25519PublicKey",
"returns",
"a",
"public",
"key",
"from",
"input",
"bytes",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L117-L125 | test |
libp2p/go-libp2p-crypto | ed25519.go | UnmarshalEd25519PrivateKey | func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error) {
switch len(data) {
case ed25519.PrivateKeySize + ed25519.PublicKeySize:
// Remove the redundant public key. See issue #36.
redundantPk := data[ed25519.PrivateKeySize:]
pk := data[ed25519.PrivateKeySize-ed25519.PublicKeySize : ed25519.PrivateKeySize... | go | func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error) {
switch len(data) {
case ed25519.PrivateKeySize + ed25519.PublicKeySize:
// Remove the redundant public key. See issue #36.
redundantPk := data[ed25519.PrivateKeySize:]
pk := data[ed25519.PrivateKeySize-ed25519.PublicKeySize : ed25519.PrivateKeySize... | [
"func",
"UnmarshalEd25519PrivateKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PrivKey",
",",
"error",
")",
"{",
"switch",
"len",
"(",
"data",
")",
"{",
"case",
"ed25519",
".",
"PrivateKeySize",
"+",
"ed25519",
".",
"PublicKeySize",
":",
"redundantPk",
":... | // UnmarshalEd25519PrivateKey returns a private key from input bytes. | [
"UnmarshalEd25519PrivateKey",
"returns",
"a",
"private",
"key",
"from",
"input",
"bytes",
"."
] | 9d2fed53443f745e6dc4d02bdcc94d9742a0ca84 | https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ed25519.go#L128-L155 | test |
texttheater/golang-levenshtein | levenshtein/levenshtein.go | EditScriptForStrings | func EditScriptForStrings(source []rune, target []rune, op Options) EditScript {
return backtrace(len(source), len(target),
MatrixForStrings(source, target, op), op)
} | go | func EditScriptForStrings(source []rune, target []rune, op Options) EditScript {
return backtrace(len(source), len(target),
MatrixForStrings(source, target, op), op)
} | [
"func",
"EditScriptForStrings",
"(",
"source",
"[",
"]",
"rune",
",",
"target",
"[",
"]",
"rune",
",",
"op",
"Options",
")",
"EditScript",
"{",
"return",
"backtrace",
"(",
"len",
"(",
"source",
")",
",",
"len",
"(",
"target",
")",
",",
"MatrixForStrings"... | // EditScriptForStrings returns an optimal edit script to turn source into
// target. | [
"EditScriptForStrings",
"returns",
"an",
"optimal",
"edit",
"script",
"to",
"turn",
"source",
"into",
"target",
"."
] | d188e65d659ef53fcdb0691c12f1bba64928b649 | https://github.com/texttheater/golang-levenshtein/blob/d188e65d659ef53fcdb0691c12f1bba64928b649/levenshtein/levenshtein.go#L177-L180 | test |
texttheater/golang-levenshtein | levenshtein/levenshtein.go | EditScriptForMatrix | func EditScriptForMatrix(matrix [][]int, op Options) EditScript {
return backtrace(len(matrix)-1, len(matrix[0])-1, matrix, op)
} | go | func EditScriptForMatrix(matrix [][]int, op Options) EditScript {
return backtrace(len(matrix)-1, len(matrix[0])-1, matrix, op)
} | [
"func",
"EditScriptForMatrix",
"(",
"matrix",
"[",
"]",
"[",
"]",
"int",
",",
"op",
"Options",
")",
"EditScript",
"{",
"return",
"backtrace",
"(",
"len",
"(",
"matrix",
")",
"-",
"1",
",",
"len",
"(",
"matrix",
"[",
"0",
"]",
")",
"-",
"1",
",",
... | // EditScriptForMatrix returns an optimal edit script based on the given
// Levenshtein matrix. | [
"EditScriptForMatrix",
"returns",
"an",
"optimal",
"edit",
"script",
"based",
"on",
"the",
"given",
"Levenshtein",
"matrix",
"."
] | d188e65d659ef53fcdb0691c12f1bba64928b649 | https://github.com/texttheater/golang-levenshtein/blob/d188e65d659ef53fcdb0691c12f1bba64928b649/levenshtein/levenshtein.go#L184-L186 | test |
texttheater/golang-levenshtein | levenshtein/levenshtein.go | WriteMatrix | func WriteMatrix(source []rune, target []rune, matrix [][]int, writer io.Writer) {
fmt.Fprintf(writer, " ")
for _, targetRune := range target {
fmt.Fprintf(writer, " %c", targetRune)
}
fmt.Fprintf(writer, "\n")
fmt.Fprintf(writer, " %2d", matrix[0][0])
for j, _ := range target {
fmt.Fprintf(writer, " %2d... | go | func WriteMatrix(source []rune, target []rune, matrix [][]int, writer io.Writer) {
fmt.Fprintf(writer, " ")
for _, targetRune := range target {
fmt.Fprintf(writer, " %c", targetRune)
}
fmt.Fprintf(writer, "\n")
fmt.Fprintf(writer, " %2d", matrix[0][0])
for j, _ := range target {
fmt.Fprintf(writer, " %2d... | [
"func",
"WriteMatrix",
"(",
"source",
"[",
"]",
"rune",
",",
"target",
"[",
"]",
"rune",
",",
"matrix",
"[",
"]",
"[",
"]",
"int",
",",
"writer",
"io",
".",
"Writer",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"writer",
",",
"\" \"",
")",
"\n",
"fo... | // WriteMatrix writes a visual representation of the given matrix for the given
// strings to the given writer. | [
"WriteMatrix",
"writes",
"a",
"visual",
"representation",
"of",
"the",
"given",
"matrix",
"for",
"the",
"given",
"strings",
"to",
"the",
"given",
"writer",
"."
] | d188e65d659ef53fcdb0691c12f1bba64928b649 | https://github.com/texttheater/golang-levenshtein/blob/d188e65d659ef53fcdb0691c12f1bba64928b649/levenshtein/levenshtein.go#L190-L208 | test |
nightlyone/lockfile | lockfile.go | New | func New(path string) (Lockfile, error) {
if !filepath.IsAbs(path) {
return Lockfile(""), ErrNeedAbsPath
}
return Lockfile(path), nil
} | go | func New(path string) (Lockfile, error) {
if !filepath.IsAbs(path) {
return Lockfile(""), ErrNeedAbsPath
}
return Lockfile(path), nil
} | [
"func",
"New",
"(",
"path",
"string",
")",
"(",
"Lockfile",
",",
"error",
")",
"{",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"path",
")",
"{",
"return",
"Lockfile",
"(",
"\"\"",
")",
",",
"ErrNeedAbsPath",
"\n",
"}",
"\n",
"return",
"Lockfile",
"(",... | // New describes a new filename located at the given absolute path. | [
"New",
"describes",
"a",
"new",
"filename",
"located",
"at",
"the",
"given",
"absolute",
"path",
"."
] | 0ad87eef1443f64d3d8c50da647e2b1552851124 | https://github.com/nightlyone/lockfile/blob/0ad87eef1443f64d3d8c50da647e2b1552851124/lockfile.go#L44-L49 | test |
nightlyone/lockfile | lockfile.go | GetOwner | func (l Lockfile) GetOwner() (*os.Process, error) {
name := string(l)
// Ok, see, if we have a stale lockfile here
content, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
pid, err := scanPidLine(content)
if err !=... | go | func (l Lockfile) GetOwner() (*os.Process, error) {
name := string(l)
// Ok, see, if we have a stale lockfile here
content, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
// try hard for pids. If no pid, the lockfile is junk anyway and we delete it.
pid, err := scanPidLine(content)
if err !=... | [
"func",
"(",
"l",
"Lockfile",
")",
"GetOwner",
"(",
")",
"(",
"*",
"os",
".",
"Process",
",",
"error",
")",
"{",
"name",
":=",
"string",
"(",
"l",
")",
"\n",
"content",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"name",
")",
"\n",
"if",
... | // GetOwner returns who owns the lockfile. | [
"GetOwner",
"returns",
"who",
"owns",
"the",
"lockfile",
"."
] | 0ad87eef1443f64d3d8c50da647e2b1552851124 | https://github.com/nightlyone/lockfile/blob/0ad87eef1443f64d3d8c50da647e2b1552851124/lockfile.go#L52-L80 | test |
nightlyone/lockfile | lockfile.go | TryLock | func (l Lockfile) TryLock() error {
name := string(l)
// This has been checked by New already. If we trigger here,
// the caller didn't use New and re-implemented it's functionality badly.
// So panic, that he might find this easily during testing.
if !filepath.IsAbs(name) {
panic(ErrNeedAbsPath)
}
tmplock, ... | go | func (l Lockfile) TryLock() error {
name := string(l)
// This has been checked by New already. If we trigger here,
// the caller didn't use New and re-implemented it's functionality badly.
// So panic, that he might find this easily during testing.
if !filepath.IsAbs(name) {
panic(ErrNeedAbsPath)
}
tmplock, ... | [
"func",
"(",
"l",
"Lockfile",
")",
"TryLock",
"(",
")",
"error",
"{",
"name",
":=",
"string",
"(",
"l",
")",
"\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"name",
")",
"{",
"panic",
"(",
"ErrNeedAbsPath",
")",
"\n",
"}",
"\n",
"tmplock",
",",
"... | // TryLock tries to own the lock.
// It Returns nil, if successful and and error describing the reason, it didn't work out.
// Please note, that existing lockfiles containing pids of dead processes
// and lockfiles containing no pid at all are simply deleted. | [
"TryLock",
"tries",
"to",
"own",
"the",
"lock",
".",
"It",
"Returns",
"nil",
"if",
"successful",
"and",
"and",
"error",
"describing",
"the",
"reason",
"it",
"didn",
"t",
"work",
"out",
".",
"Please",
"note",
"that",
"existing",
"lockfiles",
"containing",
"... | 0ad87eef1443f64d3d8c50da647e2b1552851124 | https://github.com/nightlyone/lockfile/blob/0ad87eef1443f64d3d8c50da647e2b1552851124/lockfile.go#L86-L166 | test |
nightlyone/lockfile | lockfile.go | Unlock | func (l Lockfile) Unlock() error {
proc, err := l.GetOwner()
switch err {
case ErrInvalidPid, ErrDeadOwner:
return ErrRogueDeletion
case nil:
if proc.Pid == os.Getpid() {
// we really own it, so let's remove it.
return os.Remove(string(l))
}
// Not owned by me, so don't delete it.
return ErrRogueDel... | go | func (l Lockfile) Unlock() error {
proc, err := l.GetOwner()
switch err {
case ErrInvalidPid, ErrDeadOwner:
return ErrRogueDeletion
case nil:
if proc.Pid == os.Getpid() {
// we really own it, so let's remove it.
return os.Remove(string(l))
}
// Not owned by me, so don't delete it.
return ErrRogueDel... | [
"func",
"(",
"l",
"Lockfile",
")",
"Unlock",
"(",
")",
"error",
"{",
"proc",
",",
"err",
":=",
"l",
".",
"GetOwner",
"(",
")",
"\n",
"switch",
"err",
"{",
"case",
"ErrInvalidPid",
",",
"ErrDeadOwner",
":",
"return",
"ErrRogueDeletion",
"\n",
"case",
"n... | // Unlock a lock again, if we owned it. Returns any error that happend during release of lock. | [
"Unlock",
"a",
"lock",
"again",
"if",
"we",
"owned",
"it",
".",
"Returns",
"any",
"error",
"that",
"happend",
"during",
"release",
"of",
"lock",
"."
] | 0ad87eef1443f64d3d8c50da647e2b1552851124 | https://github.com/nightlyone/lockfile/blob/0ad87eef1443f64d3d8c50da647e2b1552851124/lockfile.go#L169-L190 | test |
aphistic/gomol | base.go | NewBase | func NewBase(configs ...baseConfigFunc) *Base {
b := &Base{
clock: glock.NewRealClock(),
config: NewConfig(),
logLevel: LevelDebug,
sequence: 0,
BaseAttrs: NewAttrs(),
loggers: make([]Logger, 0),
hookPreQueue: make([]HookPreQueue, 0),
}
for _, f := range configs {
f(b)
}
return b
} | go | func NewBase(configs ...baseConfigFunc) *Base {
b := &Base{
clock: glock.NewRealClock(),
config: NewConfig(),
logLevel: LevelDebug,
sequence: 0,
BaseAttrs: NewAttrs(),
loggers: make([]Logger, 0),
hookPreQueue: make([]HookPreQueue, 0),
}
for _, f := range configs {
f(b)
}
return b
} | [
"func",
"NewBase",
"(",
"configs",
"...",
"baseConfigFunc",
")",
"*",
"Base",
"{",
"b",
":=",
"&",
"Base",
"{",
"clock",
":",
"glock",
".",
"NewRealClock",
"(",
")",
",",
"config",
":",
"NewConfig",
"(",
")",
",",
"logLevel",
":",
"LevelDebug",
",",
... | // NewBase creates a new instance of Base with default values set. | [
"NewBase",
"creates",
"a",
"new",
"instance",
"of",
"Base",
"with",
"default",
"values",
"set",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L45-L63 | test |
aphistic/gomol | base.go | SetFallbackLogger | func (b *Base) SetFallbackLogger(logger Logger) error {
if logger == nil {
if b.fallbackLogger != nil && b.fallbackLogger.IsInitialized() {
b.fallbackLogger.ShutdownLogger()
}
b.fallbackLogger = nil
return nil
}
if !logger.IsInitialized() {
err := logger.InitLogger()
if err != nil {
return err
}... | go | func (b *Base) SetFallbackLogger(logger Logger) error {
if logger == nil {
if b.fallbackLogger != nil && b.fallbackLogger.IsInitialized() {
b.fallbackLogger.ShutdownLogger()
}
b.fallbackLogger = nil
return nil
}
if !logger.IsInitialized() {
err := logger.InitLogger()
if err != nil {
return err
}... | [
"func",
"(",
"b",
"*",
"Base",
")",
"SetFallbackLogger",
"(",
"logger",
"Logger",
")",
"error",
"{",
"if",
"logger",
"==",
"nil",
"{",
"if",
"b",
".",
"fallbackLogger",
"!=",
"nil",
"&&",
"b",
".",
"fallbackLogger",
".",
"IsInitialized",
"(",
")",
"{",... | // SetFallbackLogger sets a Logger to be used if there aren't any loggers added or any of
// the added loggers are in a degraded or unhealthy state. A Logger passed to SetFallbackLogger
// will be initialized if it hasn't been already. In addition, if the Logger fails to initialize
// completely the fallback logger w... | [
"SetFallbackLogger",
"sets",
"a",
"Logger",
"to",
"be",
"used",
"if",
"there",
"aren",
"t",
"any",
"loggers",
"added",
"or",
"any",
"of",
"the",
"added",
"loggers",
"are",
"in",
"a",
"degraded",
"or",
"unhealthy",
"state",
".",
"A",
"Logger",
"passed",
"... | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L118-L142 | test |
aphistic/gomol | base.go | AddLogger | func (b *Base) AddLogger(logger Logger) error {
if b.IsInitialized() && !logger.IsInitialized() {
err := logger.InitLogger()
if err != nil {
return err
}
} else if !b.IsInitialized() && logger.IsInitialized() {
err := logger.ShutdownLogger()
if err != nil {
return err
}
}
b.loggers = append(b.logg... | go | func (b *Base) AddLogger(logger Logger) error {
if b.IsInitialized() && !logger.IsInitialized() {
err := logger.InitLogger()
if err != nil {
return err
}
} else if !b.IsInitialized() && logger.IsInitialized() {
err := logger.ShutdownLogger()
if err != nil {
return err
}
}
b.loggers = append(b.logg... | [
"func",
"(",
"b",
"*",
"Base",
")",
"AddLogger",
"(",
"logger",
"Logger",
")",
"error",
"{",
"if",
"b",
".",
"IsInitialized",
"(",
")",
"&&",
"!",
"logger",
".",
"IsInitialized",
"(",
")",
"{",
"err",
":=",
"logger",
".",
"InitLogger",
"(",
")",
"\... | // AddLogger adds a new logger instance to the Base | [
"AddLogger",
"adds",
"a",
"new",
"logger",
"instance",
"to",
"the",
"Base"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L145-L165 | test |
aphistic/gomol | base.go | LogWithTime | func (b *Base) LogWithTime(level LogLevel, ts time.Time, m *Attrs, msg string, a ...interface{}) error {
if !b.shouldLog(level) {
return nil
}
if !b.isInitialized {
return ErrNotInitialized
}
if len(b.config.FilenameAttr) > 0 || len(b.config.LineNumberAttr) > 0 {
file, line := getCallerInfo()
if m == nil... | go | func (b *Base) LogWithTime(level LogLevel, ts time.Time, m *Attrs, msg string, a ...interface{}) error {
if !b.shouldLog(level) {
return nil
}
if !b.isInitialized {
return ErrNotInitialized
}
if len(b.config.FilenameAttr) > 0 || len(b.config.LineNumberAttr) > 0 {
file, line := getCallerInfo()
if m == nil... | [
"func",
"(",
"b",
"*",
"Base",
")",
"LogWithTime",
"(",
"level",
"LogLevel",
",",
"ts",
"time",
".",
"Time",
",",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"b",
".",
"shouldLog"... | // LogWithTime will log a message at the provided level to all added loggers with the timestamp set to the
// value of ts. | [
"LogWithTime",
"will",
"log",
"a",
"message",
"at",
"the",
"provided",
"level",
"to",
"all",
"added",
"loggers",
"with",
"the",
"timestamp",
"set",
"to",
"the",
"value",
"of",
"ts",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L318-L358 | test |
aphistic/gomol | base.go | Log | func (b *Base) Log(level LogLevel, m *Attrs, msg string, a ...interface{}) error {
return b.LogWithTime(level, b.clock.Now(), m, msg, a...)
} | go | func (b *Base) Log(level LogLevel, m *Attrs, msg string, a ...interface{}) error {
return b.LogWithTime(level, b.clock.Now(), m, msg, a...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"Log",
"(",
"level",
"LogLevel",
",",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"b",
".",
"LogWithTime",
"(",
"level",
",",
"b",
".",
"clock",... | // Log will log a message at the provided level to all added loggers with the timestamp set to the time
// Log was called. | [
"Log",
"will",
"log",
"a",
"message",
"at",
"the",
"provided",
"level",
"to",
"all",
"added",
"loggers",
"with",
"the",
"timestamp",
"set",
"to",
"the",
"time",
"Log",
"was",
"called",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L362-L364 | test |
aphistic/gomol | base.go | Warnm | func (b *Base) Warnm(m *Attrs, msg string, a ...interface{}) error {
return b.Warningm(m, msg, a...)
} | go | func (b *Base) Warnm(m *Attrs, msg string, a ...interface{}) error {
return b.Warningm(m, msg, a...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"Warnm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"b",
".",
"Warningm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Warnm is a short-hand version of Warningm | [
"Warnm",
"is",
"a",
"short",
"-",
"hand",
"version",
"of",
"Warningm"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/base.go#L438-L440 | test |
aphistic/gomol | template.go | NewTemplateWithFuncMap | func NewTemplateWithFuncMap(tpl string, funcMap template.FuncMap) (*Template, error) {
var levels = []LogLevel{LevelNone, LevelDebug, LevelInfo, LevelWarning, LevelError, LevelFatal}
tpls := make(map[LogLevel]*template.Template, 0)
for _, level := range levels {
// If color is overridden, we need to ensure that {{... | go | func NewTemplateWithFuncMap(tpl string, funcMap template.FuncMap) (*Template, error) {
var levels = []LogLevel{LevelNone, LevelDebug, LevelInfo, LevelWarning, LevelError, LevelFatal}
tpls := make(map[LogLevel]*template.Template, 0)
for _, level := range levels {
// If color is overridden, we need to ensure that {{... | [
"func",
"NewTemplateWithFuncMap",
"(",
"tpl",
"string",
",",
"funcMap",
"template",
".",
"FuncMap",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"var",
"levels",
"=",
"[",
"]",
"LogLevel",
"{",
"LevelNone",
",",
"LevelDebug",
",",
"LevelInfo",
",",
... | // NewTemplateWithFuncMap creates a new Template from the given string and a template FuncMap. The FuncMap available
// to the template during evaluation will also include the default values, if not overridden. An error is returned
// if the template fails to compile. | [
"NewTemplateWithFuncMap",
"creates",
"a",
"new",
"Template",
"from",
"the",
"given",
"string",
"and",
"a",
"template",
"FuncMap",
".",
"The",
"FuncMap",
"available",
"to",
"the",
"template",
"during",
"evaluation",
"will",
"also",
"include",
"the",
"default",
"v... | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/template.go#L110-L135 | test |
aphistic/gomol | template.go | Execute | func (t *Template) Execute(msg *TemplateMsg, colorize bool) (string, error) {
tplLevel := msg.Level
if !colorize {
tplLevel = LevelNone
}
var buf bytes.Buffer
execTpl := t.tpls[tplLevel]
if execTpl == nil {
return "", ErrUnknownLevel
}
err := execTpl.Execute(&buf, msg)
if err != nil {
return "", err
}
... | go | func (t *Template) Execute(msg *TemplateMsg, colorize bool) (string, error) {
tplLevel := msg.Level
if !colorize {
tplLevel = LevelNone
}
var buf bytes.Buffer
execTpl := t.tpls[tplLevel]
if execTpl == nil {
return "", ErrUnknownLevel
}
err := execTpl.Execute(&buf, msg)
if err != nil {
return "", err
}
... | [
"func",
"(",
"t",
"*",
"Template",
")",
"Execute",
"(",
"msg",
"*",
"TemplateMsg",
",",
"colorize",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"tplLevel",
":=",
"msg",
".",
"Level",
"\n",
"if",
"!",
"colorize",
"{",
"tplLevel",
"=",
"LevelNo... | // Execute takes a TemplateMsg and applies it to the Go template. If colorize is true the template
// will insert ANSI color codes within the resulting string. | [
"Execute",
"takes",
"a",
"TemplateMsg",
"and",
"applies",
"it",
"to",
"the",
"Go",
"template",
".",
"If",
"colorize",
"is",
"true",
"the",
"template",
"will",
"insert",
"ANSI",
"color",
"codes",
"within",
"the",
"resulting",
"string",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/template.go#L148-L164 | test |
aphistic/gomol | template.go | NewTemplateMsg | func NewTemplateMsg(timestamp time.Time, level LogLevel, m map[string]interface{}, msg string) *TemplateMsg {
msgAttrs := m
if msgAttrs == nil {
msgAttrs = make(map[string]interface{})
}
tplMsg := &TemplateMsg{
Timestamp: timestamp,
Message: msg,
Level: level,
LevelName: level.String(),
Attrs: ... | go | func NewTemplateMsg(timestamp time.Time, level LogLevel, m map[string]interface{}, msg string) *TemplateMsg {
msgAttrs := m
if msgAttrs == nil {
msgAttrs = make(map[string]interface{})
}
tplMsg := &TemplateMsg{
Timestamp: timestamp,
Message: msg,
Level: level,
LevelName: level.String(),
Attrs: ... | [
"func",
"NewTemplateMsg",
"(",
"timestamp",
"time",
".",
"Time",
",",
"level",
"LogLevel",
",",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"msg",
"string",
")",
"*",
"TemplateMsg",
"{",
"msgAttrs",
":=",
"m",
"\n",
"if",
"msgAttrs",
"=... | // NewTemplateMsg will create a new TemplateMsg with values from the given parameters | [
"NewTemplateMsg",
"will",
"create",
"a",
"new",
"TemplateMsg",
"with",
"values",
"from",
"the",
"given",
"parameters"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/template.go#L176-L189 | test |
aphistic/gomol | log_adapter.go | NewLogAdapterFor | func NewLogAdapterFor(base WrappableLogger, attrs *Attrs) *LogAdapter {
if attrs == nil {
attrs = NewAttrs()
}
return &LogAdapter{
base: base,
attrs: attrs,
}
} | go | func NewLogAdapterFor(base WrappableLogger, attrs *Attrs) *LogAdapter {
if attrs == nil {
attrs = NewAttrs()
}
return &LogAdapter{
base: base,
attrs: attrs,
}
} | [
"func",
"NewLogAdapterFor",
"(",
"base",
"WrappableLogger",
",",
"attrs",
"*",
"Attrs",
")",
"*",
"LogAdapter",
"{",
"if",
"attrs",
"==",
"nil",
"{",
"attrs",
"=",
"NewAttrs",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"LogAdapter",
"{",
"base",
":",
"b... | // NewLogAdapterFor creates a LogAdapter that wraps the given loger with the
// given attributes. | [
"NewLogAdapterFor",
"creates",
"a",
"LogAdapter",
"that",
"wraps",
"the",
"given",
"loger",
"with",
"the",
"given",
"attributes",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/log_adapter.go#L37-L46 | test |
aphistic/gomol | log_adapter.go | SetAttr | func (la *LogAdapter) SetAttr(key string, value interface{}) {
la.attrs.SetAttr(key, value)
} | go | func (la *LogAdapter) SetAttr(key string, value interface{}) {
la.attrs.SetAttr(key, value)
} | [
"func",
"(",
"la",
"*",
"LogAdapter",
")",
"SetAttr",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"la",
".",
"attrs",
".",
"SetAttr",
"(",
"key",
",",
"value",
")",
"\n",
"}"
] | // SetAttr sets the attribute key to value for this LogAdapter only | [
"SetAttr",
"sets",
"the",
"attribute",
"key",
"to",
"value",
"for",
"this",
"LogAdapter",
"only"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/log_adapter.go#L57-L59 | test |
aphistic/gomol | log_adapter.go | LogWithTime | func (la *LogAdapter) LogWithTime(level LogLevel, ts time.Time, attrs *Attrs, msg string, a ...interface{}) error {
if la.logLevel != nil && level > *la.logLevel {
return nil
}
mergedAttrs := la.attrs.clone()
mergedAttrs.MergeAttrs(attrs)
return la.base.LogWithTime(level, ts, mergedAttrs, msg, a...)
} | go | func (la *LogAdapter) LogWithTime(level LogLevel, ts time.Time, attrs *Attrs, msg string, a ...interface{}) error {
if la.logLevel != nil && level > *la.logLevel {
return nil
}
mergedAttrs := la.attrs.clone()
mergedAttrs.MergeAttrs(attrs)
return la.base.LogWithTime(level, ts, mergedAttrs, msg, a...)
} | [
"func",
"(",
"la",
"*",
"LogAdapter",
")",
"LogWithTime",
"(",
"level",
"LogLevel",
",",
"ts",
"time",
".",
"Time",
",",
"attrs",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"la",
".",
"logLe... | // LogWithTime will log a message at the provided level to all loggers added
// to the Base associated with this LogAdapter. It is similar to Log except
// the timestamp will be set to the value of ts. | [
"LogWithTime",
"will",
"log",
"a",
"message",
"at",
"the",
"provided",
"level",
"to",
"all",
"loggers",
"added",
"to",
"the",
"Base",
"associated",
"with",
"this",
"LogAdapter",
".",
"It",
"is",
"similar",
"to",
"Log",
"except",
"the",
"timestamp",
"will",
... | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/log_adapter.go#L80-L88 | test |
aphistic/gomol | log_adapter.go | Log | func (la *LogAdapter) Log(level LogLevel, attrs *Attrs, msg string, a ...interface{}) error {
if la.logLevel != nil && level > *la.logLevel {
return nil
}
mergedAttrs := la.attrs.clone()
mergedAttrs.MergeAttrs(attrs)
return la.base.Log(level, mergedAttrs, msg, a...)
} | go | func (la *LogAdapter) Log(level LogLevel, attrs *Attrs, msg string, a ...interface{}) error {
if la.logLevel != nil && level > *la.logLevel {
return nil
}
mergedAttrs := la.attrs.clone()
mergedAttrs.MergeAttrs(attrs)
return la.base.Log(level, mergedAttrs, msg, a...)
} | [
"func",
"(",
"la",
"*",
"LogAdapter",
")",
"Log",
"(",
"level",
"LogLevel",
",",
"attrs",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"la",
".",
"logLevel",
"!=",
"nil",
"&&",
"level",
">",
... | // Log will log a message at the provided level to all loggers added
// to the Base associated with this LogAdapter | [
"Log",
"will",
"log",
"a",
"message",
"at",
"the",
"provided",
"level",
"to",
"all",
"loggers",
"added",
"to",
"the",
"Base",
"associated",
"with",
"this",
"LogAdapter"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/log_adapter.go#L92-L100 | test |
aphistic/gomol | log_adapter.go | Dbgm | func (la *LogAdapter) Dbgm(m *Attrs, msg string, a ...interface{}) error {
return la.Debugm(m, msg, a...)
} | go | func (la *LogAdapter) Dbgm(m *Attrs, msg string, a ...interface{}) error {
return la.Debugm(m, msg, a...)
} | [
"func",
"(",
"la",
"*",
"LogAdapter",
")",
"Dbgm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"la",
".",
"Debugm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Dbgm is a short-hand version of Debugm | [
"Dbgm",
"is",
"a",
"short",
"-",
"hand",
"version",
"of",
"Debugm"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/log_adapter.go#L113-L115 | test |
aphistic/gomol | attrs.go | NewAttrsFromMap | func NewAttrsFromMap(attrs map[string]interface{}) *Attrs {
newAttrs := NewAttrs()
for attrKey, attrVal := range attrs {
newAttrs.SetAttr(attrKey, attrVal)
}
return newAttrs
} | go | func NewAttrsFromMap(attrs map[string]interface{}) *Attrs {
newAttrs := NewAttrs()
for attrKey, attrVal := range attrs {
newAttrs.SetAttr(attrKey, attrVal)
}
return newAttrs
} | [
"func",
"NewAttrsFromMap",
"(",
"attrs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Attrs",
"{",
"newAttrs",
":=",
"NewAttrs",
"(",
")",
"\n",
"for",
"attrKey",
",",
"attrVal",
":=",
"range",
"attrs",
"{",
"newAttrs",
".",
"SetAttr",
... | // NewAttrsFromMap will create a new Attrs struct with the given attributes pre-populated | [
"NewAttrsFromMap",
"will",
"create",
"a",
"new",
"Attrs",
"struct",
"with",
"the",
"given",
"attributes",
"pre",
"-",
"populated"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L25-L31 | test |
aphistic/gomol | attrs.go | NewAttrsFromAttrs | func NewAttrsFromAttrs(attrs ...*Attrs) *Attrs {
newAttrs := NewAttrs()
for _, attr := range attrs {
newAttrs.MergeAttrs(attr)
}
return newAttrs
} | go | func NewAttrsFromAttrs(attrs ...*Attrs) *Attrs {
newAttrs := NewAttrs()
for _, attr := range attrs {
newAttrs.MergeAttrs(attr)
}
return newAttrs
} | [
"func",
"NewAttrsFromAttrs",
"(",
"attrs",
"...",
"*",
"Attrs",
")",
"*",
"Attrs",
"{",
"newAttrs",
":=",
"NewAttrs",
"(",
")",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"attrs",
"{",
"newAttrs",
".",
"MergeAttrs",
"(",
"attr",
")",
"\n",
"}",
"\... | // NewAttrsFromAttrs is a convenience function that will accept zero or more existing Attrs, create
// a new Attrs and then merge all the supplied Attrs values into the new Attrs instance. | [
"NewAttrsFromAttrs",
"is",
"a",
"convenience",
"function",
"that",
"will",
"accept",
"zero",
"or",
"more",
"existing",
"Attrs",
"create",
"a",
"new",
"Attrs",
"and",
"then",
"merge",
"all",
"the",
"supplied",
"Attrs",
"values",
"into",
"the",
"new",
"Attrs",
... | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L35-L41 | test |
aphistic/gomol | attrs.go | MergeAttrs | func (a *Attrs) MergeAttrs(attrs *Attrs) {
if attrs == nil {
return
}
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
for hash, val := range attrs.attrs {
a.attrs[hash] = val
}
} | go | func (a *Attrs) MergeAttrs(attrs *Attrs) {
if attrs == nil {
return
}
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
for hash, val := range attrs.attrs {
a.attrs[hash] = val
}
} | [
"func",
"(",
"a",
"*",
"Attrs",
")",
"MergeAttrs",
"(",
"attrs",
"*",
"Attrs",
")",
"{",
"if",
"attrs",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"a",
".",
"attrsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"attrsLock",
".",
"Unlock"... | // MergeAttrs accepts another existing Attrs and merges the attributes into its own. | [
"MergeAttrs",
"accepts",
"another",
"existing",
"Attrs",
"and",
"merges",
"the",
"attributes",
"into",
"its",
"own",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L44-L53 | test |
aphistic/gomol | attrs.go | SetAttr | func (a *Attrs) SetAttr(key string, value interface{}) *Attrs {
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
valVal := reflect.ValueOf(value)
switch valVal.Kind() {
case reflect.Func:
value = valVal.Type().String()
}
hash := getAttrHash(key)
a.attrs[hash] = value
return a
} | go | func (a *Attrs) SetAttr(key string, value interface{}) *Attrs {
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
valVal := reflect.ValueOf(value)
switch valVal.Kind() {
case reflect.Func:
value = valVal.Type().String()
}
hash := getAttrHash(key)
a.attrs[hash] = value
return a
} | [
"func",
"(",
"a",
"*",
"Attrs",
")",
"SetAttr",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"Attrs",
"{",
"a",
".",
"attrsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"attrsLock",
".",
"Unlock",
"(",
")",
"\n",
... | // SetAttr will set key to the provided value. If the attribute already exists the value will
// be replaced with the new value. | [
"SetAttr",
"will",
"set",
"key",
"to",
"the",
"provided",
"value",
".",
"If",
"the",
"attribute",
"already",
"exists",
"the",
"value",
"will",
"be",
"replaced",
"with",
"the",
"new",
"value",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L65-L78 | test |
aphistic/gomol | attrs.go | GetAttr | func (a *Attrs) GetAttr(key string) interface{} {
a.attrsLock.RLock()
defer a.attrsLock.RUnlock()
return a.attrs[getAttrHash(key)]
} | go | func (a *Attrs) GetAttr(key string) interface{} {
a.attrsLock.RLock()
defer a.attrsLock.RUnlock()
return a.attrs[getAttrHash(key)]
} | [
"func",
"(",
"a",
"*",
"Attrs",
")",
"GetAttr",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"a",
".",
"attrsLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"a",
".",
"attrsLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"a",
".",
"attrs... | // GetAttr gets the value of the attribute with the provided name. If the attribute does not
// exist, nil will be returned | [
"GetAttr",
"gets",
"the",
"value",
"of",
"the",
"attribute",
"with",
"the",
"provided",
"name",
".",
"If",
"the",
"attribute",
"does",
"not",
"exist",
"nil",
"will",
"be",
"returned"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L82-L87 | test |
aphistic/gomol | attrs.go | RemoveAttr | func (a *Attrs) RemoveAttr(key string) {
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
delete(a.attrs, getAttrHash(key))
} | go | func (a *Attrs) RemoveAttr(key string) {
a.attrsLock.Lock()
defer a.attrsLock.Unlock()
delete(a.attrs, getAttrHash(key))
} | [
"func",
"(",
"a",
"*",
"Attrs",
")",
"RemoveAttr",
"(",
"key",
"string",
")",
"{",
"a",
".",
"attrsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"attrsLock",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"a",
".",
"attrs",
",",
"getAttrH... | // RemoveAttr will remove the attribute with the provided name. | [
"RemoveAttr",
"will",
"remove",
"the",
"attribute",
"with",
"the",
"provided",
"name",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L90-L95 | test |
aphistic/gomol | attrs.go | Attrs | func (a *Attrs) Attrs() map[string]interface{} {
a.attrsLock.RLock()
defer a.attrsLock.RUnlock()
attrs := make(map[string]interface{})
for hash, val := range a.attrs {
key, _ := getHashAttr(hash)
attrs[key] = val
}
return attrs
} | go | func (a *Attrs) Attrs() map[string]interface{} {
a.attrsLock.RLock()
defer a.attrsLock.RUnlock()
attrs := make(map[string]interface{})
for hash, val := range a.attrs {
key, _ := getHashAttr(hash)
attrs[key] = val
}
return attrs
} | [
"func",
"(",
"a",
"*",
"Attrs",
")",
"Attrs",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"a",
".",
"attrsLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"a",
".",
"attrsLock",
".",
"RUnlock",
"(",
")",
"\n",
"attrs",
":=",
"... | // Attrs will return a map of the attributes added to the struct. | [
"Attrs",
"will",
"return",
"a",
"map",
"of",
"the",
"attributes",
"added",
"to",
"the",
"struct",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/attrs.go#L98-L108 | test |
aphistic/gomol | default.go | Debugm | func Debugm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Debugm(m, msg, a...)
} | go | func Debugm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Debugm(m, msg, a...)
} | [
"func",
"Debugm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"curDefault",
".",
"Debugm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Debugm executes the same function on the default Base instance | [
"Debugm",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L121-L123 | test |
aphistic/gomol | default.go | Infom | func Infom(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Infom(m, msg, a...)
} | go | func Infom(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Infom(m, msg, a...)
} | [
"func",
"Infom",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"curDefault",
".",
"Infom",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Infom executes the same function on the default Base instance | [
"Infom",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L136-L138 | test |
aphistic/gomol | default.go | Warningm | func Warningm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Warningm(m, msg, a...)
} | go | func Warningm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Warningm(m, msg, a...)
} | [
"func",
"Warningm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"curDefault",
".",
"Warningm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Warningm executes the same function on the default Base instance | [
"Warningm",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L166-L168 | test |
aphistic/gomol | default.go | Errm | func Errm(m *Attrs, msg string, a ...interface{}) error {
return Errorm(m, msg, a...)
} | go | func Errm(m *Attrs, msg string, a ...interface{}) error {
return Errorm(m, msg, a...)
} | [
"func",
"Errm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Errorm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Errm executes the same function on the default Base instance | [
"Errm",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L181-L183 | test |
aphistic/gomol | default.go | Errorm | func Errorm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Errorm(m, msg, a...)
} | go | func Errorm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Errorm(m, msg, a...)
} | [
"func",
"Errorm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"curDefault",
".",
"Errorm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Errorm executes the same function on the default Base instance | [
"Errorm",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L196-L198 | test |
aphistic/gomol | default.go | Fatalm | func Fatalm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Fatalm(m, msg, a...)
} | go | func Fatalm(m *Attrs, msg string, a ...interface{}) error {
return curDefault.Fatalm(m, msg, a...)
} | [
"func",
"Fatalm",
"(",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"curDefault",
".",
"Fatalm",
"(",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Fatalm executes the same function on the default Base instance | [
"Fatalm",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L211-L213 | test |
aphistic/gomol | default.go | Dief | func Dief(exitCode int, msg string, a ...interface{}) {
curDefault.Dief(exitCode, msg, a...)
} | go | func Dief(exitCode int, msg string, a ...interface{}) {
curDefault.Dief(exitCode, msg, a...)
} | [
"func",
"Dief",
"(",
"exitCode",
"int",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"curDefault",
".",
"Dief",
"(",
"exitCode",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Dief executes the same function on the default Base instance | [
"Dief",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L221-L223 | test |
aphistic/gomol | default.go | Diem | func Diem(exitCode int, m *Attrs, msg string, a ...interface{}) {
curDefault.Diem(exitCode, m, msg, a...)
} | go | func Diem(exitCode int, m *Attrs, msg string, a ...interface{}) {
curDefault.Diem(exitCode, m, msg, a...)
} | [
"func",
"Diem",
"(",
"exitCode",
"int",
",",
"m",
"*",
"Attrs",
",",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"curDefault",
".",
"Diem",
"(",
"exitCode",
",",
"m",
",",
"msg",
",",
"a",
"...",
")",
"\n",
"}"
] | // Diem executes the same function on the default Base instance | [
"Diem",
"executes",
"the",
"same",
"function",
"on",
"the",
"default",
"Base",
"instance"
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/default.go#L226-L228 | test |
aphistic/gomol | message.go | ToLogLevel | func ToLogLevel(level string) (LogLevel, error) {
lowLevel := strings.ToLower(level)
switch lowLevel {
case "dbg":
fallthrough
case "debug":
return LevelDebug, nil
case "info":
return LevelInfo, nil
case "warn":
fallthrough
case "warning":
return LevelWarning, nil
case "err":
fallthrough
case "err... | go | func ToLogLevel(level string) (LogLevel, error) {
lowLevel := strings.ToLower(level)
switch lowLevel {
case "dbg":
fallthrough
case "debug":
return LevelDebug, nil
case "info":
return LevelInfo, nil
case "warn":
fallthrough
case "warning":
return LevelWarning, nil
case "err":
fallthrough
case "err... | [
"func",
"ToLogLevel",
"(",
"level",
"string",
")",
"(",
"LogLevel",
",",
"error",
")",
"{",
"lowLevel",
":=",
"strings",
".",
"ToLower",
"(",
"level",
")",
"\n",
"switch",
"lowLevel",
"{",
"case",
"\"dbg\"",
":",
"fallthrough",
"\n",
"case",
"\"debug\"",
... | // ToLogLevel will take a string and return the appropriate log level for
// the string if known. If the string is not recognized it will return
// an ErrUnknownLevel error. | [
"ToLogLevel",
"will",
"take",
"a",
"string",
"and",
"return",
"the",
"appropriate",
"log",
"level",
"for",
"the",
"string",
"if",
"known",
".",
"If",
"the",
"string",
"is",
"not",
"recognized",
"it",
"will",
"return",
"an",
"ErrUnknownLevel",
"error",
"."
] | 1546845ba714699f76f484ad3af64cf0503064d1 | https://github.com/aphistic/gomol/blob/1546845ba714699f76f484ad3af64cf0503064d1/message.go#L49-L74 | test |
faiface/mainthread | mainthread.go | CallErr | func CallErr(f func() error) error {
checkRun()
errChan := make(chan error)
callQueue <- func() {
errChan <- f()
}
return <-errChan
} | go | func CallErr(f func() error) error {
checkRun()
errChan := make(chan error)
callQueue <- func() {
errChan <- f()
}
return <-errChan
} | [
"func",
"CallErr",
"(",
"f",
"func",
"(",
")",
"error",
")",
"error",
"{",
"checkRun",
"(",
")",
"\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"callQueue",
"<-",
"func",
"(",
")",
"{",
"errChan",
"<-",
"f",
"(",
")",
"\n",
"}",
... | // CallErr queues function f on the main thread and returns an error returned by f. | [
"CallErr",
"queues",
"function",
"f",
"on",
"the",
"main",
"thread",
"and",
"returns",
"an",
"error",
"returned",
"by",
"f",
"."
] | 8b78f0a41ae388189090ac4506612659fa53082b | https://github.com/faiface/mainthread/blob/8b78f0a41ae388189090ac4506612659fa53082b/mainthread.go#L70-L77 | test |
knq/sdhook | sdhook.go | New | func New(opts ...Option) (*StackdriverHook, error) {
var err error
sh := &StackdriverHook{
levels: logrus.AllLevels,
}
// apply opts
for _, o := range opts {
err = o(sh)
if err != nil {
return nil, err
}
}
// check service, resource, logName set
if sh.service == nil && sh.agentClient == nil {
re... | go | func New(opts ...Option) (*StackdriverHook, error) {
var err error
sh := &StackdriverHook{
levels: logrus.AllLevels,
}
// apply opts
for _, o := range opts {
err = o(sh)
if err != nil {
return nil, err
}
}
// check service, resource, logName set
if sh.service == nil && sh.agentClient == nil {
re... | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"StackdriverHook",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"sh",
":=",
"&",
"StackdriverHook",
"{",
"levels",
":",
"logrus",
".",
"AllLevels",
",",
"}",
"\n",
"for",
"_",
",",
... | // New creates a StackdriverHook using the provided options that is suitible
// for using with logrus for logging to Google Stackdriver. | [
"New",
"creates",
"a",
"StackdriverHook",
"using",
"the",
"provided",
"options",
"that",
"is",
"suitible",
"for",
"using",
"with",
"logrus",
"for",
"logging",
"to",
"Google",
"Stackdriver",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/sdhook.go#L80-L121 | test |
knq/sdhook | sdhook.go | Fire | func (sh *StackdriverHook) Fire(entry *logrus.Entry) error {
sh.waitGroup.Add(1)
go func(entry *logrus.Entry) {
defer sh.waitGroup.Done()
var httpReq *logging.HttpRequest
// convert entry data to labels
labels := make(map[string]string, len(entry.Data))
for k, v := range entry.Data {
switch x := v.(type... | go | func (sh *StackdriverHook) Fire(entry *logrus.Entry) error {
sh.waitGroup.Add(1)
go func(entry *logrus.Entry) {
defer sh.waitGroup.Done()
var httpReq *logging.HttpRequest
// convert entry data to labels
labels := make(map[string]string, len(entry.Data))
for k, v := range entry.Data {
switch x := v.(type... | [
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"Fire",
"(",
"entry",
"*",
"logrus",
".",
"Entry",
")",
"error",
"{",
"sh",
".",
"waitGroup",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"entry",
"*",
"logrus",
".",
"Entry",
")",
"{",
"def... | // Fire writes the message to the Stackdriver entry service. | [
"Fire",
"writes",
"the",
"message",
"to",
"the",
"Stackdriver",
"entry",
"service",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/sdhook.go#L144-L183 | test |
knq/sdhook | opts.go | Levels | func Levels(levels ...logrus.Level) Option {
return func(sh *StackdriverHook) error {
sh.levels = levels
return nil
}
} | go | func Levels(levels ...logrus.Level) Option {
return func(sh *StackdriverHook) error {
sh.levels = levels
return nil
}
} | [
"func",
"Levels",
"(",
"levels",
"...",
"logrus",
".",
"Level",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"levels",
"=",
"levels",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Levels is an option that sets the logrus levels that the StackdriverHook
// will create log entries for. | [
"Levels",
"is",
"an",
"option",
"that",
"sets",
"the",
"logrus",
"levels",
"that",
"the",
"StackdriverHook",
"will",
"create",
"log",
"entries",
"for",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L27-L32 | test |
knq/sdhook | opts.go | ProjectID | func ProjectID(projectID string) Option {
return func(sh *StackdriverHook) error {
sh.projectID = projectID
return nil
}
} | go | func ProjectID(projectID string) Option {
return func(sh *StackdriverHook) error {
sh.projectID = projectID
return nil
}
} | [
"func",
"ProjectID",
"(",
"projectID",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"projectID",
"=",
"projectID",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ProjectID is an option that sets the project ID which is needed for the log
// name. | [
"ProjectID",
"is",
"an",
"option",
"that",
"sets",
"the",
"project",
"ID",
"which",
"is",
"needed",
"for",
"the",
"log",
"name",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L36-L41 | test |
knq/sdhook | opts.go | EntriesService | func EntriesService(service *logging.EntriesService) Option {
return func(sh *StackdriverHook) error {
sh.service = service
return nil
}
} | go | func EntriesService(service *logging.EntriesService) Option {
return func(sh *StackdriverHook) error {
sh.service = service
return nil
}
} | [
"func",
"EntriesService",
"(",
"service",
"*",
"logging",
".",
"EntriesService",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"service",
"=",
"service",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"... | // EntriesService is an option that sets the Google API entry service to use
// with Stackdriver. | [
"EntriesService",
"is",
"an",
"option",
"that",
"sets",
"the",
"Google",
"API",
"entry",
"service",
"to",
"use",
"with",
"Stackdriver",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L45-L50 | test |
knq/sdhook | opts.go | LoggingService | func LoggingService(service *logging.Service) Option {
return func(sh *StackdriverHook) error {
sh.service = service.Entries
return nil
}
} | go | func LoggingService(service *logging.Service) Option {
return func(sh *StackdriverHook) error {
sh.service = service.Entries
return nil
}
} | [
"func",
"LoggingService",
"(",
"service",
"*",
"logging",
".",
"Service",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"service",
"=",
"service",
".",
"Entries",
"\n",
"return",
"nil",
"\n",
"}",
... | // LoggingService is an option that sets the Google API logging service to use. | [
"LoggingService",
"is",
"an",
"option",
"that",
"sets",
"the",
"Google",
"API",
"logging",
"service",
"to",
"use",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L53-L58 | test |
knq/sdhook | opts.go | ErrorService | func ErrorService(errorService *errorReporting.Service) Option {
return func(sh *StackdriverHook) error {
sh.errorService = errorService
return nil
}
} | go | func ErrorService(errorService *errorReporting.Service) Option {
return func(sh *StackdriverHook) error {
sh.errorService = errorService
return nil
}
} | [
"func",
"ErrorService",
"(",
"errorService",
"*",
"errorReporting",
".",
"Service",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"errorService",
"=",
"errorService",
"\n",
"return",
"nil",
"\n",
"}",
... | // ErrorService is an option that sets the Google API error reporting service to use. | [
"ErrorService",
"is",
"an",
"option",
"that",
"sets",
"the",
"Google",
"API",
"error",
"reporting",
"service",
"to",
"use",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L61-L66 | test |
knq/sdhook | opts.go | HTTPClient | func HTTPClient(client *http.Client) Option {
return func(sh *StackdriverHook) error {
// create logging service
l, err := logging.New(client)
if err != nil {
return err
}
// create error reporting service
e, err := errorReporting.New(client)
if err != nil {
return err
} else {
ErrorService(e)... | go | func HTTPClient(client *http.Client) Option {
return func(sh *StackdriverHook) error {
// create logging service
l, err := logging.New(client)
if err != nil {
return err
}
// create error reporting service
e, err := errorReporting.New(client)
if err != nil {
return err
} else {
ErrorService(e)... | [
"func",
"HTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"l",
",",
"err",
":=",
"logging",
".",
"New",
"(",
"client",
")",
"\n",
"if",
"err",
"!=",
... | // HTTPClient is an option that sets the http.Client to be used when creating
// the Stackdriver service. | [
"HTTPClient",
"is",
"an",
"option",
"that",
"sets",
"the",
"http",
".",
"Client",
"to",
"be",
"used",
"when",
"creating",
"the",
"Stackdriver",
"service",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L70-L87 | test |
knq/sdhook | opts.go | MonitoredResource | func MonitoredResource(resource *logging.MonitoredResource) Option {
return func(sh *StackdriverHook) error {
sh.resource = resource
return nil
}
} | go | func MonitoredResource(resource *logging.MonitoredResource) Option {
return func(sh *StackdriverHook) error {
sh.resource = resource
return nil
}
} | [
"func",
"MonitoredResource",
"(",
"resource",
"*",
"logging",
".",
"MonitoredResource",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"resource",
"=",
"resource",
"\n",
"return",
"nil",
"\n",
"}",
"\... | // MonitoredResource is an option that sets the monitored resource to send with
// each log entry. | [
"MonitoredResource",
"is",
"an",
"option",
"that",
"sets",
"the",
"monitored",
"resource",
"to",
"send",
"with",
"each",
"log",
"entry",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L91-L96 | test |
knq/sdhook | opts.go | ErrorReportingLogName | func ErrorReportingLogName(name string) Option {
return func(sh *StackdriverHook) error {
sh.errorReportingLogName = name
return nil
}
} | go | func ErrorReportingLogName(name string) Option {
return func(sh *StackdriverHook) error {
sh.errorReportingLogName = name
return nil
}
} | [
"func",
"ErrorReportingLogName",
"(",
"name",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"errorReportingLogName",
"=",
"name",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ErrorReportingLogName is an option that sets the log name to send
// with each error message for error reporting.
// Only used when ErrorReportingService has been set. | [
"ErrorReportingLogName",
"is",
"an",
"option",
"that",
"sets",
"the",
"log",
"name",
"to",
"send",
"with",
"each",
"error",
"message",
"for",
"error",
"reporting",
".",
"Only",
"used",
"when",
"ErrorReportingService",
"has",
"been",
"set",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L130-L135 | test |
knq/sdhook | opts.go | Labels | func Labels(labels map[string]string) Option {
return func(sh *StackdriverHook) error {
sh.labels = labels
return nil
}
} | go | func Labels(labels map[string]string) Option {
return func(sh *StackdriverHook) error {
sh.labels = labels
return nil
}
} | [
"func",
"Labels",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"labels",
"=",
"labels",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Labels is an option that sets the labels to send with each log entry. | [
"Labels",
"is",
"an",
"option",
"that",
"sets",
"the",
"labels",
"to",
"send",
"with",
"each",
"log",
"entry",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L138-L143 | test |
knq/sdhook | opts.go | PartialSuccess | func PartialSuccess(enabled bool) Option {
return func(sh *StackdriverHook) error {
sh.partialSuccess = enabled
return nil
}
} | go | func PartialSuccess(enabled bool) Option {
return func(sh *StackdriverHook) error {
sh.partialSuccess = enabled
return nil
}
} | [
"func",
"PartialSuccess",
"(",
"enabled",
"bool",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"sh",
".",
"partialSuccess",
"=",
"enabled",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // PartialSuccess is an option that toggles whether or not to write partial log
// entries. | [
"PartialSuccess",
"is",
"an",
"option",
"that",
"toggles",
"whether",
"or",
"not",
"to",
"write",
"partial",
"log",
"entries",
"."
] | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L147-L152 | test |
knq/sdhook | opts.go | GoogleComputeCredentials | func GoogleComputeCredentials(serviceAccount string) Option {
return func(sh *StackdriverHook) error {
var err error
// get compute metadata scopes associated with the service account
scopes, err := metadata.Scopes(serviceAccount)
if err != nil {
return err
}
// check if all the necessary scopes are p... | go | func GoogleComputeCredentials(serviceAccount string) Option {
return func(sh *StackdriverHook) error {
var err error
// get compute metadata scopes associated with the service account
scopes, err := metadata.Scopes(serviceAccount)
if err != nil {
return err
}
// check if all the necessary scopes are p... | [
"func",
"GoogleComputeCredentials",
"(",
"serviceAccount",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"sh",
"*",
"StackdriverHook",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"scopes",
",",
"err",
":=",
"metadata",
".",
"Scopes",
"(",
"service... | // GoogleComputeCredentials is an option that loads the Google Service Account
// credentials from the GCE metadata associated with the GCE compute instance.
// If serviceAccount is empty, then the default service account credentials
// associated with the GCE instance will be used. | [
"GoogleComputeCredentials",
"is",
"an",
"option",
"that",
"loads",
"the",
"Google",
"Service",
"Account",
"credentials",
"from",
"the",
"GCE",
"metadata",
"associated",
"with",
"the",
"GCE",
"compute",
"instance",
".",
"If",
"serviceAccount",
"is",
"empty",
"then"... | 41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b | https://github.com/knq/sdhook/blob/41b9ccbff0b5fa5a56fbdccf2eb8653e7afe8d4b/opts.go#L241-L269 | test |
segmentio/objconv | codec.go | NewEncoder | func (c Codec) NewEncoder(w io.Writer) *Encoder {
return NewEncoder(c.NewEmitter(w))
} | go | func (c Codec) NewEncoder(w io.Writer) *Encoder {
return NewEncoder(c.NewEmitter(w))
} | [
"func",
"(",
"c",
"Codec",
")",
"NewEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Encoder",
"{",
"return",
"NewEncoder",
"(",
"c",
".",
"NewEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewEncoder returns a new encoder that outputs to w. | [
"NewEncoder",
"returns",
"a",
"new",
"encoder",
"that",
"outputs",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L15-L17 | test |
segmentio/objconv | codec.go | NewDecoder | func (c Codec) NewDecoder(r io.Reader) *Decoder {
return NewDecoder(c.NewParser(r))
} | go | func (c Codec) NewDecoder(r io.Reader) *Decoder {
return NewDecoder(c.NewParser(r))
} | [
"func",
"(",
"c",
"Codec",
")",
"NewDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Decoder",
"{",
"return",
"NewDecoder",
"(",
"c",
".",
"NewParser",
"(",
"r",
")",
")",
"\n",
"}"
] | // NewDecoder returns a new decoder that takes input from r. | [
"NewDecoder",
"returns",
"a",
"new",
"decoder",
"that",
"takes",
"input",
"from",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L20-L22 | test |
segmentio/objconv | codec.go | NewStreamEncoder | func (c Codec) NewStreamEncoder(w io.Writer) *StreamEncoder {
return NewStreamEncoder(c.NewEmitter(w))
} | go | func (c Codec) NewStreamEncoder(w io.Writer) *StreamEncoder {
return NewStreamEncoder(c.NewEmitter(w))
} | [
"func",
"(",
"c",
"Codec",
")",
"NewStreamEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"StreamEncoder",
"{",
"return",
"NewStreamEncoder",
"(",
"c",
".",
"NewEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewStreamEncoder returns a new stream encoder that outputs to w. | [
"NewStreamEncoder",
"returns",
"a",
"new",
"stream",
"encoder",
"that",
"outputs",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L25-L27 | test |
segmentio/objconv | codec.go | NewStreamDecoder | func (c Codec) NewStreamDecoder(r io.Reader) *StreamDecoder {
return NewStreamDecoder(c.NewParser(r))
} | go | func (c Codec) NewStreamDecoder(r io.Reader) *StreamDecoder {
return NewStreamDecoder(c.NewParser(r))
} | [
"func",
"(",
"c",
"Codec",
")",
"NewStreamDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"StreamDecoder",
"{",
"return",
"NewStreamDecoder",
"(",
"c",
".",
"NewParser",
"(",
"r",
")",
")",
"\n",
"}"
] | // NewStreamDecoder returns a new stream decoder that takes input from r. | [
"NewStreamDecoder",
"returns",
"a",
"new",
"stream",
"decoder",
"that",
"takes",
"input",
"from",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L30-L32 | test |
segmentio/objconv | codec.go | Register | func (reg *Registry) Register(mimetype string, codec Codec) {
defer reg.mutex.Unlock()
reg.mutex.Lock()
if reg.codecs == nil {
reg.codecs = make(map[string]Codec)
}
reg.codecs[mimetype] = codec
} | go | func (reg *Registry) Register(mimetype string, codec Codec) {
defer reg.mutex.Unlock()
reg.mutex.Lock()
if reg.codecs == nil {
reg.codecs = make(map[string]Codec)
}
reg.codecs[mimetype] = codec
} | [
"func",
"(",
"reg",
"*",
"Registry",
")",
"Register",
"(",
"mimetype",
"string",
",",
"codec",
"Codec",
")",
"{",
"defer",
"reg",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"reg",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"reg",
".",
"co... | // Register adds a codec for a mimetype to r. | [
"Register",
"adds",
"a",
"codec",
"for",
"a",
"mimetype",
"to",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L43-L52 | test |
segmentio/objconv | codec.go | Unregister | func (reg *Registry) Unregister(mimetype string) {
defer reg.mutex.Unlock()
reg.mutex.Lock()
delete(reg.codecs, mimetype)
} | go | func (reg *Registry) Unregister(mimetype string) {
defer reg.mutex.Unlock()
reg.mutex.Lock()
delete(reg.codecs, mimetype)
} | [
"func",
"(",
"reg",
"*",
"Registry",
")",
"Unregister",
"(",
"mimetype",
"string",
")",
"{",
"defer",
"reg",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"reg",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"reg",
".",
"codecs",
",",
... | // Unregister removes the codec for a mimetype from r. | [
"Unregister",
"removes",
"the",
"codec",
"for",
"a",
"mimetype",
"from",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L55-L60 | test |
segmentio/objconv | codec.go | Lookup | func (reg *Registry) Lookup(mimetype string) (codec Codec, ok bool) {
reg.mutex.RLock()
codec, ok = reg.codecs[mimetype]
reg.mutex.RUnlock()
return
} | go | func (reg *Registry) Lookup(mimetype string) (codec Codec, ok bool) {
reg.mutex.RLock()
codec, ok = reg.codecs[mimetype]
reg.mutex.RUnlock()
return
} | [
"func",
"(",
"reg",
"*",
"Registry",
")",
"Lookup",
"(",
"mimetype",
"string",
")",
"(",
"codec",
"Codec",
",",
"ok",
"bool",
")",
"{",
"reg",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"codec",
",",
"ok",
"=",
"reg",
".",
"codecs",
"[",
"mimety... | // Lookup returns the codec associated with mimetype, ok is set to true or false
// based on whether a codec was found. | [
"Lookup",
"returns",
"the",
"codec",
"associated",
"with",
"mimetype",
"ok",
"is",
"set",
"to",
"true",
"or",
"false",
"based",
"on",
"whether",
"a",
"codec",
"was",
"found",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L64-L69 | test |
segmentio/objconv | codec.go | Codecs | func (reg *Registry) Codecs() (codecs map[string]Codec) {
codecs = make(map[string]Codec)
reg.mutex.RLock()
for mimetype, codec := range reg.codecs {
codecs[mimetype] = codec
}
reg.mutex.RUnlock()
return
} | go | func (reg *Registry) Codecs() (codecs map[string]Codec) {
codecs = make(map[string]Codec)
reg.mutex.RLock()
for mimetype, codec := range reg.codecs {
codecs[mimetype] = codec
}
reg.mutex.RUnlock()
return
} | [
"func",
"(",
"reg",
"*",
"Registry",
")",
"Codecs",
"(",
")",
"(",
"codecs",
"map",
"[",
"string",
"]",
"Codec",
")",
"{",
"codecs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Codec",
")",
"\n",
"reg",
".",
"mutex",
".",
"RLock",
"(",
")",
"... | // Codecs returns a map of all codecs registered in reg. | [
"Codecs",
"returns",
"a",
"map",
"of",
"all",
"codecs",
"registered",
"in",
"reg",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/codec.go#L72-L80 | test |
segmentio/objconv | resp/error.go | Type | func (e *Error) Type() string {
s := e.Error()
if i := strings.IndexByte(s, ' '); i < 0 {
s = ""
} else {
s = s[:i]
for _, c := range s {
if !unicode.IsUpper(c) {
s = ""
break
}
}
}
return s
} | go | func (e *Error) Type() string {
s := e.Error()
if i := strings.IndexByte(s, ' '); i < 0 {
s = ""
} else {
s = s[:i]
for _, c := range s {
if !unicode.IsUpper(c) {
s = ""
break
}
}
}
return s
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Type",
"(",
")",
"string",
"{",
"s",
":=",
"e",
".",
"Error",
"(",
")",
"\n",
"if",
"i",
":=",
"strings",
".",
"IndexByte",
"(",
"s",
",",
"' '",
")",
";",
"i",
"<",
"0",
"{",
"s",
"=",
"\"\"",
"\n",
... | // Type returns the RESP error type, which is represented by the leading
// uppercase word in the error string. | [
"Type",
"returns",
"the",
"RESP",
"error",
"type",
"which",
"is",
"represented",
"by",
"the",
"leading",
"uppercase",
"word",
"in",
"the",
"error",
"string",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/resp/error.go#L24-L41 | test |
segmentio/objconv | adapter.go | Install | func Install(typ reflect.Type, adapter Adapter) {
if adapter.Encode == nil {
panic("objconv: the encoder function of an adapter cannot be nil")
}
if adapter.Decode == nil {
panic("objconv: the decoder function of an adapter cannot be nil")
}
adapterMutex.Lock()
adapterStore[typ] = adapter
adapterMutex.Unlo... | go | func Install(typ reflect.Type, adapter Adapter) {
if adapter.Encode == nil {
panic("objconv: the encoder function of an adapter cannot be nil")
}
if adapter.Decode == nil {
panic("objconv: the decoder function of an adapter cannot be nil")
}
adapterMutex.Lock()
adapterStore[typ] = adapter
adapterMutex.Unlo... | [
"func",
"Install",
"(",
"typ",
"reflect",
".",
"Type",
",",
"adapter",
"Adapter",
")",
"{",
"if",
"adapter",
".",
"Encode",
"==",
"nil",
"{",
"panic",
"(",
"\"objconv: the encoder function of an adapter cannot be nil\"",
")",
"\n",
"}",
"\n",
"if",
"adapter",
... | // Install adds an adapter for typ.
//
// The function panics if one of the encoder and decoder functions of the
// adapter are nil.
//
// A typical use case for this function is to be called during the package
// initialization phase to extend objconv support for new types. | [
"Install",
"adds",
"an",
"adapter",
"for",
"typ",
".",
"The",
"function",
"panics",
"if",
"one",
"of",
"the",
"encoder",
"and",
"decoder",
"functions",
"of",
"the",
"adapter",
"are",
"nil",
".",
"A",
"typical",
"use",
"case",
"for",
"this",
"function",
"... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/adapter.go#L22-L41 | test |
segmentio/objconv | adapter.go | AdapterOf | func AdapterOf(typ reflect.Type) (a Adapter, ok bool) {
adapterMutex.RLock()
a, ok = adapterStore[typ]
adapterMutex.RUnlock()
return
} | go | func AdapterOf(typ reflect.Type) (a Adapter, ok bool) {
adapterMutex.RLock()
a, ok = adapterStore[typ]
adapterMutex.RUnlock()
return
} | [
"func",
"AdapterOf",
"(",
"typ",
"reflect",
".",
"Type",
")",
"(",
"a",
"Adapter",
",",
"ok",
"bool",
")",
"{",
"adapterMutex",
".",
"RLock",
"(",
")",
"\n",
"a",
",",
"ok",
"=",
"adapterStore",
"[",
"typ",
"]",
"\n",
"adapterMutex",
".",
"RUnlock",
... | // AdapterOf returns the adapter for typ, setting ok to true if one was found,
// false otherwise. | [
"AdapterOf",
"returns",
"the",
"adapter",
"for",
"typ",
"setting",
"ok",
"to",
"true",
"if",
"one",
"was",
"found",
"false",
"otherwise",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/adapter.go#L45-L50 | test |
segmentio/objconv | objutil/duration.go | AppendDuration | func AppendDuration(b []byte, d time.Duration) []byte {
// Largest time is 2540400h10m10.000000000s
var buf [32]byte
w := len(buf)
u := uint64(d)
neg := d < 0
if neg {
u = -u
}
if u < uint64(time.Second) {
// Special case: if duration is smaller than a second,
// use smaller units, like 1.2ms
var prec... | go | func AppendDuration(b []byte, d time.Duration) []byte {
// Largest time is 2540400h10m10.000000000s
var buf [32]byte
w := len(buf)
u := uint64(d)
neg := d < 0
if neg {
u = -u
}
if u < uint64(time.Second) {
// Special case: if duration is smaller than a second,
// use smaller units, like 1.2ms
var prec... | [
"func",
"AppendDuration",
"(",
"b",
"[",
"]",
"byte",
",",
"d",
"time",
".",
"Duration",
")",
"[",
"]",
"byte",
"{",
"var",
"buf",
"[",
"32",
"]",
"byte",
"\n",
"w",
":=",
"len",
"(",
"buf",
")",
"\n",
"u",
":=",
"uint64",
"(",
"d",
")",
"\n"... | // AppendDuration appends a human-readable representation of d to b.
//
// The function copies the implementation of time.Duration.String but prevents
// Go from making a dynamic memory allocation on the returned value. | [
"AppendDuration",
"appends",
"a",
"human",
"-",
"readable",
"representation",
"of",
"d",
"to",
"b",
".",
"The",
"function",
"copies",
"the",
"implementation",
"of",
"time",
".",
"Duration",
".",
"String",
"but",
"prevents",
"Go",
"from",
"making",
"a",
"dyna... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/objutil/duration.go#L13-L84 | test |
segmentio/objconv | objutil/duration.go | fmtInt | func fmtInt(buf []byte, v uint64) int {
w := len(buf)
if v == 0 {
w--
buf[w] = '0'
} else {
for v > 0 {
w--
buf[w] = byte(v%10) + '0'
v /= 10
}
}
return w
} | go | func fmtInt(buf []byte, v uint64) int {
w := len(buf)
if v == 0 {
w--
buf[w] = '0'
} else {
for v > 0 {
w--
buf[w] = byte(v%10) + '0'
v /= 10
}
}
return w
} | [
"func",
"fmtInt",
"(",
"buf",
"[",
"]",
"byte",
",",
"v",
"uint64",
")",
"int",
"{",
"w",
":=",
"len",
"(",
"buf",
")",
"\n",
"if",
"v",
"==",
"0",
"{",
"w",
"--",
"\n",
"buf",
"[",
"w",
"]",
"=",
"'0'",
"\n",
"}",
"else",
"{",
"for",
"v"... | // fmtInt formats v into the tail of buf.
// It returns the index where the output begins. | [
"fmtInt",
"formats",
"v",
"into",
"the",
"tail",
"of",
"buf",
".",
"It",
"returns",
"the",
"index",
"where",
"the",
"output",
"begins",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/objutil/duration.go#L112-L125 | test |
segmentio/objconv | json/decode.go | NewDecoder | func NewDecoder(r io.Reader) *objconv.Decoder {
return objconv.NewDecoder(NewParser(r))
} | go | func NewDecoder(r io.Reader) *objconv.Decoder {
return objconv.NewDecoder(NewParser(r))
} | [
"func",
"NewDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"objconv",
".",
"Decoder",
"{",
"return",
"objconv",
".",
"NewDecoder",
"(",
"NewParser",
"(",
"r",
")",
")",
"\n",
"}"
] | // NewDecoder returns a new JSON decoder that parses values from r. | [
"NewDecoder",
"returns",
"a",
"new",
"JSON",
"decoder",
"that",
"parses",
"values",
"from",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/decode.go#L12-L14 | test |
segmentio/objconv | json/decode.go | NewStreamDecoder | func NewStreamDecoder(r io.Reader) *objconv.StreamDecoder {
return objconv.NewStreamDecoder(NewParser(r))
} | go | func NewStreamDecoder(r io.Reader) *objconv.StreamDecoder {
return objconv.NewStreamDecoder(NewParser(r))
} | [
"func",
"NewStreamDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"objconv",
".",
"StreamDecoder",
"{",
"return",
"objconv",
".",
"NewStreamDecoder",
"(",
"NewParser",
"(",
"r",
")",
")",
"\n",
"}"
] | // NewStreamDecoder returns a new JSON stream decoder that parses values from r. | [
"NewStreamDecoder",
"returns",
"a",
"new",
"JSON",
"stream",
"decoder",
"that",
"parses",
"values",
"from",
"r",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/decode.go#L17-L19 | test |
segmentio/objconv | json/decode.go | Unmarshal | func Unmarshal(b []byte, v interface{}) error {
u := unmarshalerPool.Get().(*unmarshaler)
u.reset(b)
err := (objconv.Decoder{Parser: u}).Decode(v)
u.reset(nil)
unmarshalerPool.Put(u)
return err
} | go | func Unmarshal(b []byte, v interface{}) error {
u := unmarshalerPool.Get().(*unmarshaler)
u.reset(b)
err := (objconv.Decoder{Parser: u}).Decode(v)
u.reset(nil)
unmarshalerPool.Put(u)
return err
} | [
"func",
"Unmarshal",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"u",
":=",
"unmarshalerPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"unmarshaler",
")",
"\n",
"u",
".",
"reset",
"(",
"b",
")",
"\n",
"err",
":=... | // Unmarshal decodes a JSON representation of v from b. | [
"Unmarshal",
"decodes",
"a",
"JSON",
"representation",
"of",
"v",
"from",
"b",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/decode.go#L22-L31 | test |
segmentio/objconv | value.go | String | func (t Type) String() string {
switch t {
case Nil:
return "nil"
case Bool:
return "bool"
case Int:
return "int"
case Uint:
return "uint"
case Float:
return "float"
case String:
return "string"
case Bytes:
return "bytes"
case Time:
return "time"
case Duration:
return "duration"
case Error:... | go | func (t Type) String() string {
switch t {
case Nil:
return "nil"
case Bool:
return "bool"
case Int:
return "int"
case Uint:
return "uint"
case Float:
return "float"
case String:
return "string"
case Bytes:
return "bytes"
case Time:
return "time"
case Duration:
return "duration"
case Error:... | [
"func",
"(",
"t",
"Type",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Nil",
":",
"return",
"\"nil\"",
"\n",
"case",
"Bool",
":",
"return",
"\"bool\"",
"\n",
"case",
"Int",
":",
"return",
"\"int\"",
"\n",
"case",
"Uint",
":",
... | // String returns a human readable representation of the type. | [
"String",
"returns",
"a",
"human",
"readable",
"representation",
"of",
"the",
"type",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/value.go#L33-L62 | test |
segmentio/objconv | value.go | zeroValueOf | func zeroValueOf(t reflect.Type) reflect.Value {
zeroMutex.RLock()
v, ok := zeroCache[t]
zeroMutex.RUnlock()
if !ok {
v = reflect.Zero(t)
zeroMutex.Lock()
zeroCache[t] = v
zeroMutex.Unlock()
}
return v
} | go | func zeroValueOf(t reflect.Type) reflect.Value {
zeroMutex.RLock()
v, ok := zeroCache[t]
zeroMutex.RUnlock()
if !ok {
v = reflect.Zero(t)
zeroMutex.Lock()
zeroCache[t] = v
zeroMutex.Unlock()
}
return v
} | [
"func",
"zeroValueOf",
"(",
"t",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Value",
"{",
"zeroMutex",
".",
"RLock",
"(",
")",
"\n",
"v",
",",
"ok",
":=",
"zeroCache",
"[",
"t",
"]",
"\n",
"zeroMutex",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
... | // zeroValueOf and the related cache is used to keep the zero values so they
// don't need to be reallocated every time they're used. | [
"zeroValueOf",
"and",
"the",
"related",
"cache",
"is",
"used",
"to",
"keep",
"the",
"zero",
"values",
"so",
"they",
"don",
"t",
"need",
"to",
"be",
"reallocated",
"every",
"time",
"they",
"re",
"used",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/value.go#L71-L84 | test |
segmentio/objconv | value.go | NewValueParser | func NewValueParser(v interface{}) *ValueParser {
return &ValueParser{
stack: []reflect.Value{reflect.ValueOf(v)},
}
} | go | func NewValueParser(v interface{}) *ValueParser {
return &ValueParser{
stack: []reflect.Value{reflect.ValueOf(v)},
}
} | [
"func",
"NewValueParser",
"(",
"v",
"interface",
"{",
"}",
")",
"*",
"ValueParser",
"{",
"return",
"&",
"ValueParser",
"{",
"stack",
":",
"[",
"]",
"reflect",
".",
"Value",
"{",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"}",
",",
"}",
"\n",
"}"
] | // NewValueParser creates a new parser that exposes the value v. | [
"NewValueParser",
"creates",
"a",
"new",
"parser",
"that",
"exposes",
"the",
"value",
"v",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/value.go#L156-L160 | test |
segmentio/objconv | objutil/tag.go | ParseTag | func ParseTag(s string) Tag {
var name string
var omitzero bool
var omitempty bool
name, s = parseNextTagToken(s)
for len(s) != 0 {
var token string
switch token, s = parseNextTagToken(s); token {
case "omitempty":
omitempty = true
case "omitzero":
omitzero = true
}
}
return Tag{
Name: ... | go | func ParseTag(s string) Tag {
var name string
var omitzero bool
var omitempty bool
name, s = parseNextTagToken(s)
for len(s) != 0 {
var token string
switch token, s = parseNextTagToken(s); token {
case "omitempty":
omitempty = true
case "omitzero":
omitzero = true
}
}
return Tag{
Name: ... | [
"func",
"ParseTag",
"(",
"s",
"string",
")",
"Tag",
"{",
"var",
"name",
"string",
"\n",
"var",
"omitzero",
"bool",
"\n",
"var",
"omitempty",
"bool",
"\n",
"name",
",",
"s",
"=",
"parseNextTagToken",
"(",
"s",
")",
"\n",
"for",
"len",
"(",
"s",
")",
... | // ParseTag parses a raw tag obtained from a struct field, returning the results
// as a tag value. | [
"ParseTag",
"parses",
"a",
"raw",
"tag",
"obtained",
"from",
"a",
"struct",
"field",
"returning",
"the",
"results",
"as",
"a",
"tag",
"value",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/objutil/tag.go#L19-L41 | test |
segmentio/objconv | json/encode.go | NewEncoder | func NewEncoder(w io.Writer) *objconv.Encoder {
return objconv.NewEncoder(NewEmitter(w))
} | go | func NewEncoder(w io.Writer) *objconv.Encoder {
return objconv.NewEncoder(NewEmitter(w))
} | [
"func",
"NewEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"objconv",
".",
"Encoder",
"{",
"return",
"objconv",
".",
"NewEncoder",
"(",
"NewEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewEncoder returns a new JSON encoder that writes to w. | [
"NewEncoder",
"returns",
"a",
"new",
"JSON",
"encoder",
"that",
"writes",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/encode.go#L12-L14 | test |
segmentio/objconv | json/encode.go | NewStreamEncoder | func NewStreamEncoder(w io.Writer) *objconv.StreamEncoder {
return objconv.NewStreamEncoder(NewEmitter(w))
} | go | func NewStreamEncoder(w io.Writer) *objconv.StreamEncoder {
return objconv.NewStreamEncoder(NewEmitter(w))
} | [
"func",
"NewStreamEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"objconv",
".",
"StreamEncoder",
"{",
"return",
"objconv",
".",
"NewStreamEncoder",
"(",
"NewEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewStreamEncoder returns a new JSON stream encoder that writes to w. | [
"NewStreamEncoder",
"returns",
"a",
"new",
"JSON",
"stream",
"encoder",
"that",
"writes",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/encode.go#L17-L19 | test |
segmentio/objconv | json/encode.go | NewPrettyEncoder | func NewPrettyEncoder(w io.Writer) *objconv.Encoder {
return objconv.NewEncoder(NewPrettyEmitter(w))
} | go | func NewPrettyEncoder(w io.Writer) *objconv.Encoder {
return objconv.NewEncoder(NewPrettyEmitter(w))
} | [
"func",
"NewPrettyEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"objconv",
".",
"Encoder",
"{",
"return",
"objconv",
".",
"NewEncoder",
"(",
"NewPrettyEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewPrettyEncoder returns a new JSON encoder that writes to w. | [
"NewPrettyEncoder",
"returns",
"a",
"new",
"JSON",
"encoder",
"that",
"writes",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/encode.go#L22-L24 | test |
segmentio/objconv | json/encode.go | NewPrettyStreamEncoder | func NewPrettyStreamEncoder(w io.Writer) *objconv.StreamEncoder {
return objconv.NewStreamEncoder(NewPrettyEmitter(w))
} | go | func NewPrettyStreamEncoder(w io.Writer) *objconv.StreamEncoder {
return objconv.NewStreamEncoder(NewPrettyEmitter(w))
} | [
"func",
"NewPrettyStreamEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"objconv",
".",
"StreamEncoder",
"{",
"return",
"objconv",
".",
"NewStreamEncoder",
"(",
"NewPrettyEmitter",
"(",
"w",
")",
")",
"\n",
"}"
] | // NewPrettyStreamEncoder returns a new JSON stream encoder that writes to w. | [
"NewPrettyStreamEncoder",
"returns",
"a",
"new",
"JSON",
"stream",
"encoder",
"that",
"writes",
"to",
"w",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/encode.go#L27-L29 | test |
segmentio/objconv | json/encode.go | Marshal | func Marshal(v interface{}) (b []byte, err error) {
m := marshalerPool.Get().(*marshaler)
m.b.Truncate(0)
if err = (objconv.Encoder{Emitter: m}).Encode(v); err == nil {
b = make([]byte, m.b.Len())
copy(b, m.b.Bytes())
}
marshalerPool.Put(m)
return
} | go | func Marshal(v interface{}) (b []byte, err error) {
m := marshalerPool.Get().(*marshaler)
m.b.Truncate(0)
if err = (objconv.Encoder{Emitter: m}).Encode(v); err == nil {
b = make([]byte, m.b.Len())
copy(b, m.b.Bytes())
}
marshalerPool.Put(m)
return
} | [
"func",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"b",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"m",
":=",
"marshalerPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"marshaler",
")",
"\n",
"m",
".",
"b",
".",
"Truncate",
"(",
... | // Marshal writes the JSON representation of v to a byte slice returned in b. | [
"Marshal",
"writes",
"the",
"JSON",
"representation",
"of",
"v",
"to",
"a",
"byte",
"slice",
"returned",
"in",
"b",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/json/encode.go#L32-L43 | test |
segmentio/objconv | encode.go | NewEncoder | func NewEncoder(e Emitter) *Encoder {
if e == nil {
panic("objconv: the emitter is nil")
}
return &Encoder{Emitter: e}
} | go | func NewEncoder(e Emitter) *Encoder {
if e == nil {
panic("objconv: the emitter is nil")
}
return &Encoder{Emitter: e}
} | [
"func",
"NewEncoder",
"(",
"e",
"Emitter",
")",
"*",
"Encoder",
"{",
"if",
"e",
"==",
"nil",
"{",
"panic",
"(",
"\"objconv: the emitter is nil\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Encoder",
"{",
"Emitter",
":",
"e",
"}",
"\n",
"}"
] | // NewEncoder returns a new encoder that outputs values to e.
//
// Encoders created by this function use the default encoder configuration,
// which is equivalent to using a zero-value EncoderConfig with only the Emitter
// field set.
//
// The function panics if e is nil. | [
"NewEncoder",
"returns",
"a",
"new",
"encoder",
"that",
"outputs",
"values",
"to",
"e",
".",
"Encoders",
"created",
"by",
"this",
"function",
"use",
"the",
"default",
"encoder",
"configuration",
"which",
"is",
"equivalent",
"to",
"using",
"a",
"zero",
"-",
"... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L30-L35 | test |
segmentio/objconv | encode.go | EncodeArray | func (e Encoder) EncodeArray(n int, f func(Encoder) error) (err error) {
if e.key {
if e.key, err = false, e.Emitter.EmitMapValue(); err != nil {
return
}
}
if err = e.Emitter.EmitArrayBegin(n); err != nil {
return
}
encodeArray:
for i := 0; n < 0 || i < n; i++ {
if i != 0 {
if e.Emitter.EmitArrayN... | go | func (e Encoder) EncodeArray(n int, f func(Encoder) error) (err error) {
if e.key {
if e.key, err = false, e.Emitter.EmitMapValue(); err != nil {
return
}
}
if err = e.Emitter.EmitArrayBegin(n); err != nil {
return
}
encodeArray:
for i := 0; n < 0 || i < n; i++ {
if i != 0 {
if e.Emitter.EmitArrayN... | [
"func",
"(",
"e",
"Encoder",
")",
"EncodeArray",
"(",
"n",
"int",
",",
"f",
"func",
"(",
"Encoder",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"if",
"e",
".",
"key",
"{",
"if",
"e",
".",
"key",
",",
"err",
"=",
"false",
",",
"e",
".",
... | // EncodeArray provides the implementation of the array encoding algorithm,
// where n is the number of elements in the array, and f a function called to
// encode each element.
//
// The n argument can be set to a negative value to indicate that the program
// doesn't know how many elements it will output to the array... | [
"EncodeArray",
"provides",
"the",
"implementation",
"of",
"the",
"array",
"encoding",
"algorithm",
"where",
"n",
"is",
"the",
"number",
"of",
"elements",
"in",
"the",
"array",
"and",
"f",
"a",
"function",
"called",
"to",
"encode",
"each",
"element",
".",
"Th... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L620-L648 | test |
segmentio/objconv | encode.go | EncodeMap | func (e Encoder) EncodeMap(n int, f func(Encoder, Encoder) error) (err error) {
if e.key {
if e.key, err = false, e.Emitter.EmitMapValue(); err != nil {
return
}
}
if err = e.Emitter.EmitMapBegin(n); err != nil {
return
}
encodeMap:
for i := 0; n < 0 || i < n; i++ {
if i != 0 {
if err = e.Emitter.E... | go | func (e Encoder) EncodeMap(n int, f func(Encoder, Encoder) error) (err error) {
if e.key {
if e.key, err = false, e.Emitter.EmitMapValue(); err != nil {
return
}
}
if err = e.Emitter.EmitMapBegin(n); err != nil {
return
}
encodeMap:
for i := 0; n < 0 || i < n; i++ {
if i != 0 {
if err = e.Emitter.E... | [
"func",
"(",
"e",
"Encoder",
")",
"EncodeMap",
"(",
"n",
"int",
",",
"f",
"func",
"(",
"Encoder",
",",
"Encoder",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"if",
"e",
".",
"key",
"{",
"if",
"e",
".",
"key",
",",
"err",
"=",
"false",
"... | // EncodeMap provides the implementation of the map encoding algorithm, where n
// is the number of elements in the map, and f a function called to encode each
// element.
//
// The n argument can be set to a negative value to indicate that the program
// doesn't know how many elements it will output to the map. Be min... | [
"EncodeMap",
"provides",
"the",
"implementation",
"of",
"the",
"map",
"encoding",
"algorithm",
"where",
"n",
"is",
"the",
"number",
"of",
"elements",
"in",
"the",
"map",
"and",
"f",
"a",
"function",
"called",
"to",
"encode",
"each",
"element",
".",
"The",
... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L661-L698 | test |
segmentio/objconv | encode.go | NewStreamEncoder | func NewStreamEncoder(e Emitter) *StreamEncoder {
if e == nil {
panic("objconv.NewStreamEncoder: the emitter is nil")
}
return &StreamEncoder{Emitter: e}
} | go | func NewStreamEncoder(e Emitter) *StreamEncoder {
if e == nil {
panic("objconv.NewStreamEncoder: the emitter is nil")
}
return &StreamEncoder{Emitter: e}
} | [
"func",
"NewStreamEncoder",
"(",
"e",
"Emitter",
")",
"*",
"StreamEncoder",
"{",
"if",
"e",
"==",
"nil",
"{",
"panic",
"(",
"\"objconv.NewStreamEncoder: the emitter is nil\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"StreamEncoder",
"{",
"Emitter",
":",
"e",
"}",... | // NewStreamEncoder returns a new stream encoder that outputs to e.
//
// The function panics if e is nil. | [
"NewStreamEncoder",
"returns",
"a",
"new",
"stream",
"encoder",
"that",
"outputs",
"to",
"e",
".",
"The",
"function",
"panics",
"if",
"e",
"is",
"nil",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L718-L723 | test |
segmentio/objconv | encode.go | Open | func (e *StreamEncoder) Open(n int) error {
if err := e.err; err != nil {
return err
}
if e.closed {
return io.ErrClosedPipe
}
if !e.opened {
e.max = n
e.opened = true
if !e.oneshot {
e.err = e.Emitter.EmitArrayBegin(n)
}
}
return e.err
} | go | func (e *StreamEncoder) Open(n int) error {
if err := e.err; err != nil {
return err
}
if e.closed {
return io.ErrClosedPipe
}
if !e.opened {
e.max = n
e.opened = true
if !e.oneshot {
e.err = e.Emitter.EmitArrayBegin(n)
}
}
return e.err
} | [
"func",
"(",
"e",
"*",
"StreamEncoder",
")",
"Open",
"(",
"n",
"int",
")",
"error",
"{",
"if",
"err",
":=",
"e",
".",
"err",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"e",
".",
"closed",
"{",
"return",
"io",
".",
"... | // Open explicitly tells the encoder to start the stream, setting the number
// of values to n.
//
// Depending on the actual format that the stream is encoding to, n may or
// may not have to be accurate, some formats also support passing a negative
// value to indicate that the number of elements is unknown. | [
"Open",
"explicitly",
"tells",
"the",
"encoder",
"to",
"start",
"the",
"stream",
"setting",
"the",
"number",
"of",
"values",
"to",
"n",
".",
"Depending",
"on",
"the",
"actual",
"format",
"that",
"the",
"stream",
"is",
"encoding",
"to",
"n",
"may",
"or",
... | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L731-L750 | test |
segmentio/objconv | encode.go | Close | func (e *StreamEncoder) Close() error {
if !e.closed {
if err := e.Open(-1); err != nil {
return err
}
e.closed = true
if !e.oneshot {
e.err = e.Emitter.EmitArrayEnd()
}
}
return e.err
} | go | func (e *StreamEncoder) Close() error {
if !e.closed {
if err := e.Open(-1); err != nil {
return err
}
e.closed = true
if !e.oneshot {
e.err = e.Emitter.EmitArrayEnd()
}
}
return e.err
} | [
"func",
"(",
"e",
"*",
"StreamEncoder",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"!",
"e",
".",
"closed",
"{",
"if",
"err",
":=",
"e",
".",
"Open",
"(",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"e",
... | // Close terminates the stream encoder. | [
"Close",
"terminates",
"the",
"stream",
"encoder",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L753-L767 | test |
segmentio/objconv | encode.go | Encode | func (e *StreamEncoder) Encode(v interface{}) error {
if err := e.Open(-1); err != nil {
return err
}
if e.max >= 0 && e.cnt >= e.max {
return fmt.Errorf("objconv: too many values sent to a stream encoder exceed the configured limit of %d", e.max)
}
if !e.oneshot && e.cnt != 0 {
e.err = e.Emitter.EmitArray... | go | func (e *StreamEncoder) Encode(v interface{}) error {
if err := e.Open(-1); err != nil {
return err
}
if e.max >= 0 && e.cnt >= e.max {
return fmt.Errorf("objconv: too many values sent to a stream encoder exceed the configured limit of %d", e.max)
}
if !e.oneshot && e.cnt != 0 {
e.err = e.Emitter.EmitArray... | [
"func",
"(",
"e",
"*",
"StreamEncoder",
")",
"Encode",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"err",
":=",
"e",
".",
"Open",
"(",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"e",
"."... | // Encode writes v to the stream, encoding it based on the emitter configured
// on e. | [
"Encode",
"writes",
"v",
"to",
"the",
"stream",
"encoding",
"it",
"based",
"on",
"the",
"emitter",
"configured",
"on",
"e",
"."
] | 7a1d7b8e6f3551b30751e6b2ea6bae500883870e | https://github.com/segmentio/objconv/blob/7a1d7b8e6f3551b30751e6b2ea6bae500883870e/encode.go#L771-L796 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.