id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
17,200 |
hoisie/redis
|
redis.go
|
valueToString
|
func valueToString(v reflect.Value) (string, error) {
if !v.IsValid() {
return "null", nil
}
switch v.Kind() {
case reflect.Ptr:
return valueToString(reflect.Indirect(v))
case reflect.Interface:
return valueToString(v.Elem())
case reflect.Bool:
x := v.Bool()
if x {
return "true", nil
} else {
return "false", nil
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return strconv.FormatInt(v.Int(), 10), nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return strconv.FormatUint(v.Uint(), 10), nil
case reflect.UnsafePointer:
return strconv.FormatUint(uint64(v.Pointer()), 10), nil
case reflect.Float32, reflect.Float64:
return strconv.FormatFloat(v.Float(), 'g', -1, 64), nil
case reflect.String:
return v.String(), nil
//This is kind of a rough hack to replace the old []byte
//detection with reflect.Uint8Type, it doesn't catch
//zero-length byte slices
case reflect.Slice:
typ := v.Type()
if typ.Elem().Kind() == reflect.Uint || typ.Elem().Kind() == reflect.Uint8 || typ.Elem().Kind() == reflect.Uint16 || typ.Elem().Kind() == reflect.Uint32 || typ.Elem().Kind() == reflect.Uint64 || typ.Elem().Kind() == reflect.Uintptr {
if v.Len() > 0 {
if v.Index(0).OverflowUint(257) {
return string(v.Interface().([]byte)), nil
}
}
}
}
return "", errors.New("Unsupported type")
}
|
go
|
func valueToString(v reflect.Value) (string, error) {
if !v.IsValid() {
return "null", nil
}
switch v.Kind() {
case reflect.Ptr:
return valueToString(reflect.Indirect(v))
case reflect.Interface:
return valueToString(v.Elem())
case reflect.Bool:
x := v.Bool()
if x {
return "true", nil
} else {
return "false", nil
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return strconv.FormatInt(v.Int(), 10), nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return strconv.FormatUint(v.Uint(), 10), nil
case reflect.UnsafePointer:
return strconv.FormatUint(uint64(v.Pointer()), 10), nil
case reflect.Float32, reflect.Float64:
return strconv.FormatFloat(v.Float(), 'g', -1, 64), nil
case reflect.String:
return v.String(), nil
//This is kind of a rough hack to replace the old []byte
//detection with reflect.Uint8Type, it doesn't catch
//zero-length byte slices
case reflect.Slice:
typ := v.Type()
if typ.Elem().Kind() == reflect.Uint || typ.Elem().Kind() == reflect.Uint8 || typ.Elem().Kind() == reflect.Uint16 || typ.Elem().Kind() == reflect.Uint32 || typ.Elem().Kind() == reflect.Uint64 || typ.Elem().Kind() == reflect.Uintptr {
if v.Len() > 0 {
if v.Index(0).OverflowUint(257) {
return string(v.Interface().([]byte)), nil
}
}
}
}
return "", errors.New("Unsupported type")
}
|
[
"func",
"valueToString",
"(",
"v",
"reflect",
".",
"Value",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"v",
".",
"IsValid",
"(",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Ptr",
":",
"return",
"valueToString",
"(",
"reflect",
".",
"Indirect",
"(",
"v",
")",
")",
"\n",
"case",
"reflect",
".",
"Interface",
":",
"return",
"valueToString",
"(",
"v",
".",
"Elem",
"(",
")",
")",
"\n",
"case",
"reflect",
".",
"Bool",
":",
"x",
":=",
"v",
".",
"Bool",
"(",
")",
"\n",
"if",
"x",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"return",
"strconv",
".",
"FormatInt",
"(",
"v",
".",
"Int",
"(",
")",
",",
"10",
")",
",",
"nil",
"\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"return",
"strconv",
".",
"FormatUint",
"(",
"v",
".",
"Uint",
"(",
")",
",",
"10",
")",
",",
"nil",
"\n",
"case",
"reflect",
".",
"UnsafePointer",
":",
"return",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"v",
".",
"Pointer",
"(",
")",
")",
",",
"10",
")",
",",
"nil",
"\n\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"return",
"strconv",
".",
"FormatFloat",
"(",
"v",
".",
"Float",
"(",
")",
",",
"'g'",
",",
"-",
"1",
",",
"64",
")",
",",
"nil",
"\n\n",
"case",
"reflect",
".",
"String",
":",
"return",
"v",
".",
"String",
"(",
")",
",",
"nil",
"\n\n",
"//This is kind of a rough hack to replace the old []byte",
"//detection with reflect.Uint8Type, it doesn't catch",
"//zero-length byte slices",
"case",
"reflect",
".",
"Slice",
":",
"typ",
":=",
"v",
".",
"Type",
"(",
")",
"\n",
"if",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uint",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uint8",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uint16",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uint32",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uint64",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Uintptr",
"{",
"if",
"v",
".",
"Len",
"(",
")",
">",
"0",
"{",
"if",
"v",
".",
"Index",
"(",
"0",
")",
".",
"OverflowUint",
"(",
"257",
")",
"{",
"return",
"string",
"(",
"v",
".",
"Interface",
"(",
")",
".",
"(",
"[",
"]",
"byte",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
//pretty much copy the json code from here.
|
[
"pretty",
"much",
"copy",
"the",
"json",
"code",
"from",
"here",
"."
] |
b5c6e81454e0395c280f220d82a6854fd0fcf42e
|
https://github.com/hoisie/redis/blob/b5c6e81454e0395c280f220d82a6854fd0fcf42e/redis.go#L1068-L1113
|
17,201 |
hoisie/redis
|
redis.go
|
Publish
|
func (client *Client) Publish(channel string, val []byte) error {
_, err := client.sendCommand("PUBLISH", channel, string(val))
if err != nil {
return err
}
return nil
}
|
go
|
func (client *Client) Publish(channel string, val []byte) error {
_, err := client.sendCommand("PUBLISH", channel, string(val))
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"client",
"*",
"Client",
")",
"Publish",
"(",
"channel",
"string",
",",
"val",
"[",
"]",
"byte",
")",
"error",
"{",
"_",
",",
"err",
":=",
"client",
".",
"sendCommand",
"(",
"\"",
"\"",
",",
"channel",
",",
"string",
"(",
"val",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Publish a message to a redis server.
|
[
"Publish",
"a",
"message",
"to",
"a",
"redis",
"server",
"."
] |
b5c6e81454e0395c280f220d82a6854fd0fcf42e
|
https://github.com/hoisie/redis/blob/b5c6e81454e0395c280f220d82a6854fd0fcf42e/redis.go#L1404-L1410
|
17,202 |
Luzifer/go-openssl
|
openssl.go
|
DigestSHA256Sum
|
func DigestSHA256Sum(data []byte) []byte {
h := sha256.New()
h.Write(data)
return h.Sum(nil)
}
|
go
|
func DigestSHA256Sum(data []byte) []byte {
h := sha256.New()
h.Write(data)
return h.Sum(nil)
}
|
[
"func",
"DigestSHA256Sum",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"h",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n",
"}"
] |
// DigestSHA256Sum uses SHA256 digest to create the key which is the default behaviour since OpenSSL 1.1.0c
|
[
"DigestSHA256Sum",
"uses",
"SHA256",
"digest",
"to",
"create",
"the",
"key",
"which",
"is",
"the",
"default",
"behaviour",
"since",
"OpenSSL",
"1",
".",
"1",
".",
"0c"
] |
3eef5a5be8e50536ed727038b76dbaa9ac804279
|
https://github.com/Luzifer/go-openssl/blob/3eef5a5be8e50536ed727038b76dbaa9ac804279/openssl.go#L61-L65
|
17,203 |
Luzifer/go-openssl
|
openssl.go
|
EncryptBytes
|
func (o OpenSSL) EncryptBytes(passphrase string, plainData []byte, kdf DigestFunc) ([]byte, error) {
salt, err := o.GenerateSalt()
if err != nil {
return nil, err
}
return o.EncryptBytesWithSaltAndDigestFunc(passphrase, salt, plainData, kdf)
}
|
go
|
func (o OpenSSL) EncryptBytes(passphrase string, plainData []byte, kdf DigestFunc) ([]byte, error) {
salt, err := o.GenerateSalt()
if err != nil {
return nil, err
}
return o.EncryptBytesWithSaltAndDigestFunc(passphrase, salt, plainData, kdf)
}
|
[
"func",
"(",
"o",
"OpenSSL",
")",
"EncryptBytes",
"(",
"passphrase",
"string",
",",
"plainData",
"[",
"]",
"byte",
",",
"kdf",
"DigestFunc",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"salt",
",",
"err",
":=",
"o",
".",
"GenerateSalt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"EncryptBytesWithSaltAndDigestFunc",
"(",
"passphrase",
",",
"salt",
",",
"plainData",
",",
"kdf",
")",
"\n",
"}"
] |
// EncryptBytes encrypts a slice of bytes that are base64 encoded in a manner compatible to OpenSSL encryption
// functions using AES-256-CBC as encryption algorithm. This function generates
// a random salt on every execution.
|
[
"EncryptBytes",
"encrypts",
"a",
"slice",
"of",
"bytes",
"that",
"are",
"base64",
"encoded",
"in",
"a",
"manner",
"compatible",
"to",
"OpenSSL",
"encryption",
"functions",
"using",
"AES",
"-",
"256",
"-",
"CBC",
"as",
"encryption",
"algorithm",
".",
"This",
"function",
"generates",
"a",
"random",
"salt",
"on",
"every",
"execution",
"."
] |
3eef5a5be8e50536ed727038b76dbaa9ac804279
|
https://github.com/Luzifer/go-openssl/blob/3eef5a5be8e50536ed727038b76dbaa9ac804279/openssl.go#L133-L140
|
17,204 |
Luzifer/go-openssl
|
openssl.go
|
EncryptBinaryBytes
|
func (o OpenSSL) EncryptBinaryBytes(passphrase string, plainData []byte, kdf DigestFunc) ([]byte, error) {
salt, err := o.GenerateSalt()
if err != nil {
return nil, err
}
return o.EncryptBinaryBytesWithSaltAndDigestFunc(passphrase, salt, plainData, kdf)
}
|
go
|
func (o OpenSSL) EncryptBinaryBytes(passphrase string, plainData []byte, kdf DigestFunc) ([]byte, error) {
salt, err := o.GenerateSalt()
if err != nil {
return nil, err
}
return o.EncryptBinaryBytesWithSaltAndDigestFunc(passphrase, salt, plainData, kdf)
}
|
[
"func",
"(",
"o",
"OpenSSL",
")",
"EncryptBinaryBytes",
"(",
"passphrase",
"string",
",",
"plainData",
"[",
"]",
"byte",
",",
"kdf",
"DigestFunc",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"salt",
",",
"err",
":=",
"o",
".",
"GenerateSalt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"EncryptBinaryBytesWithSaltAndDigestFunc",
"(",
"passphrase",
",",
"salt",
",",
"plainData",
",",
"kdf",
")",
"\n",
"}"
] |
// EncryptBinaryBytes encrypts a slice of bytes in a manner compatible to OpenSSL encryption
// functions using AES-256-CBC as encryption algorithm. This function generates
// a random salt on every execution.
|
[
"EncryptBinaryBytes",
"encrypts",
"a",
"slice",
"of",
"bytes",
"in",
"a",
"manner",
"compatible",
"to",
"OpenSSL",
"encryption",
"functions",
"using",
"AES",
"-",
"256",
"-",
"CBC",
"as",
"encryption",
"algorithm",
".",
"This",
"function",
"generates",
"a",
"random",
"salt",
"on",
"every",
"execution",
"."
] |
3eef5a5be8e50536ed727038b76dbaa9ac804279
|
https://github.com/Luzifer/go-openssl/blob/3eef5a5be8e50536ed727038b76dbaa9ac804279/openssl.go#L145-L152
|
17,205 |
Luzifer/go-openssl
|
openssl.go
|
MustGenerateSalt
|
func (o OpenSSL) MustGenerateSalt() []byte {
s, err := o.GenerateSalt()
if err != nil {
panic(err)
}
return s
}
|
go
|
func (o OpenSSL) MustGenerateSalt() []byte {
s, err := o.GenerateSalt()
if err != nil {
panic(err)
}
return s
}
|
[
"func",
"(",
"o",
"OpenSSL",
")",
"MustGenerateSalt",
"(",
")",
"[",
"]",
"byte",
"{",
"s",
",",
"err",
":=",
"o",
".",
"GenerateSalt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// MustGenerateSalt is a wrapper around GenerateSalt which will panic on an error.
// This allows you to use this function as a parameter to EncryptBytesWithSaltAndDigestFunc
|
[
"MustGenerateSalt",
"is",
"a",
"wrapper",
"around",
"GenerateSalt",
"which",
"will",
"panic",
"on",
"an",
"error",
".",
"This",
"allows",
"you",
"to",
"use",
"this",
"function",
"as",
"a",
"parameter",
"to",
"EncryptBytesWithSaltAndDigestFunc"
] |
3eef5a5be8e50536ed727038b76dbaa9ac804279
|
https://github.com/Luzifer/go-openssl/blob/3eef5a5be8e50536ed727038b76dbaa9ac804279/openssl.go#L261-L267
|
17,206 |
Luzifer/go-openssl
|
openssl.go
|
pkcs7Unpad
|
func (o OpenSSL) pkcs7Unpad(data []byte, blocklen int) ([]byte, error) {
if blocklen <= 0 {
return nil, fmt.Errorf("invalid blocklen %d", blocklen)
}
if len(data)%blocklen != 0 || len(data) == 0 {
return nil, fmt.Errorf("invalid data len %d", len(data))
}
padlen := int(data[len(data)-1])
if padlen > blocklen || padlen == 0 {
return nil, fmt.Errorf("invalid padding")
}
pad := data[len(data)-padlen:]
for i := 0; i < padlen; i++ {
if pad[i] != byte(padlen) {
return nil, fmt.Errorf("invalid padding")
}
}
return data[:len(data)-padlen], nil
}
|
go
|
func (o OpenSSL) pkcs7Unpad(data []byte, blocklen int) ([]byte, error) {
if blocklen <= 0 {
return nil, fmt.Errorf("invalid blocklen %d", blocklen)
}
if len(data)%blocklen != 0 || len(data) == 0 {
return nil, fmt.Errorf("invalid data len %d", len(data))
}
padlen := int(data[len(data)-1])
if padlen > blocklen || padlen == 0 {
return nil, fmt.Errorf("invalid padding")
}
pad := data[len(data)-padlen:]
for i := 0; i < padlen; i++ {
if pad[i] != byte(padlen) {
return nil, fmt.Errorf("invalid padding")
}
}
return data[:len(data)-padlen], nil
}
|
[
"func",
"(",
"o",
"OpenSSL",
")",
"pkcs7Unpad",
"(",
"data",
"[",
"]",
"byte",
",",
"blocklen",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"blocklen",
"<=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"blocklen",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"data",
")",
"%",
"blocklen",
"!=",
"0",
"||",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"data",
")",
")",
"\n",
"}",
"\n",
"padlen",
":=",
"int",
"(",
"data",
"[",
"len",
"(",
"data",
")",
"-",
"1",
"]",
")",
"\n",
"if",
"padlen",
">",
"blocklen",
"||",
"padlen",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pad",
":=",
"data",
"[",
"len",
"(",
"data",
")",
"-",
"padlen",
":",
"]",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"padlen",
";",
"i",
"++",
"{",
"if",
"pad",
"[",
"i",
"]",
"!=",
"byte",
"(",
"padlen",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"data",
"[",
":",
"len",
"(",
"data",
")",
"-",
"padlen",
"]",
",",
"nil",
"\n",
"}"
] |
// pkcs7Unpad returns slice of the original data without padding.
|
[
"pkcs7Unpad",
"returns",
"slice",
"of",
"the",
"original",
"data",
"without",
"padding",
"."
] |
3eef5a5be8e50536ed727038b76dbaa9ac804279
|
https://github.com/Luzifer/go-openssl/blob/3eef5a5be8e50536ed727038b76dbaa9ac804279/openssl.go#L284-L302
|
17,207 |
vishvananda/netns
|
netns_linux.go
|
Setns
|
func Setns(ns NsHandle, nstype int) (err error) {
_, _, e1 := syscall.Syscall(SYS_SETNS, uintptr(ns), uintptr(nstype), 0)
if e1 != 0 {
err = e1
}
return
}
|
go
|
func Setns(ns NsHandle, nstype int) (err error) {
_, _, e1 := syscall.Syscall(SYS_SETNS, uintptr(ns), uintptr(nstype), 0)
if e1 != 0 {
err = e1
}
return
}
|
[
"func",
"Setns",
"(",
"ns",
"NsHandle",
",",
"nstype",
"int",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"_",
",",
"e1",
":=",
"syscall",
".",
"Syscall",
"(",
"SYS_SETNS",
",",
"uintptr",
"(",
"ns",
")",
",",
"uintptr",
"(",
"nstype",
")",
",",
"0",
")",
"\n",
"if",
"e1",
"!=",
"0",
"{",
"err",
"=",
"e1",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Setns sets namespace using syscall. Note that this should be a method
// in syscall but it has not been added.
|
[
"Setns",
"sets",
"namespace",
"using",
"syscall",
".",
"Note",
"that",
"this",
"should",
"be",
"a",
"method",
"in",
"syscall",
"but",
"it",
"has",
"not",
"been",
"added",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns_linux.go#L41-L47
|
17,208 |
vishvananda/netns
|
netns_linux.go
|
New
|
func New() (ns NsHandle, err error) {
if err := syscall.Unshare(CLONE_NEWNET); err != nil {
return -1, err
}
return Get()
}
|
go
|
func New() (ns NsHandle, err error) {
if err := syscall.Unshare(CLONE_NEWNET); err != nil {
return -1, err
}
return Get()
}
|
[
"func",
"New",
"(",
")",
"(",
"ns",
"NsHandle",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"syscall",
".",
"Unshare",
"(",
"CLONE_NEWNET",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"Get",
"(",
")",
"\n",
"}"
] |
// New creates a new network namespace and returns a handle to it.
|
[
"New",
"creates",
"a",
"new",
"network",
"namespace",
"and",
"returns",
"a",
"handle",
"to",
"it",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns_linux.go#L56-L61
|
17,209 |
vishvananda/netns
|
netns_linux.go
|
GetFromPath
|
func GetFromPath(path string) (NsHandle, error) {
fd, err := syscall.Open(path, syscall.O_RDONLY, 0)
if err != nil {
return -1, err
}
return NsHandle(fd), nil
}
|
go
|
func GetFromPath(path string) (NsHandle, error) {
fd, err := syscall.Open(path, syscall.O_RDONLY, 0)
if err != nil {
return -1, err
}
return NsHandle(fd), nil
}
|
[
"func",
"GetFromPath",
"(",
"path",
"string",
")",
"(",
"NsHandle",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"syscall",
".",
"Open",
"(",
"path",
",",
"syscall",
".",
"O_RDONLY",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"NsHandle",
"(",
"fd",
")",
",",
"nil",
"\n",
"}"
] |
// GetFromPath gets a handle to a network namespace
// identified by the path
|
[
"GetFromPath",
"gets",
"a",
"handle",
"to",
"a",
"network",
"namespace",
"identified",
"by",
"the",
"path"
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns_linux.go#L70-L76
|
17,210 |
vishvananda/netns
|
netns_linux.go
|
GetFromThread
|
func GetFromThread(pid, tid int) (NsHandle, error) {
return GetFromPath(fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid))
}
|
go
|
func GetFromThread(pid, tid int) (NsHandle, error) {
return GetFromPath(fmt.Sprintf("/proc/%d/task/%d/ns/net", pid, tid))
}
|
[
"func",
"GetFromThread",
"(",
"pid",
",",
"tid",
"int",
")",
"(",
"NsHandle",
",",
"error",
")",
"{",
"return",
"GetFromPath",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
",",
"tid",
")",
")",
"\n",
"}"
] |
// GetFromThread gets a handle to the network namespace of a given pid and tid.
|
[
"GetFromThread",
"gets",
"a",
"handle",
"to",
"the",
"network",
"namespace",
"of",
"a",
"given",
"pid",
"and",
"tid",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns_linux.go#L90-L92
|
17,211 |
vishvananda/netns
|
netns_linux.go
|
GetFromDocker
|
func GetFromDocker(id string) (NsHandle, error) {
pid, err := getPidForContainer(id)
if err != nil {
return -1, err
}
return GetFromPid(pid)
}
|
go
|
func GetFromDocker(id string) (NsHandle, error) {
pid, err := getPidForContainer(id)
if err != nil {
return -1, err
}
return GetFromPid(pid)
}
|
[
"func",
"GetFromDocker",
"(",
"id",
"string",
")",
"(",
"NsHandle",
",",
"error",
")",
"{",
"pid",
",",
"err",
":=",
"getPidForContainer",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"GetFromPid",
"(",
"pid",
")",
"\n",
"}"
] |
// GetFromDocker gets a handle to the network namespace of a docker container.
// Id is prefixed matched against the running docker containers, so a short
// identifier can be used as long as it isn't ambiguous.
|
[
"GetFromDocker",
"gets",
"a",
"handle",
"to",
"the",
"network",
"namespace",
"of",
"a",
"docker",
"container",
".",
"Id",
"is",
"prefixed",
"matched",
"against",
"the",
"running",
"docker",
"containers",
"so",
"a",
"short",
"identifier",
"can",
"be",
"used",
"as",
"long",
"as",
"it",
"isn",
"t",
"ambiguous",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns_linux.go#L97-L103
|
17,212 |
vishvananda/netns
|
netns.go
|
Equal
|
func (ns NsHandle) Equal(other NsHandle) bool {
if ns == other {
return true
}
var s1, s2 syscall.Stat_t
if err := syscall.Fstat(int(ns), &s1); err != nil {
return false
}
if err := syscall.Fstat(int(other), &s2); err != nil {
return false
}
return (s1.Dev == s2.Dev) && (s1.Ino == s2.Ino)
}
|
go
|
func (ns NsHandle) Equal(other NsHandle) bool {
if ns == other {
return true
}
var s1, s2 syscall.Stat_t
if err := syscall.Fstat(int(ns), &s1); err != nil {
return false
}
if err := syscall.Fstat(int(other), &s2); err != nil {
return false
}
return (s1.Dev == s2.Dev) && (s1.Ino == s2.Ino)
}
|
[
"func",
"(",
"ns",
"NsHandle",
")",
"Equal",
"(",
"other",
"NsHandle",
")",
"bool",
"{",
"if",
"ns",
"==",
"other",
"{",
"return",
"true",
"\n",
"}",
"\n",
"var",
"s1",
",",
"s2",
"syscall",
".",
"Stat_t",
"\n",
"if",
"err",
":=",
"syscall",
".",
"Fstat",
"(",
"int",
"(",
"ns",
")",
",",
"&",
"s1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"err",
":=",
"syscall",
".",
"Fstat",
"(",
"int",
"(",
"other",
")",
",",
"&",
"s2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"(",
"s1",
".",
"Dev",
"==",
"s2",
".",
"Dev",
")",
"&&",
"(",
"s1",
".",
"Ino",
"==",
"s2",
".",
"Ino",
")",
"\n",
"}"
] |
// Equal determines if two network handles refer to the same network
// namespace. This is done by comparing the device and inode that the
// file descriptors point to.
|
[
"Equal",
"determines",
"if",
"two",
"network",
"handles",
"refer",
"to",
"the",
"same",
"network",
"namespace",
".",
"This",
"is",
"done",
"by",
"comparing",
"the",
"device",
"and",
"inode",
"that",
"the",
"file",
"descriptors",
"point",
"to",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns.go#L23-L35
|
17,213 |
vishvananda/netns
|
netns.go
|
String
|
func (ns NsHandle) String() string {
var s syscall.Stat_t
if ns == -1 {
return "NS(None)"
}
if err := syscall.Fstat(int(ns), &s); err != nil {
return fmt.Sprintf("NS(%d: unknown)", ns)
}
return fmt.Sprintf("NS(%d: %d, %d)", ns, s.Dev, s.Ino)
}
|
go
|
func (ns NsHandle) String() string {
var s syscall.Stat_t
if ns == -1 {
return "NS(None)"
}
if err := syscall.Fstat(int(ns), &s); err != nil {
return fmt.Sprintf("NS(%d: unknown)", ns)
}
return fmt.Sprintf("NS(%d: %d, %d)", ns, s.Dev, s.Ino)
}
|
[
"func",
"(",
"ns",
"NsHandle",
")",
"String",
"(",
")",
"string",
"{",
"var",
"s",
"syscall",
".",
"Stat_t",
"\n",
"if",
"ns",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"err",
":=",
"syscall",
".",
"Fstat",
"(",
"int",
"(",
"ns",
")",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ns",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ns",
",",
"s",
".",
"Dev",
",",
"s",
".",
"Ino",
")",
"\n",
"}"
] |
// String shows the file descriptor number and its dev and inode.
|
[
"String",
"shows",
"the",
"file",
"descriptor",
"number",
"and",
"its",
"dev",
"and",
"inode",
"."
] |
13995c7128ccc8e51e9a6bd2b551020a27180abd
|
https://github.com/vishvananda/netns/blob/13995c7128ccc8e51e9a6bd2b551020a27180abd/netns.go#L38-L47
|
17,214 |
onrik/ethrpc
|
helpers.go
|
ParseInt
|
func ParseInt(value string) (int, error) {
i, err := strconv.ParseInt(strings.TrimPrefix(value, "0x"), 16, 64)
if err != nil {
return 0, err
}
return int(i), nil
}
|
go
|
func ParseInt(value string) (int, error) {
i, err := strconv.ParseInt(strings.TrimPrefix(value, "0x"), 16, 64)
if err != nil {
return 0, err
}
return int(i), nil
}
|
[
"func",
"ParseInt",
"(",
"value",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"strings",
".",
"TrimPrefix",
"(",
"value",
",",
"\"",
"\"",
")",
",",
"16",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"i",
")",
",",
"nil",
"\n",
"}"
] |
// ParseInt parse hex string value to int
|
[
"ParseInt",
"parse",
"hex",
"string",
"value",
"to",
"int"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/helpers.go#L11-L18
|
17,215 |
onrik/ethrpc
|
helpers.go
|
ParseBigInt
|
func ParseBigInt(value string) (big.Int, error) {
i := big.Int{}
_, err := fmt.Sscan(value, &i)
return i, err
}
|
go
|
func ParseBigInt(value string) (big.Int, error) {
i := big.Int{}
_, err := fmt.Sscan(value, &i)
return i, err
}
|
[
"func",
"ParseBigInt",
"(",
"value",
"string",
")",
"(",
"big",
".",
"Int",
",",
"error",
")",
"{",
"i",
":=",
"big",
".",
"Int",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"fmt",
".",
"Sscan",
"(",
"value",
",",
"&",
"i",
")",
"\n\n",
"return",
"i",
",",
"err",
"\n",
"}"
] |
// ParseBigInt parse hex string value to big.Int
|
[
"ParseBigInt",
"parse",
"hex",
"string",
"value",
"to",
"big",
".",
"Int"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/helpers.go#L21-L26
|
17,216 |
onrik/ethrpc
|
helpers.go
|
BigToHex
|
func BigToHex(bigInt big.Int) string {
if bigInt.BitLen() == 0 {
return "0x0"
}
return "0x" + strings.TrimPrefix(fmt.Sprintf("%x", bigInt.Bytes()), "0")
}
|
go
|
func BigToHex(bigInt big.Int) string {
if bigInt.BitLen() == 0 {
return "0x0"
}
return "0x" + strings.TrimPrefix(fmt.Sprintf("%x", bigInt.Bytes()), "0")
}
|
[
"func",
"BigToHex",
"(",
"bigInt",
"big",
".",
"Int",
")",
"string",
"{",
"if",
"bigInt",
".",
"BitLen",
"(",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"+",
"strings",
".",
"TrimPrefix",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"bigInt",
".",
"Bytes",
"(",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// BigToHex covert big.Int to hexadecimal representation
|
[
"BigToHex",
"covert",
"big",
".",
"Int",
"to",
"hexadecimal",
"representation"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/helpers.go#L34-L40
|
17,217 |
onrik/ethrpc
|
types.go
|
MarshalJSON
|
func (t T) MarshalJSON() ([]byte, error) {
params := map[string]interface{}{
"from": t.From,
}
if t.To != "" {
params["to"] = t.To
}
if t.Gas > 0 {
params["gas"] = IntToHex(t.Gas)
}
if t.GasPrice != nil {
params["gasPrice"] = BigToHex(*t.GasPrice)
}
if t.Value != nil {
params["value"] = BigToHex(*t.Value)
}
if t.Data != "" {
params["data"] = t.Data
}
if t.Nonce > 0 {
params["nonce"] = IntToHex(t.Nonce)
}
return json.Marshal(params)
}
|
go
|
func (t T) MarshalJSON() ([]byte, error) {
params := map[string]interface{}{
"from": t.From,
}
if t.To != "" {
params["to"] = t.To
}
if t.Gas > 0 {
params["gas"] = IntToHex(t.Gas)
}
if t.GasPrice != nil {
params["gasPrice"] = BigToHex(*t.GasPrice)
}
if t.Value != nil {
params["value"] = BigToHex(*t.Value)
}
if t.Data != "" {
params["data"] = t.Data
}
if t.Nonce > 0 {
params["nonce"] = IntToHex(t.Nonce)
}
return json.Marshal(params)
}
|
[
"func",
"(",
"t",
"T",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"params",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"t",
".",
"From",
",",
"}",
"\n",
"if",
"t",
".",
"To",
"!=",
"\"",
"\"",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"t",
".",
"To",
"\n",
"}",
"\n",
"if",
"t",
".",
"Gas",
">",
"0",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"IntToHex",
"(",
"t",
".",
"Gas",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"GasPrice",
"!=",
"nil",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"BigToHex",
"(",
"*",
"t",
".",
"GasPrice",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"Value",
"!=",
"nil",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"BigToHex",
"(",
"*",
"t",
".",
"Value",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"Data",
"!=",
"\"",
"\"",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"t",
".",
"Data",
"\n",
"}",
"\n",
"if",
"t",
".",
"Nonce",
">",
"0",
"{",
"params",
"[",
"\"",
"\"",
"]",
"=",
"IntToHex",
"(",
"t",
".",
"Nonce",
")",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"params",
")",
"\n",
"}"
] |
// MarshalJSON implements the json.Unmarshaler interface.
|
[
"MarshalJSON",
"implements",
"the",
"json",
".",
"Unmarshaler",
"interface",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/types.go#L43-L67
|
17,218 |
onrik/ethrpc
|
ethrpc.go
|
New
|
func New(url string, options ...func(rpc *EthRPC)) *EthRPC {
rpc := &EthRPC{
url: url,
client: http.DefaultClient,
log: log.New(os.Stderr, "", log.LstdFlags),
}
for _, option := range options {
option(rpc)
}
return rpc
}
|
go
|
func New(url string, options ...func(rpc *EthRPC)) *EthRPC {
rpc := &EthRPC{
url: url,
client: http.DefaultClient,
log: log.New(os.Stderr, "", log.LstdFlags),
}
for _, option := range options {
option(rpc)
}
return rpc
}
|
[
"func",
"New",
"(",
"url",
"string",
",",
"options",
"...",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
")",
"*",
"EthRPC",
"{",
"rpc",
":=",
"&",
"EthRPC",
"{",
"url",
":",
"url",
",",
"client",
":",
"http",
".",
"DefaultClient",
",",
"log",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
",",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
"(",
"rpc",
")",
"\n",
"}",
"\n\n",
"return",
"rpc",
"\n",
"}"
] |
// New create new rpc client with given url
|
[
"New",
"create",
"new",
"rpc",
"client",
"with",
"given",
"url"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L47-L58
|
17,219 |
onrik/ethrpc
|
ethrpc.go
|
NewEthRPC
|
func NewEthRPC(url string, options ...func(rpc *EthRPC)) *EthRPC {
return New(url, options...)
}
|
go
|
func NewEthRPC(url string, options ...func(rpc *EthRPC)) *EthRPC {
return New(url, options...)
}
|
[
"func",
"NewEthRPC",
"(",
"url",
"string",
",",
"options",
"...",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
")",
"*",
"EthRPC",
"{",
"return",
"New",
"(",
"url",
",",
"options",
"...",
")",
"\n",
"}"
] |
// NewEthRPC create new rpc client with given url
|
[
"NewEthRPC",
"create",
"new",
"rpc",
"client",
"with",
"given",
"url"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L61-L63
|
17,220 |
onrik/ethrpc
|
ethrpc.go
|
Call
|
func (rpc *EthRPC) Call(method string, params ...interface{}) (json.RawMessage, error) {
request := ethRequest{
ID: 1,
JSONRPC: "2.0",
Method: method,
Params: params,
}
body, err := json.Marshal(request)
if err != nil {
return nil, err
}
response, err := rpc.client.Post(rpc.url, "application/json", bytes.NewBuffer(body))
if response != nil {
defer response.Body.Close()
}
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
if rpc.Debug {
rpc.log.Println(fmt.Sprintf("%s\nRequest: %s\nResponse: %s\n", method, body, data))
}
resp := new(ethResponse)
if err := json.Unmarshal(data, resp); err != nil {
return nil, err
}
if resp.Error != nil {
return nil, *resp.Error
}
return resp.Result, nil
}
|
go
|
func (rpc *EthRPC) Call(method string, params ...interface{}) (json.RawMessage, error) {
request := ethRequest{
ID: 1,
JSONRPC: "2.0",
Method: method,
Params: params,
}
body, err := json.Marshal(request)
if err != nil {
return nil, err
}
response, err := rpc.client.Post(rpc.url, "application/json", bytes.NewBuffer(body))
if response != nil {
defer response.Body.Close()
}
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
if rpc.Debug {
rpc.log.Println(fmt.Sprintf("%s\nRequest: %s\nResponse: %s\n", method, body, data))
}
resp := new(ethResponse)
if err := json.Unmarshal(data, resp); err != nil {
return nil, err
}
if resp.Error != nil {
return nil, *resp.Error
}
return resp.Result, nil
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"Call",
"(",
"method",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"(",
"json",
".",
"RawMessage",
",",
"error",
")",
"{",
"request",
":=",
"ethRequest",
"{",
"ID",
":",
"1",
",",
"JSONRPC",
":",
"\"",
"\"",
",",
"Method",
":",
"method",
",",
"Params",
":",
"params",
",",
"}",
"\n\n",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"rpc",
".",
"client",
".",
"Post",
"(",
"rpc",
".",
"url",
",",
"\"",
"\"",
",",
"bytes",
".",
"NewBuffer",
"(",
"body",
")",
")",
"\n",
"if",
"response",
"!=",
"nil",
"{",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"rpc",
".",
"Debug",
"{",
"rpc",
".",
"log",
".",
"Println",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"method",
",",
"body",
",",
"data",
")",
")",
"\n",
"}",
"\n\n",
"resp",
":=",
"new",
"(",
"ethResponse",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"resp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"*",
"resp",
".",
"Error",
"\n",
"}",
"\n\n",
"return",
"resp",
".",
"Result",
",",
"nil",
"\n\n",
"}"
] |
// Call returns raw response of method call
|
[
"Call",
"returns",
"raw",
"response",
"of",
"method",
"call"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L84-L125
|
17,221 |
onrik/ethrpc
|
ethrpc.go
|
Web3ClientVersion
|
func (rpc *EthRPC) Web3ClientVersion() (string, error) {
var clientVersion string
err := rpc.call("web3_clientVersion", &clientVersion)
return clientVersion, err
}
|
go
|
func (rpc *EthRPC) Web3ClientVersion() (string, error) {
var clientVersion string
err := rpc.call("web3_clientVersion", &clientVersion)
return clientVersion, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"Web3ClientVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"clientVersion",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"clientVersion",
")",
"\n",
"return",
"clientVersion",
",",
"err",
"\n",
"}"
] |
// Web3ClientVersion returns the current client version.
|
[
"Web3ClientVersion",
"returns",
"the",
"current",
"client",
"version",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L133-L138
|
17,222 |
onrik/ethrpc
|
ethrpc.go
|
NetVersion
|
func (rpc *EthRPC) NetVersion() (string, error) {
var version string
err := rpc.call("net_version", &version)
return version, err
}
|
go
|
func (rpc *EthRPC) NetVersion() (string, error) {
var version string
err := rpc.call("net_version", &version)
return version, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"NetVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"version",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"version",
")",
"\n",
"return",
"version",
",",
"err",
"\n",
"}"
] |
// NetVersion returns the current network protocol version.
|
[
"NetVersion",
"returns",
"the",
"current",
"network",
"protocol",
"version",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L149-L154
|
17,223 |
onrik/ethrpc
|
ethrpc.go
|
NetListening
|
func (rpc *EthRPC) NetListening() (bool, error) {
var listening bool
err := rpc.call("net_listening", &listening)
return listening, err
}
|
go
|
func (rpc *EthRPC) NetListening() (bool, error) {
var listening bool
err := rpc.call("net_listening", &listening)
return listening, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"NetListening",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"listening",
"bool",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"listening",
")",
"\n",
"return",
"listening",
",",
"err",
"\n",
"}"
] |
// NetListening returns true if client is actively listening for network connections.
|
[
"NetListening",
"returns",
"true",
"if",
"client",
"is",
"actively",
"listening",
"for",
"network",
"connections",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L157-L162
|
17,224 |
onrik/ethrpc
|
ethrpc.go
|
EthProtocolVersion
|
func (rpc *EthRPC) EthProtocolVersion() (string, error) {
var protocolVersion string
err := rpc.call("eth_protocolVersion", &protocolVersion)
return protocolVersion, err
}
|
go
|
func (rpc *EthRPC) EthProtocolVersion() (string, error) {
var protocolVersion string
err := rpc.call("eth_protocolVersion", &protocolVersion)
return protocolVersion, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthProtocolVersion",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"protocolVersion",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"protocolVersion",
")",
"\n",
"return",
"protocolVersion",
",",
"err",
"\n",
"}"
] |
// EthProtocolVersion returns the current ethereum protocol version.
|
[
"EthProtocolVersion",
"returns",
"the",
"current",
"ethereum",
"protocol",
"version",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L175-L180
|
17,225 |
onrik/ethrpc
|
ethrpc.go
|
EthSyncing
|
func (rpc *EthRPC) EthSyncing() (*Syncing, error) {
result, err := rpc.RawCall("eth_syncing")
if err != nil {
return nil, err
}
syncing := new(Syncing)
if bytes.Equal(result, []byte("false")) {
return syncing, nil
}
err = json.Unmarshal(result, syncing)
return syncing, err
}
|
go
|
func (rpc *EthRPC) EthSyncing() (*Syncing, error) {
result, err := rpc.RawCall("eth_syncing")
if err != nil {
return nil, err
}
syncing := new(Syncing)
if bytes.Equal(result, []byte("false")) {
return syncing, nil
}
err = json.Unmarshal(result, syncing)
return syncing, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthSyncing",
"(",
")",
"(",
"*",
"Syncing",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"rpc",
".",
"RawCall",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"syncing",
":=",
"new",
"(",
"Syncing",
")",
"\n",
"if",
"bytes",
".",
"Equal",
"(",
"result",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"{",
"return",
"syncing",
",",
"nil",
"\n",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"result",
",",
"syncing",
")",
"\n",
"return",
"syncing",
",",
"err",
"\n",
"}"
] |
// EthSyncing returns an object with data about the sync status or false.
|
[
"EthSyncing",
"returns",
"an",
"object",
"with",
"data",
"about",
"the",
"sync",
"status",
"or",
"false",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L183-L194
|
17,226 |
onrik/ethrpc
|
ethrpc.go
|
EthCoinbase
|
func (rpc *EthRPC) EthCoinbase() (string, error) {
var address string
err := rpc.call("eth_coinbase", &address)
return address, err
}
|
go
|
func (rpc *EthRPC) EthCoinbase() (string, error) {
var address string
err := rpc.call("eth_coinbase", &address)
return address, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthCoinbase",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"address",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"address",
")",
"\n",
"return",
"address",
",",
"err",
"\n",
"}"
] |
// EthCoinbase returns the client coinbase address
|
[
"EthCoinbase",
"returns",
"the",
"client",
"coinbase",
"address"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L197-L202
|
17,227 |
onrik/ethrpc
|
ethrpc.go
|
EthMining
|
func (rpc *EthRPC) EthMining() (bool, error) {
var mining bool
err := rpc.call("eth_mining", &mining)
return mining, err
}
|
go
|
func (rpc *EthRPC) EthMining() (bool, error) {
var mining bool
err := rpc.call("eth_mining", &mining)
return mining, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthMining",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"mining",
"bool",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"mining",
")",
"\n",
"return",
"mining",
",",
"err",
"\n",
"}"
] |
// EthMining returns true if client is actively mining new blocks.
|
[
"EthMining",
"returns",
"true",
"if",
"client",
"is",
"actively",
"mining",
"new",
"blocks",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L205-L210
|
17,228 |
onrik/ethrpc
|
ethrpc.go
|
EthGasPrice
|
func (rpc *EthRPC) EthGasPrice() (big.Int, error) {
var response string
if err := rpc.call("eth_gasPrice", &response); err != nil {
return big.Int{}, err
}
return ParseBigInt(response)
}
|
go
|
func (rpc *EthRPC) EthGasPrice() (big.Int, error) {
var response string
if err := rpc.call("eth_gasPrice", &response); err != nil {
return big.Int{}, err
}
return ParseBigInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGasPrice",
"(",
")",
"(",
"big",
".",
"Int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"big",
".",
"Int",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseBigInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthGasPrice returns the current price per gas in wei.
|
[
"EthGasPrice",
"returns",
"the",
"current",
"price",
"per",
"gas",
"in",
"wei",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L224-L231
|
17,229 |
onrik/ethrpc
|
ethrpc.go
|
EthAccounts
|
func (rpc *EthRPC) EthAccounts() ([]string, error) {
accounts := []string{}
err := rpc.call("eth_accounts", &accounts)
return accounts, err
}
|
go
|
func (rpc *EthRPC) EthAccounts() ([]string, error) {
accounts := []string{}
err := rpc.call("eth_accounts", &accounts)
return accounts, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthAccounts",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"accounts",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"accounts",
")",
"\n",
"return",
"accounts",
",",
"err",
"\n",
"}"
] |
// EthAccounts returns a list of addresses owned by client.
|
[
"EthAccounts",
"returns",
"a",
"list",
"of",
"addresses",
"owned",
"by",
"client",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L234-L239
|
17,230 |
onrik/ethrpc
|
ethrpc.go
|
EthBlockNumber
|
func (rpc *EthRPC) EthBlockNumber() (int, error) {
var response string
if err := rpc.call("eth_blockNumber", &response); err != nil {
return 0, err
}
return ParseInt(response)
}
|
go
|
func (rpc *EthRPC) EthBlockNumber() (int, error) {
var response string
if err := rpc.call("eth_blockNumber", &response); err != nil {
return 0, err
}
return ParseInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthBlockNumber",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthBlockNumber returns the number of most recent block.
|
[
"EthBlockNumber",
"returns",
"the",
"number",
"of",
"most",
"recent",
"block",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L242-L249
|
17,231 |
onrik/ethrpc
|
ethrpc.go
|
EthGetBalance
|
func (rpc *EthRPC) EthGetBalance(address, block string) (big.Int, error) {
var response string
if err := rpc.call("eth_getBalance", &response, address, block); err != nil {
return big.Int{}, err
}
return ParseBigInt(response)
}
|
go
|
func (rpc *EthRPC) EthGetBalance(address, block string) (big.Int, error) {
var response string
if err := rpc.call("eth_getBalance", &response, address, block); err != nil {
return big.Int{}, err
}
return ParseBigInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetBalance",
"(",
"address",
",",
"block",
"string",
")",
"(",
"big",
".",
"Int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
",",
"address",
",",
"block",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"big",
".",
"Int",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseBigInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthGetBalance returns the balance of the account of given address in wei.
|
[
"EthGetBalance",
"returns",
"the",
"balance",
"of",
"the",
"account",
"of",
"given",
"address",
"in",
"wei",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L252-L259
|
17,232 |
onrik/ethrpc
|
ethrpc.go
|
EthGetStorageAt
|
func (rpc *EthRPC) EthGetStorageAt(data string, position int, tag string) (string, error) {
var result string
err := rpc.call("eth_getStorageAt", &result, data, IntToHex(position), tag)
return result, err
}
|
go
|
func (rpc *EthRPC) EthGetStorageAt(data string, position int, tag string) (string, error) {
var result string
err := rpc.call("eth_getStorageAt", &result, data, IntToHex(position), tag)
return result, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetStorageAt",
"(",
"data",
"string",
",",
"position",
"int",
",",
"tag",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"result",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"result",
",",
"data",
",",
"IntToHex",
"(",
"position",
")",
",",
"tag",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] |
// EthGetStorageAt returns the value from a storage position at a given address.
|
[
"EthGetStorageAt",
"returns",
"the",
"value",
"from",
"a",
"storage",
"position",
"at",
"a",
"given",
"address",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L262-L267
|
17,233 |
onrik/ethrpc
|
ethrpc.go
|
EthGetTransactionCount
|
func (rpc *EthRPC) EthGetTransactionCount(address, block string) (int, error) {
var response string
if err := rpc.call("eth_getTransactionCount", &response, address, block); err != nil {
return 0, err
}
return ParseInt(response)
}
|
go
|
func (rpc *EthRPC) EthGetTransactionCount(address, block string) (int, error) {
var response string
if err := rpc.call("eth_getTransactionCount", &response, address, block); err != nil {
return 0, err
}
return ParseInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetTransactionCount",
"(",
"address",
",",
"block",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
",",
"address",
",",
"block",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthGetTransactionCount returns the number of transactions sent from an address.
|
[
"EthGetTransactionCount",
"returns",
"the",
"number",
"of",
"transactions",
"sent",
"from",
"an",
"address",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L270-L278
|
17,234 |
onrik/ethrpc
|
ethrpc.go
|
EthGetBlockTransactionCountByHash
|
func (rpc *EthRPC) EthGetBlockTransactionCountByHash(hash string) (int, error) {
var response string
if err := rpc.call("eth_getBlockTransactionCountByHash", &response, hash); err != nil {
return 0, err
}
return ParseInt(response)
}
|
go
|
func (rpc *EthRPC) EthGetBlockTransactionCountByHash(hash string) (int, error) {
var response string
if err := rpc.call("eth_getBlockTransactionCountByHash", &response, hash); err != nil {
return 0, err
}
return ParseInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetBlockTransactionCountByHash",
"(",
"hash",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
",",
"hash",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthGetBlockTransactionCountByHash returns the number of transactions in a block from a block matching the given block hash.
|
[
"EthGetBlockTransactionCountByHash",
"returns",
"the",
"number",
"of",
"transactions",
"in",
"a",
"block",
"from",
"a",
"block",
"matching",
"the",
"given",
"block",
"hash",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L281-L289
|
17,235 |
onrik/ethrpc
|
ethrpc.go
|
EthGetBlockTransactionCountByNumber
|
func (rpc *EthRPC) EthGetBlockTransactionCountByNumber(number int) (int, error) {
var response string
if err := rpc.call("eth_getBlockTransactionCountByNumber", &response, IntToHex(number)); err != nil {
return 0, err
}
return ParseInt(response)
}
|
go
|
func (rpc *EthRPC) EthGetBlockTransactionCountByNumber(number int) (int, error) {
var response string
if err := rpc.call("eth_getBlockTransactionCountByNumber", &response, IntToHex(number)); err != nil {
return 0, err
}
return ParseInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetBlockTransactionCountByNumber",
"(",
"number",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n\n",
"if",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
",",
"IntToHex",
"(",
"number",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthGetBlockTransactionCountByNumber returns the number of transactions in a block from a block matching the given block
|
[
"EthGetBlockTransactionCountByNumber",
"returns",
"the",
"number",
"of",
"transactions",
"in",
"a",
"block",
"from",
"a",
"block",
"matching",
"the",
"given",
"block"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L292-L300
|
17,236 |
onrik/ethrpc
|
ethrpc.go
|
EthGetCode
|
func (rpc *EthRPC) EthGetCode(address, block string) (string, error) {
var code string
err := rpc.call("eth_getCode", &code, address, block)
return code, err
}
|
go
|
func (rpc *EthRPC) EthGetCode(address, block string) (string, error) {
var code string
err := rpc.call("eth_getCode", &code, address, block)
return code, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetCode",
"(",
"address",
",",
"block",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"code",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"code",
",",
"address",
",",
"block",
")",
"\n",
"return",
"code",
",",
"err",
"\n",
"}"
] |
// EthGetCode returns code at a given address.
|
[
"EthGetCode",
"returns",
"code",
"at",
"a",
"given",
"address",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L325-L330
|
17,237 |
onrik/ethrpc
|
ethrpc.go
|
EthSendTransaction
|
func (rpc *EthRPC) EthSendTransaction(transaction T) (string, error) {
var hash string
err := rpc.call("eth_sendTransaction", &hash, transaction)
return hash, err
}
|
go
|
func (rpc *EthRPC) EthSendTransaction(transaction T) (string, error) {
var hash string
err := rpc.call("eth_sendTransaction", &hash, transaction)
return hash, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthSendTransaction",
"(",
"transaction",
"T",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"hash",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"hash",
",",
"transaction",
")",
"\n",
"return",
"hash",
",",
"err",
"\n",
"}"
] |
// EthSendTransaction creates new message call transaction or a contract creation, if the data field contains code.
|
[
"EthSendTransaction",
"creates",
"new",
"message",
"call",
"transaction",
"or",
"a",
"contract",
"creation",
"if",
"the",
"data",
"field",
"contains",
"code",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L342-L347
|
17,238 |
onrik/ethrpc
|
ethrpc.go
|
EthSendRawTransaction
|
func (rpc *EthRPC) EthSendRawTransaction(data string) (string, error) {
var hash string
err := rpc.call("eth_sendRawTransaction", &hash, data)
return hash, err
}
|
go
|
func (rpc *EthRPC) EthSendRawTransaction(data string) (string, error) {
var hash string
err := rpc.call("eth_sendRawTransaction", &hash, data)
return hash, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthSendRawTransaction",
"(",
"data",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"hash",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"hash",
",",
"data",
")",
"\n",
"return",
"hash",
",",
"err",
"\n",
"}"
] |
// EthSendRawTransaction creates new message call transaction or a contract creation for signed transactions.
|
[
"EthSendRawTransaction",
"creates",
"new",
"message",
"call",
"transaction",
"or",
"a",
"contract",
"creation",
"for",
"signed",
"transactions",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L350-L355
|
17,239 |
onrik/ethrpc
|
ethrpc.go
|
EthCall
|
func (rpc *EthRPC) EthCall(transaction T, tag string) (string, error) {
var data string
err := rpc.call("eth_call", &data, transaction, tag)
return data, err
}
|
go
|
func (rpc *EthRPC) EthCall(transaction T, tag string) (string, error) {
var data string
err := rpc.call("eth_call", &data, transaction, tag)
return data, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthCall",
"(",
"transaction",
"T",
",",
"tag",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"data",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"data",
",",
"transaction",
",",
"tag",
")",
"\n",
"return",
"data",
",",
"err",
"\n",
"}"
] |
// EthCall executes a new message call immediately without creating a transaction on the block chain.
|
[
"EthCall",
"executes",
"a",
"new",
"message",
"call",
"immediately",
"without",
"creating",
"a",
"transaction",
"on",
"the",
"block",
"chain",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L358-L363
|
17,240 |
onrik/ethrpc
|
ethrpc.go
|
EthEstimateGas
|
func (rpc *EthRPC) EthEstimateGas(transaction T) (int, error) {
var response string
err := rpc.call("eth_estimateGas", &response, transaction)
if err != nil {
return 0, err
}
return ParseInt(response)
}
|
go
|
func (rpc *EthRPC) EthEstimateGas(transaction T) (int, error) {
var response string
err := rpc.call("eth_estimateGas", &response, transaction)
if err != nil {
return 0, err
}
return ParseInt(response)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthEstimateGas",
"(",
"transaction",
"T",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"response",
"string",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"response",
",",
"transaction",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseInt",
"(",
"response",
")",
"\n",
"}"
] |
// EthEstimateGas makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas.
|
[
"EthEstimateGas",
"makes",
"a",
"call",
"or",
"transaction",
"which",
"won",
"t",
"be",
"added",
"to",
"the",
"blockchain",
"and",
"returns",
"the",
"used",
"gas",
"which",
"can",
"be",
"used",
"for",
"estimating",
"the",
"used",
"gas",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L366-L375
|
17,241 |
onrik/ethrpc
|
ethrpc.go
|
EthGetBlockByHash
|
func (rpc *EthRPC) EthGetBlockByHash(hash string, withTransactions bool) (*Block, error) {
return rpc.getBlock("eth_getBlockByHash", withTransactions, hash, withTransactions)
}
|
go
|
func (rpc *EthRPC) EthGetBlockByHash(hash string, withTransactions bool) (*Block, error) {
return rpc.getBlock("eth_getBlockByHash", withTransactions, hash, withTransactions)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetBlockByHash",
"(",
"hash",
"string",
",",
"withTransactions",
"bool",
")",
"(",
"*",
"Block",
",",
"error",
")",
"{",
"return",
"rpc",
".",
"getBlock",
"(",
"\"",
"\"",
",",
"withTransactions",
",",
"hash",
",",
"withTransactions",
")",
"\n",
"}"
] |
// EthGetBlockByHash returns information about a block by hash.
|
[
"EthGetBlockByHash",
"returns",
"information",
"about",
"a",
"block",
"by",
"hash",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L403-L405
|
17,242 |
onrik/ethrpc
|
ethrpc.go
|
EthGetBlockByNumber
|
func (rpc *EthRPC) EthGetBlockByNumber(number int, withTransactions bool) (*Block, error) {
return rpc.getBlock("eth_getBlockByNumber", withTransactions, IntToHex(number), withTransactions)
}
|
go
|
func (rpc *EthRPC) EthGetBlockByNumber(number int, withTransactions bool) (*Block, error) {
return rpc.getBlock("eth_getBlockByNumber", withTransactions, IntToHex(number), withTransactions)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetBlockByNumber",
"(",
"number",
"int",
",",
"withTransactions",
"bool",
")",
"(",
"*",
"Block",
",",
"error",
")",
"{",
"return",
"rpc",
".",
"getBlock",
"(",
"\"",
"\"",
",",
"withTransactions",
",",
"IntToHex",
"(",
"number",
")",
",",
"withTransactions",
")",
"\n",
"}"
] |
// EthGetBlockByNumber returns information about a block by block number.
|
[
"EthGetBlockByNumber",
"returns",
"information",
"about",
"a",
"block",
"by",
"block",
"number",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L408-L410
|
17,243 |
onrik/ethrpc
|
ethrpc.go
|
EthGetTransactionByHash
|
func (rpc *EthRPC) EthGetTransactionByHash(hash string) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByHash", hash)
}
|
go
|
func (rpc *EthRPC) EthGetTransactionByHash(hash string) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByHash", hash)
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetTransactionByHash",
"(",
"hash",
"string",
")",
"(",
"*",
"Transaction",
",",
"error",
")",
"{",
"return",
"rpc",
".",
"getTransaction",
"(",
"\"",
"\"",
",",
"hash",
")",
"\n",
"}"
] |
// EthGetTransactionByHash returns the information about a transaction requested by transaction hash.
|
[
"EthGetTransactionByHash",
"returns",
"the",
"information",
"about",
"a",
"transaction",
"requested",
"by",
"transaction",
"hash",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L420-L422
|
17,244 |
onrik/ethrpc
|
ethrpc.go
|
EthGetTransactionByBlockHashAndIndex
|
func (rpc *EthRPC) EthGetTransactionByBlockHashAndIndex(blockHash string, transactionIndex int) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByBlockHashAndIndex", blockHash, IntToHex(transactionIndex))
}
|
go
|
func (rpc *EthRPC) EthGetTransactionByBlockHashAndIndex(blockHash string, transactionIndex int) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByBlockHashAndIndex", blockHash, IntToHex(transactionIndex))
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetTransactionByBlockHashAndIndex",
"(",
"blockHash",
"string",
",",
"transactionIndex",
"int",
")",
"(",
"*",
"Transaction",
",",
"error",
")",
"{",
"return",
"rpc",
".",
"getTransaction",
"(",
"\"",
"\"",
",",
"blockHash",
",",
"IntToHex",
"(",
"transactionIndex",
")",
")",
"\n",
"}"
] |
// EthGetTransactionByBlockHashAndIndex returns information about a transaction by block hash and transaction index position.
|
[
"EthGetTransactionByBlockHashAndIndex",
"returns",
"information",
"about",
"a",
"transaction",
"by",
"block",
"hash",
"and",
"transaction",
"index",
"position",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L425-L427
|
17,245 |
onrik/ethrpc
|
ethrpc.go
|
EthGetTransactionByBlockNumberAndIndex
|
func (rpc *EthRPC) EthGetTransactionByBlockNumberAndIndex(blockNumber, transactionIndex int) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByBlockNumberAndIndex", IntToHex(blockNumber), IntToHex(transactionIndex))
}
|
go
|
func (rpc *EthRPC) EthGetTransactionByBlockNumberAndIndex(blockNumber, transactionIndex int) (*Transaction, error) {
return rpc.getTransaction("eth_getTransactionByBlockNumberAndIndex", IntToHex(blockNumber), IntToHex(transactionIndex))
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetTransactionByBlockNumberAndIndex",
"(",
"blockNumber",
",",
"transactionIndex",
"int",
")",
"(",
"*",
"Transaction",
",",
"error",
")",
"{",
"return",
"rpc",
".",
"getTransaction",
"(",
"\"",
"\"",
",",
"IntToHex",
"(",
"blockNumber",
")",
",",
"IntToHex",
"(",
"transactionIndex",
")",
")",
"\n",
"}"
] |
// EthGetTransactionByBlockNumberAndIndex returns information about a transaction by block number and transaction index position.
|
[
"EthGetTransactionByBlockNumberAndIndex",
"returns",
"information",
"about",
"a",
"transaction",
"by",
"block",
"number",
"and",
"transaction",
"index",
"position",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L430-L432
|
17,246 |
onrik/ethrpc
|
ethrpc.go
|
EthGetTransactionReceipt
|
func (rpc *EthRPC) EthGetTransactionReceipt(hash string) (*TransactionReceipt, error) {
transactionReceipt := new(TransactionReceipt)
err := rpc.call("eth_getTransactionReceipt", transactionReceipt, hash)
if err != nil {
return nil, err
}
return transactionReceipt, nil
}
|
go
|
func (rpc *EthRPC) EthGetTransactionReceipt(hash string) (*TransactionReceipt, error) {
transactionReceipt := new(TransactionReceipt)
err := rpc.call("eth_getTransactionReceipt", transactionReceipt, hash)
if err != nil {
return nil, err
}
return transactionReceipt, nil
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetTransactionReceipt",
"(",
"hash",
"string",
")",
"(",
"*",
"TransactionReceipt",
",",
"error",
")",
"{",
"transactionReceipt",
":=",
"new",
"(",
"TransactionReceipt",
")",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"transactionReceipt",
",",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"transactionReceipt",
",",
"nil",
"\n",
"}"
] |
// EthGetTransactionReceipt returns the receipt of a transaction by transaction hash.
// Note That the receipt is not available for pending transactions.
|
[
"EthGetTransactionReceipt",
"returns",
"the",
"receipt",
"of",
"a",
"transaction",
"by",
"transaction",
"hash",
".",
"Note",
"That",
"the",
"receipt",
"is",
"not",
"available",
"for",
"pending",
"transactions",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L436-L445
|
17,247 |
onrik/ethrpc
|
ethrpc.go
|
EthGetCompilers
|
func (rpc *EthRPC) EthGetCompilers() ([]string, error) {
compilers := []string{}
err := rpc.call("eth_getCompilers", &compilers)
return compilers, err
}
|
go
|
func (rpc *EthRPC) EthGetCompilers() ([]string, error) {
compilers := []string{}
err := rpc.call("eth_getCompilers", &compilers)
return compilers, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetCompilers",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"compilers",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"compilers",
")",
"\n",
"return",
"compilers",
",",
"err",
"\n",
"}"
] |
// EthGetCompilers returns a list of available compilers in the client.
|
[
"EthGetCompilers",
"returns",
"a",
"list",
"of",
"available",
"compilers",
"in",
"the",
"client",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L448-L453
|
17,248 |
onrik/ethrpc
|
ethrpc.go
|
EthNewFilter
|
func (rpc *EthRPC) EthNewFilter(params FilterParams) (string, error) {
var filterID string
err := rpc.call("eth_newFilter", &filterID, params)
return filterID, err
}
|
go
|
func (rpc *EthRPC) EthNewFilter(params FilterParams) (string, error) {
var filterID string
err := rpc.call("eth_newFilter", &filterID, params)
return filterID, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthNewFilter",
"(",
"params",
"FilterParams",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"filterID",
"string",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"filterID",
",",
"params",
")",
"\n",
"return",
"filterID",
",",
"err",
"\n",
"}"
] |
// EthNewFilter creates a new filter object.
|
[
"EthNewFilter",
"creates",
"a",
"new",
"filter",
"object",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L456-L460
|
17,249 |
onrik/ethrpc
|
ethrpc.go
|
EthNewBlockFilter
|
func (rpc *EthRPC) EthNewBlockFilter() (string, error) {
var filterID string
err := rpc.call("eth_newBlockFilter", &filterID)
return filterID, err
}
|
go
|
func (rpc *EthRPC) EthNewBlockFilter() (string, error) {
var filterID string
err := rpc.call("eth_newBlockFilter", &filterID)
return filterID, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthNewBlockFilter",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"filterID",
"string",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"filterID",
")",
"\n",
"return",
"filterID",
",",
"err",
"\n",
"}"
] |
// EthNewBlockFilter creates a filter in the node, to notify when a new block arrives.
// To check if the state has changed, call EthGetFilterChanges.
|
[
"EthNewBlockFilter",
"creates",
"a",
"filter",
"in",
"the",
"node",
"to",
"notify",
"when",
"a",
"new",
"block",
"arrives",
".",
"To",
"check",
"if",
"the",
"state",
"has",
"changed",
"call",
"EthGetFilterChanges",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L464-L468
|
17,250 |
onrik/ethrpc
|
ethrpc.go
|
EthNewPendingTransactionFilter
|
func (rpc *EthRPC) EthNewPendingTransactionFilter() (string, error) {
var filterID string
err := rpc.call("eth_newPendingTransactionFilter", &filterID)
return filterID, err
}
|
go
|
func (rpc *EthRPC) EthNewPendingTransactionFilter() (string, error) {
var filterID string
err := rpc.call("eth_newPendingTransactionFilter", &filterID)
return filterID, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthNewPendingTransactionFilter",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"filterID",
"string",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"filterID",
")",
"\n",
"return",
"filterID",
",",
"err",
"\n",
"}"
] |
// EthNewPendingTransactionFilter creates a filter in the node, to notify when new pending transactions arrive.
// To check if the state has changed, call EthGetFilterChanges.
|
[
"EthNewPendingTransactionFilter",
"creates",
"a",
"filter",
"in",
"the",
"node",
"to",
"notify",
"when",
"new",
"pending",
"transactions",
"arrive",
".",
"To",
"check",
"if",
"the",
"state",
"has",
"changed",
"call",
"EthGetFilterChanges",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L472-L476
|
17,251 |
onrik/ethrpc
|
ethrpc.go
|
EthUninstallFilter
|
func (rpc *EthRPC) EthUninstallFilter(filterID string) (bool, error) {
var res bool
err := rpc.call("eth_uninstallFilter", &res, filterID)
return res, err
}
|
go
|
func (rpc *EthRPC) EthUninstallFilter(filterID string) (bool, error) {
var res bool
err := rpc.call("eth_uninstallFilter", &res, filterID)
return res, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthUninstallFilter",
"(",
"filterID",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"res",
"bool",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"res",
",",
"filterID",
")",
"\n",
"return",
"res",
",",
"err",
"\n",
"}"
] |
// EthUninstallFilter uninstalls a filter with given id.
|
[
"EthUninstallFilter",
"uninstalls",
"a",
"filter",
"with",
"given",
"id",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L479-L483
|
17,252 |
onrik/ethrpc
|
ethrpc.go
|
EthGetFilterChanges
|
func (rpc *EthRPC) EthGetFilterChanges(filterID string) ([]Log, error) {
var logs = []Log{}
err := rpc.call("eth_getFilterChanges", &logs, filterID)
return logs, err
}
|
go
|
func (rpc *EthRPC) EthGetFilterChanges(filterID string) ([]Log, error) {
var logs = []Log{}
err := rpc.call("eth_getFilterChanges", &logs, filterID)
return logs, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetFilterChanges",
"(",
"filterID",
"string",
")",
"(",
"[",
"]",
"Log",
",",
"error",
")",
"{",
"var",
"logs",
"=",
"[",
"]",
"Log",
"{",
"}",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"logs",
",",
"filterID",
")",
"\n",
"return",
"logs",
",",
"err",
"\n",
"}"
] |
// EthGetFilterChanges polling method for a filter, which returns an array of logs which occurred since last poll.
|
[
"EthGetFilterChanges",
"polling",
"method",
"for",
"a",
"filter",
"which",
"returns",
"an",
"array",
"of",
"logs",
"which",
"occurred",
"since",
"last",
"poll",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L486-L490
|
17,253 |
onrik/ethrpc
|
ethrpc.go
|
EthGetLogs
|
func (rpc *EthRPC) EthGetLogs(params FilterParams) ([]Log, error) {
var logs = []Log{}
err := rpc.call("eth_getLogs", &logs, params)
return logs, err
}
|
go
|
func (rpc *EthRPC) EthGetLogs(params FilterParams) ([]Log, error) {
var logs = []Log{}
err := rpc.call("eth_getLogs", &logs, params)
return logs, err
}
|
[
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"EthGetLogs",
"(",
"params",
"FilterParams",
")",
"(",
"[",
"]",
"Log",
",",
"error",
")",
"{",
"var",
"logs",
"=",
"[",
"]",
"Log",
"{",
"}",
"\n",
"err",
":=",
"rpc",
".",
"call",
"(",
"\"",
"\"",
",",
"&",
"logs",
",",
"params",
")",
"\n",
"return",
"logs",
",",
"err",
"\n",
"}"
] |
// EthGetLogs returns an array of all logs matching a given filter object.
|
[
"EthGetLogs",
"returns",
"an",
"array",
"of",
"all",
"logs",
"matching",
"a",
"given",
"filter",
"object",
"."
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/ethrpc.go#L500-L504
|
17,254 |
onrik/ethrpc
|
options.go
|
WithHttpClient
|
func WithHttpClient(client httpClient) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.client = client
}
}
|
go
|
func WithHttpClient(client httpClient) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.client = client
}
}
|
[
"func",
"WithHttpClient",
"(",
"client",
"httpClient",
")",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"return",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"rpc",
".",
"client",
"=",
"client",
"\n",
"}",
"\n",
"}"
] |
// WithHttpClient set custom http client
|
[
"WithHttpClient",
"set",
"custom",
"http",
"client"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/options.go#L17-L21
|
17,255 |
onrik/ethrpc
|
options.go
|
WithLogger
|
func WithLogger(l logger) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.log = l
}
}
|
go
|
func WithLogger(l logger) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.log = l
}
}
|
[
"func",
"WithLogger",
"(",
"l",
"logger",
")",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"return",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"rpc",
".",
"log",
"=",
"l",
"\n",
"}",
"\n",
"}"
] |
// WithLogger set custom logger
|
[
"WithLogger",
"set",
"custom",
"logger"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/options.go#L24-L28
|
17,256 |
onrik/ethrpc
|
options.go
|
WithDebug
|
func WithDebug(enabled bool) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.Debug = enabled
}
}
|
go
|
func WithDebug(enabled bool) func(rpc *EthRPC) {
return func(rpc *EthRPC) {
rpc.Debug = enabled
}
}
|
[
"func",
"WithDebug",
"(",
"enabled",
"bool",
")",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"return",
"func",
"(",
"rpc",
"*",
"EthRPC",
")",
"{",
"rpc",
".",
"Debug",
"=",
"enabled",
"\n",
"}",
"\n",
"}"
] |
// WithDebug set debug flag
|
[
"WithDebug",
"set",
"debug",
"flag"
] |
6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788
|
https://github.com/onrik/ethrpc/blob/6b8e9c0e9a8ffd2154cd4470a6ffb4919885e788/options.go#L31-L35
|
17,257 |
pborman/getopt
|
v2/generic.go
|
Flag
|
func Flag(v interface{}, short rune, helpvalue ...string) Option {
return CommandLine.long(v, "", short, helpvalue...)
}
|
go
|
func Flag(v interface{}, short rune, helpvalue ...string) Option {
return CommandLine.long(v, "", short, helpvalue...)
}
|
[
"func",
"Flag",
"(",
"v",
"interface",
"{",
"}",
",",
"short",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"Option",
"{",
"return",
"CommandLine",
".",
"long",
"(",
"v",
",",
"\"",
"\"",
",",
"short",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Flag is shorthand for CommandLine.Flag.
|
[
"Flag",
"is",
"shorthand",
"for",
"CommandLine",
".",
"Flag",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/generic.go#L19-L21
|
17,258 |
pborman/getopt
|
v2/generic.go
|
FlagLong
|
func FlagLong(v interface{}, long string, short rune, helpvalue ...string) Option {
return CommandLine.long(v, long, short, helpvalue...)
}
|
go
|
func FlagLong(v interface{}, long string, short rune, helpvalue ...string) Option {
return CommandLine.long(v, long, short, helpvalue...)
}
|
[
"func",
"FlagLong",
"(",
"v",
"interface",
"{",
"}",
",",
"long",
"string",
",",
"short",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"Option",
"{",
"return",
"CommandLine",
".",
"long",
"(",
"v",
",",
"long",
",",
"short",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// FlagLong is shorthand for CommandLine.LongFlag.
|
[
"FlagLong",
"is",
"shorthand",
"for",
"CommandLine",
".",
"LongFlag",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/generic.go#L24-L26
|
17,259 |
pborman/getopt
|
v2/generic.go
|
Flag
|
func (s *Set) Flag(v interface{}, short rune, helpvalue ...string) Option {
return s.long(v, "", short, helpvalue...)
}
|
go
|
func (s *Set) Flag(v interface{}, short rune, helpvalue ...string) Option {
return s.long(v, "", short, helpvalue...)
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"Flag",
"(",
"v",
"interface",
"{",
"}",
",",
"short",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"Option",
"{",
"return",
"s",
".",
"long",
"(",
"v",
",",
"\"",
"\"",
",",
"short",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Flag calls FlagLong with only a short flag name.
|
[
"Flag",
"calls",
"FlagLong",
"with",
"only",
"a",
"short",
"flag",
"name",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/generic.go#L29-L31
|
17,260 |
pborman/getopt
|
v2/generic.go
|
genericValue
|
func genericValue(v Value) interface{} {
if g, ok := v.(*generic); ok {
return g.p
}
return nil
}
|
go
|
func genericValue(v Value) interface{} {
if g, ok := v.(*generic); ok {
return g.p
}
return nil
}
|
[
"func",
"genericValue",
"(",
"v",
"Value",
")",
"interface",
"{",
"}",
"{",
"if",
"g",
",",
"ok",
":=",
"v",
".",
"(",
"*",
"generic",
")",
";",
"ok",
"{",
"return",
"g",
".",
"p",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// genericValue returns the object underlying the generic Value v, or nil if v
// is not a generic Value.
|
[
"genericValue",
"returns",
"the",
"object",
"underlying",
"the",
"generic",
"Value",
"v",
"or",
"nil",
"if",
"v",
"is",
"not",
"a",
"generic",
"Value",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/generic.go#L84-L89
|
17,261 |
pborman/getopt
|
uint64.go
|
Uint64
|
func Uint64(name rune, value uint64, helpvalue ...string) *uint64 {
return CommandLine.Uint64(name, value, helpvalue...)
}
|
go
|
func Uint64(name rune, value uint64, helpvalue ...string) *uint64 {
return CommandLine.Uint64(name, value, helpvalue...)
}
|
[
"func",
"Uint64",
"(",
"name",
"rune",
",",
"value",
"uint64",
",",
"helpvalue",
"...",
"string",
")",
"*",
"uint64",
"{",
"return",
"CommandLine",
".",
"Uint64",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Uint64 creates an option that parses its value as a uint64.
|
[
"Uint64",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"a",
"uint64",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/uint64.go#L36-L38
|
17,262 |
pborman/getopt
|
list.go
|
List
|
func List(name rune, helpvalue ...string) *[]string {
return CommandLine.List(name, helpvalue...)
}
|
go
|
func List(name rune, helpvalue ...string) *[]string {
return CommandLine.List(name, helpvalue...)
}
|
[
"func",
"List",
"(",
"name",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"*",
"[",
"]",
"string",
"{",
"return",
"CommandLine",
".",
"List",
"(",
"name",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// List creates an option that returns a slice of strings. The parameters
// passed are converted from a comma seperated value list into a slice.
// Subsequent occurrences append to the list.
|
[
"List",
"creates",
"an",
"option",
"that",
"returns",
"a",
"slice",
"of",
"strings",
".",
"The",
"parameters",
"passed",
"are",
"converted",
"from",
"a",
"comma",
"seperated",
"value",
"list",
"into",
"a",
"slice",
".",
"Subsequent",
"occurrences",
"append",
"to",
"the",
"list",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/list.go#L29-L31
|
17,263 |
pborman/getopt
|
list.go
|
ListVar
|
func ListVar(p *[]string, name rune, helpvalue ...string) Option {
return CommandLine.ListVar(p, name, helpvalue...)
}
|
go
|
func ListVar(p *[]string, name rune, helpvalue ...string) Option {
return CommandLine.ListVar(p, name, helpvalue...)
}
|
[
"func",
"ListVar",
"(",
"p",
"*",
"[",
"]",
"string",
",",
"name",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"Option",
"{",
"return",
"CommandLine",
".",
"ListVar",
"(",
"p",
",",
"name",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// ListVar creats a list option and places the values in p. If p is pointing
// to a list of values then those are considered the default values. The first
// time name is seen in the options the list will be set to list specified by
// the parameter to the option. Subsequent instances of the option will append
// to the list.
|
[
"ListVar",
"creats",
"a",
"list",
"option",
"and",
"places",
"the",
"values",
"in",
"p",
".",
"If",
"p",
"is",
"pointing",
"to",
"a",
"list",
"of",
"values",
"then",
"those",
"are",
"considered",
"the",
"default",
"values",
".",
"The",
"first",
"time",
"name",
"is",
"seen",
"in",
"the",
"options",
"the",
"list",
"will",
"be",
"set",
"to",
"list",
"specified",
"by",
"the",
"parameter",
"to",
"the",
"option",
".",
"Subsequent",
"instances",
"of",
"the",
"option",
"will",
"append",
"to",
"the",
"list",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/list.go#L54-L56
|
17,264 |
pborman/getopt
|
var.go
|
Var
|
func Var(p Value, name rune, helpvalue ...string) Option {
return CommandLine.VarLong(p, "", name, helpvalue...)
}
|
go
|
func Var(p Value, name rune, helpvalue ...string) Option {
return CommandLine.VarLong(p, "", name, helpvalue...)
}
|
[
"func",
"Var",
"(",
"p",
"Value",
",",
"name",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"Option",
"{",
"return",
"CommandLine",
".",
"VarLong",
"(",
"p",
",",
"\"",
"\"",
",",
"name",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Var creates an option of the specified name. The type and value of the option
// are represented by the first argument, of type Value, which typically holds a
// user-defined implementation of Value. All options are ultimately created
// as a Var.
|
[
"Var",
"creates",
"an",
"option",
"of",
"the",
"specified",
"name",
".",
"The",
"type",
"and",
"value",
"of",
"the",
"option",
"are",
"represented",
"by",
"the",
"first",
"argument",
"of",
"type",
"Value",
"which",
"typically",
"holds",
"a",
"user",
"-",
"defined",
"implementation",
"of",
"Value",
".",
"All",
"options",
"are",
"ultimately",
"created",
"as",
"a",
"Var",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/var.go#L24-L26
|
17,265 |
pborman/getopt
|
uint16.go
|
Uint16
|
func Uint16(name rune, value uint16, helpvalue ...string) *uint16 {
return CommandLine.Uint16(name, value, helpvalue...)
}
|
go
|
func Uint16(name rune, value uint16, helpvalue ...string) *uint16 {
return CommandLine.Uint16(name, value, helpvalue...)
}
|
[
"func",
"Uint16",
"(",
"name",
"rune",
",",
"value",
"uint16",
",",
"helpvalue",
"...",
"string",
")",
"*",
"uint16",
"{",
"return",
"CommandLine",
".",
"Uint16",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Uint16 creates an option that parses its value as an uint16.
|
[
"Uint16",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"an",
"uint16",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/uint16.go#L36-L38
|
17,266 |
pborman/getopt
|
v2/list.go
|
List
|
func List(name rune, helpvalue ...string) *[]string {
p := []string{}
CommandLine.Flag(&p, name, helpvalue...)
return &p
}
|
go
|
func List(name rune, helpvalue ...string) *[]string {
p := []string{}
CommandLine.Flag(&p, name, helpvalue...)
return &p
}
|
[
"func",
"List",
"(",
"name",
"rune",
",",
"helpvalue",
"...",
"string",
")",
"*",
"[",
"]",
"string",
"{",
"p",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"CommandLine",
".",
"Flag",
"(",
"&",
"p",
",",
"name",
",",
"helpvalue",
"...",
")",
"\n",
"return",
"&",
"p",
"\n",
"}"
] |
// List creates an option that returns a slice of strings. The parameters
// passed are converted from a comma separated value list into a slice.
// Subsequent occurrences append to the list.
|
[
"List",
"creates",
"an",
"option",
"that",
"returns",
"a",
"slice",
"of",
"strings",
".",
"The",
"parameters",
"passed",
"are",
"converted",
"from",
"a",
"comma",
"separated",
"value",
"list",
"into",
"a",
"slice",
".",
"Subsequent",
"occurrences",
"append",
"to",
"the",
"list",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/list.go#L10-L14
|
17,267 |
pborman/getopt
|
int32.go
|
Int32
|
func Int32(name rune, value int32, helpvalue ...string) *int32 {
return CommandLine.Int32(name, value, helpvalue...)
}
|
go
|
func Int32(name rune, value int32, helpvalue ...string) *int32 {
return CommandLine.Int32(name, value, helpvalue...)
}
|
[
"func",
"Int32",
"(",
"name",
"rune",
",",
"value",
"int32",
",",
"helpvalue",
"...",
"string",
")",
"*",
"int32",
"{",
"return",
"CommandLine",
".",
"Int32",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Int32 creates an option that parses its value as an int32.
|
[
"Int32",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"an",
"int32",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/int32.go#L36-L38
|
17,268 |
pborman/getopt
|
v2/int.go
|
Int
|
func Int(name rune, value int, helpvalue ...string) *int {
return CommandLine.Int(name, value, helpvalue...)
}
|
go
|
func Int(name rune, value int, helpvalue ...string) *int {
return CommandLine.Int(name, value, helpvalue...)
}
|
[
"func",
"Int",
"(",
"name",
"rune",
",",
"value",
"int",
",",
"helpvalue",
"...",
"string",
")",
"*",
"int",
"{",
"return",
"CommandLine",
".",
"Int",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Int creates an option that parses its value as an integer.
|
[
"Int",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"an",
"integer",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/int.go#L8-L10
|
17,269 |
pborman/getopt
|
v2/int.go
|
Int16
|
func Int16(name rune, value int16, helpvalue ...string) *int16 {
return CommandLine.Int16(name, value, helpvalue...)
}
|
go
|
func Int16(name rune, value int16, helpvalue ...string) *int16 {
return CommandLine.Int16(name, value, helpvalue...)
}
|
[
"func",
"Int16",
"(",
"name",
"rune",
",",
"value",
"int16",
",",
"helpvalue",
"...",
"string",
")",
"*",
"int16",
"{",
"return",
"CommandLine",
".",
"Int16",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Int16 creates an option that parses its value as a 16 bit integer.
|
[
"Int16",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"a",
"16",
"bit",
"integer",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/int.go#L27-L29
|
17,270 |
pborman/getopt
|
v2/int.go
|
Int64
|
func Int64(name rune, value int64, helpvalue ...string) *int64 {
return CommandLine.Int64(name, value, helpvalue...)
}
|
go
|
func Int64(name rune, value int64, helpvalue ...string) *int64 {
return CommandLine.Int64(name, value, helpvalue...)
}
|
[
"func",
"Int64",
"(",
"name",
"rune",
",",
"value",
"int64",
",",
"helpvalue",
"...",
"string",
")",
"*",
"int64",
"{",
"return",
"CommandLine",
".",
"Int64",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Int64 creates an option that parses its value as a 64 bit integer.
|
[
"Int64",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"a",
"64",
"bit",
"integer",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/int.go#L65-L67
|
17,271 |
pborman/getopt
|
v2/int.go
|
Uint
|
func Uint(name rune, value uint, helpvalue ...string) *uint {
return CommandLine.Uint(name, value, helpvalue...)
}
|
go
|
func Uint(name rune, value uint, helpvalue ...string) *uint {
return CommandLine.Uint(name, value, helpvalue...)
}
|
[
"func",
"Uint",
"(",
"name",
"rune",
",",
"value",
"uint",
",",
"helpvalue",
"...",
"string",
")",
"*",
"uint",
"{",
"return",
"CommandLine",
".",
"Uint",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Uint creates an option that parses its value as an unsigned integer.
|
[
"Uint",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"an",
"unsigned",
"integer",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/int.go#L84-L86
|
17,272 |
pborman/getopt
|
v2/int.go
|
Uint32
|
func Uint32(name rune, value uint32, helpvalue ...string) *uint32 {
return CommandLine.Uint32(name, value, helpvalue...)
}
|
go
|
func Uint32(name rune, value uint32, helpvalue ...string) *uint32 {
return CommandLine.Uint32(name, value, helpvalue...)
}
|
[
"func",
"Uint32",
"(",
"name",
"rune",
",",
"value",
"uint32",
",",
"helpvalue",
"...",
"string",
")",
"*",
"uint32",
"{",
"return",
"CommandLine",
".",
"Uint32",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Uint32 creates an option that parses its value as a 32 bit unsigned integer.
|
[
"Uint32",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"a",
"32",
"bit",
"unsigned",
"integer",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/int.go#L122-L124
|
17,273 |
pborman/getopt
|
v2/getopt.go
|
PrintUsage
|
func (s *Set) PrintUsage(w io.Writer) {
parts := make([]string, 2, 4)
parts[0] = "Usage:"
parts[1] = s.program
if usage := s.UsageLine(); usage != "" {
parts = append(parts, usage)
}
if s.parameters != "" {
parts = append(parts, s.parameters)
}
fmt.Fprintln(w, strings.Join(parts, " "))
s.PrintOptions(w)
}
|
go
|
func (s *Set) PrintUsage(w io.Writer) {
parts := make([]string, 2, 4)
parts[0] = "Usage:"
parts[1] = s.program
if usage := s.UsageLine(); usage != "" {
parts = append(parts, usage)
}
if s.parameters != "" {
parts = append(parts, s.parameters)
}
fmt.Fprintln(w, strings.Join(parts, " "))
s.PrintOptions(w)
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"PrintUsage",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"parts",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"2",
",",
"4",
")",
"\n",
"parts",
"[",
"0",
"]",
"=",
"\"",
"\"",
"\n",
"parts",
"[",
"1",
"]",
"=",
"s",
".",
"program",
"\n",
"if",
"usage",
":=",
"s",
".",
"UsageLine",
"(",
")",
";",
"usage",
"!=",
"\"",
"\"",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"usage",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"parameters",
"!=",
"\"",
"\"",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"s",
".",
"parameters",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"w",
",",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
")",
"\n",
"s",
".",
"PrintOptions",
"(",
"w",
")",
"\n",
"}"
] |
// PrintUsage prints the usage line and set of options of set S to w.
|
[
"PrintUsage",
"prints",
"the",
"usage",
"line",
"and",
"set",
"of",
"options",
"of",
"set",
"S",
"to",
"w",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/getopt.go#L229-L241
|
17,274 |
pborman/getopt
|
v2/getopt.go
|
UsageLine
|
func (s *Set) UsageLine() string {
sort.Sort(s.options)
flags := ""
// Build up the list of short flag names and also compute
// how to display the option in the longer help listing.
// We also keep track of the longest option usage string
// that is no more than HelpColumn-3 bytes (at which point
// we use two lines to display the help). The three
// is for the leading space and the two spaces before the
// help string.
for _, opt := range s.options {
if opt.name == "" {
opt.name = "value"
}
if opt.uname == "" {
opt.uname = opt.usageName()
}
if opt.flag && opt.short != 0 && opt.short != '-' {
flags += string(opt.short)
}
}
var opts []string
// The short option - is special
if s.shortOptions['-'] != nil {
opts = append(opts, "-")
}
// If we have a bundle of flags, add them to the list
if flags != "" {
opts = append(opts, "-"+flags)
}
// Now append all the long options and options that require
// values.
for _, opt := range s.options {
if opt.flag {
if opt.short != 0 {
continue
}
flags = "--" + opt.long
} else if opt.short != 0 {
flags = "-" + string(opt.short) + " " + opt.name
} else {
flags = "--" + string(opt.long) + " " + opt.name
}
opts = append(opts, flags)
}
flags = strings.Join(opts, "] [")
if flags != "" {
flags = "[" + flags + "]"
}
return flags
}
|
go
|
func (s *Set) UsageLine() string {
sort.Sort(s.options)
flags := ""
// Build up the list of short flag names and also compute
// how to display the option in the longer help listing.
// We also keep track of the longest option usage string
// that is no more than HelpColumn-3 bytes (at which point
// we use two lines to display the help). The three
// is for the leading space and the two spaces before the
// help string.
for _, opt := range s.options {
if opt.name == "" {
opt.name = "value"
}
if opt.uname == "" {
opt.uname = opt.usageName()
}
if opt.flag && opt.short != 0 && opt.short != '-' {
flags += string(opt.short)
}
}
var opts []string
// The short option - is special
if s.shortOptions['-'] != nil {
opts = append(opts, "-")
}
// If we have a bundle of flags, add them to the list
if flags != "" {
opts = append(opts, "-"+flags)
}
// Now append all the long options and options that require
// values.
for _, opt := range s.options {
if opt.flag {
if opt.short != 0 {
continue
}
flags = "--" + opt.long
} else if opt.short != 0 {
flags = "-" + string(opt.short) + " " + opt.name
} else {
flags = "--" + string(opt.long) + " " + opt.name
}
opts = append(opts, flags)
}
flags = strings.Join(opts, "] [")
if flags != "" {
flags = "[" + flags + "]"
}
return flags
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"UsageLine",
"(",
")",
"string",
"{",
"sort",
".",
"Sort",
"(",
"s",
".",
"options",
")",
"\n",
"flags",
":=",
"\"",
"\"",
"\n\n",
"// Build up the list of short flag names and also compute",
"// how to display the option in the longer help listing.",
"// We also keep track of the longest option usage string",
"// that is no more than HelpColumn-3 bytes (at which point",
"// we use two lines to display the help). The three",
"// is for the leading space and the two spaces before the",
"// help string.",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
".",
"name",
"==",
"\"",
"\"",
"{",
"opt",
".",
"name",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"opt",
".",
"uname",
"==",
"\"",
"\"",
"{",
"opt",
".",
"uname",
"=",
"opt",
".",
"usageName",
"(",
")",
"\n",
"}",
"\n",
"if",
"opt",
".",
"flag",
"&&",
"opt",
".",
"short",
"!=",
"0",
"&&",
"opt",
".",
"short",
"!=",
"'-'",
"{",
"flags",
"+=",
"string",
"(",
"opt",
".",
"short",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"opts",
"[",
"]",
"string",
"\n\n",
"// The short option - is special",
"if",
"s",
".",
"shortOptions",
"[",
"'-'",
"]",
"!=",
"nil",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If we have a bundle of flags, add them to the list",
"if",
"flags",
"!=",
"\"",
"\"",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"\"",
"\"",
"+",
"flags",
")",
"\n",
"}",
"\n\n",
"// Now append all the long options and options that require",
"// values.",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
".",
"flag",
"{",
"if",
"opt",
".",
"short",
"!=",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"flags",
"=",
"\"",
"\"",
"+",
"opt",
".",
"long",
"\n",
"}",
"else",
"if",
"opt",
".",
"short",
"!=",
"0",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"string",
"(",
"opt",
".",
"short",
")",
"+",
"\"",
"\"",
"+",
"opt",
".",
"name",
"\n",
"}",
"else",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"string",
"(",
"opt",
".",
"long",
")",
"+",
"\"",
"\"",
"+",
"opt",
".",
"name",
"\n",
"}",
"\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"flags",
")",
"\n",
"}",
"\n",
"flags",
"=",
"strings",
".",
"Join",
"(",
"opts",
",",
"\"",
"\"",
")",
"\n",
"if",
"flags",
"!=",
"\"",
"\"",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"flags",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"flags",
"\n",
"}"
] |
// UsageLine returns the usage line for the set s. The set's program name and
// parameters, if any, are not included.
|
[
"UsageLine",
"returns",
"the",
"usage",
"line",
"for",
"the",
"set",
"s",
".",
"The",
"set",
"s",
"program",
"name",
"and",
"parameters",
"if",
"any",
"are",
"not",
"included",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/getopt.go#L245-L300
|
17,275 |
pborman/getopt
|
v2/getopt.go
|
breakup
|
func breakup(s string, max int) []string {
var a []string
for {
// strip leading spaces
for len(s) > 0 && s[0] == ' ' {
s = s[1:]
}
// If the option is no longer than the max just return it
if len(s) <= max {
if len(s) != 0 {
a = append(a, s)
}
return a
}
x := max
for s[x] != ' ' {
// the first word is too long?!
if x == 0 {
x = max
for x < len(s) && s[x] != ' ' {
x++
}
if x == len(s) {
x--
}
break
}
x--
}
for s[x] == ' ' {
x--
}
a = append(a, s[:x+1])
s = s[x+1:]
}
}
|
go
|
func breakup(s string, max int) []string {
var a []string
for {
// strip leading spaces
for len(s) > 0 && s[0] == ' ' {
s = s[1:]
}
// If the option is no longer than the max just return it
if len(s) <= max {
if len(s) != 0 {
a = append(a, s)
}
return a
}
x := max
for s[x] != ' ' {
// the first word is too long?!
if x == 0 {
x = max
for x < len(s) && s[x] != ' ' {
x++
}
if x == len(s) {
x--
}
break
}
x--
}
for s[x] == ' ' {
x--
}
a = append(a, s[:x+1])
s = s[x+1:]
}
}
|
[
"func",
"breakup",
"(",
"s",
"string",
",",
"max",
"int",
")",
"[",
"]",
"string",
"{",
"var",
"a",
"[",
"]",
"string",
"\n\n",
"for",
"{",
"// strip leading spaces",
"for",
"len",
"(",
"s",
")",
">",
"0",
"&&",
"s",
"[",
"0",
"]",
"==",
"' '",
"{",
"s",
"=",
"s",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"// If the option is no longer than the max just return it",
"if",
"len",
"(",
"s",
")",
"<=",
"max",
"{",
"if",
"len",
"(",
"s",
")",
"!=",
"0",
"{",
"a",
"=",
"append",
"(",
"a",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}",
"\n",
"x",
":=",
"max",
"\n",
"for",
"s",
"[",
"x",
"]",
"!=",
"' '",
"{",
"// the first word is too long?!",
"if",
"x",
"==",
"0",
"{",
"x",
"=",
"max",
"\n",
"for",
"x",
"<",
"len",
"(",
"s",
")",
"&&",
"s",
"[",
"x",
"]",
"!=",
"' '",
"{",
"x",
"++",
"\n",
"}",
"\n",
"if",
"x",
"==",
"len",
"(",
"s",
")",
"{",
"x",
"--",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"x",
"--",
"\n",
"}",
"\n",
"for",
"s",
"[",
"x",
"]",
"==",
"' '",
"{",
"x",
"--",
"\n",
"}",
"\n",
"a",
"=",
"append",
"(",
"a",
",",
"s",
"[",
":",
"x",
"+",
"1",
"]",
")",
"\n",
"s",
"=",
"s",
"[",
"x",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"}"
] |
// breakup breaks s up into strings no longer than max bytes.
|
[
"breakup",
"breaks",
"s",
"up",
"into",
"strings",
"no",
"longer",
"than",
"max",
"bytes",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/getopt.go#L374-L410
|
17,276 |
pborman/getopt
|
v2/getopt.go
|
Parse
|
func (s *Set) Parse(args []string) {
if err := s.Getopt(args, nil); err != nil {
fmt.Fprintln(stderr, err)
s.usage()
exit(1)
}
}
|
go
|
func (s *Set) Parse(args []string) {
if err := s.Getopt(args, nil); err != nil {
fmt.Fprintln(stderr, err)
s.usage()
exit(1)
}
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"Parse",
"(",
"args",
"[",
"]",
"string",
")",
"{",
"if",
"err",
":=",
"s",
".",
"Getopt",
"(",
"args",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"stderr",
",",
"err",
")",
"\n",
"s",
".",
"usage",
"(",
")",
"\n",
"exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"}"
] |
// Parse uses Getopt to parse args using the options set for s. The first
// element of args is used to assign the program for s if it is not yet set. On
// error, Parse displays the error message as well as a usage message on
// standard error and then exits the program.
|
[
"Parse",
"uses",
"Getopt",
"to",
"parse",
"args",
"using",
"the",
"options",
"set",
"for",
"s",
".",
"The",
"first",
"element",
"of",
"args",
"is",
"used",
"to",
"assign",
"the",
"program",
"for",
"s",
"if",
"it",
"is",
"not",
"yet",
"set",
".",
"On",
"error",
"Parse",
"displays",
"the",
"error",
"message",
"as",
"well",
"as",
"a",
"usage",
"message",
"on",
"standard",
"error",
"and",
"then",
"exits",
"the",
"program",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/getopt.go#L416-L422
|
17,277 |
pborman/getopt
|
getopt.go
|
PrintUsage
|
func (s *Set) PrintUsage(w io.Writer) {
sort.Sort(s.options)
flags := ""
// Build up the list of short flag names and also compute
// how to display the option in the longer help listing.
// We also keep track of the longest option usage string
// that is no more than HelpColumn-3 bytes (at which point
// we use two lines to display the help). The three
// is for the leading space and the two spaces before the
// help string.
for _, opt := range s.options {
if opt.name == "" {
opt.name = "value"
}
if opt.uname == "" {
opt.uname = opt.usageName()
}
if opt.flag && opt.short != 0 && opt.short != '-' {
flags += string(opt.short)
}
}
var opts []string
// The short option - is special
if s.shortOptions['-'] != nil {
opts = append(opts, "-")
}
// If we have a bundle of flags, add them to the list
if flags != "" {
opts = append(opts, "-"+flags)
}
// Now append all the long options and options that require
// values.
for _, opt := range s.options {
if opt.flag {
if opt.short != 0 {
continue
}
flags = "--" + opt.long
} else if opt.short != 0 {
flags = "-" + string(opt.short) + " " + opt.name
} else {
flags = "--" + string(opt.long) + " " + opt.name
}
opts = append(opts, flags)
}
flags = strings.Join(opts, "] [")
if flags != "" {
flags = " [" + flags + "]"
}
if s.parameters != "" {
flags += " " + s.parameters
}
fmt.Fprintf(w, "Usage: %s%s\n", s.program, flags)
s.PrintOptions(w)
}
|
go
|
func (s *Set) PrintUsage(w io.Writer) {
sort.Sort(s.options)
flags := ""
// Build up the list of short flag names and also compute
// how to display the option in the longer help listing.
// We also keep track of the longest option usage string
// that is no more than HelpColumn-3 bytes (at which point
// we use two lines to display the help). The three
// is for the leading space and the two spaces before the
// help string.
for _, opt := range s.options {
if opt.name == "" {
opt.name = "value"
}
if opt.uname == "" {
opt.uname = opt.usageName()
}
if opt.flag && opt.short != 0 && opt.short != '-' {
flags += string(opt.short)
}
}
var opts []string
// The short option - is special
if s.shortOptions['-'] != nil {
opts = append(opts, "-")
}
// If we have a bundle of flags, add them to the list
if flags != "" {
opts = append(opts, "-"+flags)
}
// Now append all the long options and options that require
// values.
for _, opt := range s.options {
if opt.flag {
if opt.short != 0 {
continue
}
flags = "--" + opt.long
} else if opt.short != 0 {
flags = "-" + string(opt.short) + " " + opt.name
} else {
flags = "--" + string(opt.long) + " " + opt.name
}
opts = append(opts, flags)
}
flags = strings.Join(opts, "] [")
if flags != "" {
flags = " [" + flags + "]"
}
if s.parameters != "" {
flags += " " + s.parameters
}
fmt.Fprintf(w, "Usage: %s%s\n", s.program, flags)
s.PrintOptions(w)
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"PrintUsage",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"sort",
".",
"Sort",
"(",
"s",
".",
"options",
")",
"\n",
"flags",
":=",
"\"",
"\"",
"\n\n",
"// Build up the list of short flag names and also compute",
"// how to display the option in the longer help listing.",
"// We also keep track of the longest option usage string",
"// that is no more than HelpColumn-3 bytes (at which point",
"// we use two lines to display the help). The three",
"// is for the leading space and the two spaces before the",
"// help string.",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
".",
"name",
"==",
"\"",
"\"",
"{",
"opt",
".",
"name",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"opt",
".",
"uname",
"==",
"\"",
"\"",
"{",
"opt",
".",
"uname",
"=",
"opt",
".",
"usageName",
"(",
")",
"\n",
"}",
"\n",
"if",
"opt",
".",
"flag",
"&&",
"opt",
".",
"short",
"!=",
"0",
"&&",
"opt",
".",
"short",
"!=",
"'-'",
"{",
"flags",
"+=",
"string",
"(",
"opt",
".",
"short",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"opts",
"[",
"]",
"string",
"\n\n",
"// The short option - is special",
"if",
"s",
".",
"shortOptions",
"[",
"'-'",
"]",
"!=",
"nil",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If we have a bundle of flags, add them to the list",
"if",
"flags",
"!=",
"\"",
"\"",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"\"",
"\"",
"+",
"flags",
")",
"\n",
"}",
"\n\n",
"// Now append all the long options and options that require",
"// values.",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
".",
"flag",
"{",
"if",
"opt",
".",
"short",
"!=",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"flags",
"=",
"\"",
"\"",
"+",
"opt",
".",
"long",
"\n",
"}",
"else",
"if",
"opt",
".",
"short",
"!=",
"0",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"string",
"(",
"opt",
".",
"short",
")",
"+",
"\"",
"\"",
"+",
"opt",
".",
"name",
"\n",
"}",
"else",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"string",
"(",
"opt",
".",
"long",
")",
"+",
"\"",
"\"",
"+",
"opt",
".",
"name",
"\n",
"}",
"\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"flags",
")",
"\n",
"}",
"\n",
"flags",
"=",
"strings",
".",
"Join",
"(",
"opts",
",",
"\"",
"\"",
")",
"\n",
"if",
"flags",
"!=",
"\"",
"\"",
"{",
"flags",
"=",
"\"",
"\"",
"+",
"flags",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"s",
".",
"parameters",
"!=",
"\"",
"\"",
"{",
"flags",
"+=",
"\"",
"\"",
"+",
"s",
".",
"parameters",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\n",
"\"",
",",
"s",
".",
"program",
",",
"flags",
")",
"\n",
"s",
".",
"PrintOptions",
"(",
"w",
")",
"\n",
"}"
] |
// PrintUsage prints the usage of the program to w.
|
[
"PrintUsage",
"prints",
"the",
"usage",
"of",
"the",
"program",
"to",
"w",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/getopt.go#L242-L301
|
17,278 |
pborman/getopt
|
v2/set.go
|
New
|
func New() *Set {
s := &Set{
shortOptions: make(map[rune]*option),
longOptions: make(map[string]*option),
parameters: "[parameters ...]",
}
s.usage = func() {
s.PrintUsage(stderr)
}
return s
}
|
go
|
func New() *Set {
s := &Set{
shortOptions: make(map[rune]*option),
longOptions: make(map[string]*option),
parameters: "[parameters ...]",
}
s.usage = func() {
s.PrintUsage(stderr)
}
return s
}
|
[
"func",
"New",
"(",
")",
"*",
"Set",
"{",
"s",
":=",
"&",
"Set",
"{",
"shortOptions",
":",
"make",
"(",
"map",
"[",
"rune",
"]",
"*",
"option",
")",
",",
"longOptions",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"option",
")",
",",
"parameters",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"s",
".",
"usage",
"=",
"func",
"(",
")",
"{",
"s",
".",
"PrintUsage",
"(",
"stderr",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// New returns a newly created option set.
|
[
"New",
"returns",
"a",
"newly",
"created",
"option",
"set",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/set.go#L52-L63
|
17,279 |
pborman/getopt
|
v2/set.go
|
Visit
|
func (s *Set) Visit(fn func(Option)) {
sort.Sort(s.options)
for _, opt := range s.options {
if opt.count > 0 {
fn(opt)
}
}
}
|
go
|
func (s *Set) Visit(fn func(Option)) {
sort.Sort(s.options)
for _, opt := range s.options {
if opt.count > 0 {
fn(opt)
}
}
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"Visit",
"(",
"fn",
"func",
"(",
"Option",
")",
")",
"{",
"sort",
".",
"Sort",
"(",
"s",
".",
"options",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
".",
"count",
">",
"0",
"{",
"fn",
"(",
"opt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Visit visits the options in s in lexicographical order, calling fn
// for each. It visits only those options that have been set.
|
[
"Visit",
"visits",
"the",
"options",
"in",
"s",
"in",
"lexicographical",
"order",
"calling",
"fn",
"for",
"each",
".",
"It",
"visits",
"only",
"those",
"options",
"that",
"have",
"been",
"set",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/set.go#L259-L266
|
17,280 |
pborman/getopt
|
v2/set.go
|
VisitAll
|
func (s *Set) VisitAll(fn func(Option)) {
sort.Sort(s.options)
for _, opt := range s.options {
fn(opt)
}
}
|
go
|
func (s *Set) VisitAll(fn func(Option)) {
sort.Sort(s.options)
for _, opt := range s.options {
fn(opt)
}
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"VisitAll",
"(",
"fn",
"func",
"(",
"Option",
")",
")",
"{",
"sort",
".",
"Sort",
"(",
"s",
".",
"options",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"s",
".",
"options",
"{",
"fn",
"(",
"opt",
")",
"\n",
"}",
"\n",
"}"
] |
// VisitAll visits the command-line flags in lexicographical order, calling fn
// for each. It visits all flags, even those not set.
|
[
"VisitAll",
"visits",
"the",
"command",
"-",
"line",
"flags",
"in",
"lexicographical",
"order",
"calling",
"fn",
"for",
"each",
".",
"It",
"visits",
"all",
"flags",
"even",
"those",
"not",
"set",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/set.go#L274-L279
|
17,281 |
pborman/getopt
|
string.go
|
String
|
func String(name rune, value string, helpvalue ...string) *string {
return CommandLine.String(name, value, helpvalue...)
}
|
go
|
func String(name rune, value string, helpvalue ...string) *string {
return CommandLine.String(name, value, helpvalue...)
}
|
[
"func",
"String",
"(",
"name",
"rune",
",",
"value",
"string",
",",
"helpvalue",
"...",
"string",
")",
"*",
"string",
"{",
"return",
"CommandLine",
".",
"String",
"(",
"name",
",",
"value",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// String returns a value option that stores is value as a string. The
// initial value of the string is passed in value.
|
[
"String",
"returns",
"a",
"value",
"option",
"that",
"stores",
"is",
"value",
"as",
"a",
"string",
".",
"The",
"initial",
"value",
"of",
"the",
"string",
"is",
"passed",
"in",
"value",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/string.go#L20-L22
|
17,282 |
pborman/getopt
|
v2/var.go
|
init
|
func init() {
pc, _, _, ok := runtime.Caller(0)
if !ok {
return
}
f := runtime.FuncForPC(pc)
if f == nil {
return
}
thisPackage = f.Name()
x := strings.LastIndex(thisPackage, "/")
if x < 0 {
return
}
y := strings.Index(thisPackage[x:], ".")
if y < 0 {
return
}
// thisPackage includes the trailing . after the package name.
thisPackage = thisPackage[:x+y+1]
}
|
go
|
func init() {
pc, _, _, ok := runtime.Caller(0)
if !ok {
return
}
f := runtime.FuncForPC(pc)
if f == nil {
return
}
thisPackage = f.Name()
x := strings.LastIndex(thisPackage, "/")
if x < 0 {
return
}
y := strings.Index(thisPackage[x:], ".")
if y < 0 {
return
}
// thisPackage includes the trailing . after the package name.
thisPackage = thisPackage[:x+y+1]
}
|
[
"func",
"init",
"(",
")",
"{",
"pc",
",",
"_",
",",
"_",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"0",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"f",
":=",
"runtime",
".",
"FuncForPC",
"(",
"pc",
")",
"\n",
"if",
"f",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"thisPackage",
"=",
"f",
".",
"Name",
"(",
")",
"\n",
"x",
":=",
"strings",
".",
"LastIndex",
"(",
"thisPackage",
",",
"\"",
"\"",
")",
"\n",
"if",
"x",
"<",
"0",
"{",
"return",
"\n",
"}",
"\n",
"y",
":=",
"strings",
".",
"Index",
"(",
"thisPackage",
"[",
"x",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"y",
"<",
"0",
"{",
"return",
"\n",
"}",
"\n",
"// thisPackage includes the trailing . after the package name.",
"thisPackage",
"=",
"thisPackage",
"[",
":",
"x",
"+",
"y",
"+",
"1",
"]",
"\n",
"}"
] |
// init initializes thisPackage to our full package with the trailing .
// included.
|
[
"init",
"initializes",
"thisPackage",
"to",
"our",
"full",
"package",
"with",
"the",
"trailing",
".",
"included",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/var.go#L32-L52
|
17,283 |
pborman/getopt
|
v2/var.go
|
calledFrom
|
func calledFrom() string {
for i := 2; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
return ""
}
if !strings.HasSuffix(file, "_test.go") {
f := runtime.FuncForPC(pc)
if f != nil && strings.HasPrefix(f.Name(), thisPackage) {
continue
}
}
return fmt.Sprintf("%s:%d", file, line)
}
}
|
go
|
func calledFrom() string {
for i := 2; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
return ""
}
if !strings.HasSuffix(file, "_test.go") {
f := runtime.FuncForPC(pc)
if f != nil && strings.HasPrefix(f.Name(), thisPackage) {
continue
}
}
return fmt.Sprintf("%s:%d", file, line)
}
}
|
[
"func",
"calledFrom",
"(",
")",
"string",
"{",
"for",
"i",
":=",
"2",
";",
";",
"i",
"++",
"{",
"pc",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"i",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"file",
",",
"\"",
"\"",
")",
"{",
"f",
":=",
"runtime",
".",
"FuncForPC",
"(",
"pc",
")",
"\n",
"if",
"f",
"!=",
"nil",
"&&",
"strings",
".",
"HasPrefix",
"(",
"f",
".",
"Name",
"(",
")",
",",
"thisPackage",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"file",
",",
"line",
")",
"\n",
"}",
"\n",
"}"
] |
// calledFrom returns a string containing the file and linenumber of the first
// stack frame above us that is not part of this package and is not a test.
// This is used to determine where a flag was initialized.
|
[
"calledFrom",
"returns",
"a",
"string",
"containing",
"the",
"file",
"and",
"linenumber",
"of",
"the",
"first",
"stack",
"frame",
"above",
"us",
"that",
"is",
"not",
"part",
"of",
"this",
"package",
"and",
"is",
"not",
"a",
"test",
".",
"This",
"is",
"used",
"to",
"determine",
"where",
"a",
"flag",
"was",
"initialized",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/var.go#L57-L71
|
17,284 |
pborman/getopt
|
error.go
|
unknownOption
|
func unknownOption(name interface{}) *Error {
i := &Error{ErrorCode: UnknownOption}
switch n := name.(type) {
case rune:
if n == '-' {
i.Name = "-"
} else {
i.Name = "-" + string(n)
}
case string:
i.Name = "--" + n
}
i.Err = fmt.Errorf("unknown option: %s", i.Name)
return i
}
|
go
|
func unknownOption(name interface{}) *Error {
i := &Error{ErrorCode: UnknownOption}
switch n := name.(type) {
case rune:
if n == '-' {
i.Name = "-"
} else {
i.Name = "-" + string(n)
}
case string:
i.Name = "--" + n
}
i.Err = fmt.Errorf("unknown option: %s", i.Name)
return i
}
|
[
"func",
"unknownOption",
"(",
"name",
"interface",
"{",
"}",
")",
"*",
"Error",
"{",
"i",
":=",
"&",
"Error",
"{",
"ErrorCode",
":",
"UnknownOption",
"}",
"\n",
"switch",
"n",
":=",
"name",
".",
"(",
"type",
")",
"{",
"case",
"rune",
":",
"if",
"n",
"==",
"'-'",
"{",
"i",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"i",
".",
"Name",
"=",
"\"",
"\"",
"+",
"string",
"(",
"n",
")",
"\n",
"}",
"\n",
"case",
"string",
":",
"i",
".",
"Name",
"=",
"\"",
"\"",
"+",
"n",
"\n",
"}",
"\n",
"i",
".",
"Err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
".",
"Name",
")",
"\n",
"return",
"i",
"\n",
"}"
] |
// unknownOption returns an Error indicating an unknown option was
// encountered.
|
[
"unknownOption",
"returns",
"an",
"Error",
"indicating",
"an",
"unknown",
"option",
"was",
"encountered",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/error.go#L47-L61
|
17,285 |
pborman/getopt
|
error.go
|
missingArg
|
func missingArg(o Option) *Error {
return &Error{
ErrorCode: MissingParameter,
Name: o.Name(),
Err: fmt.Errorf("missing parameter for %s", o.Name()),
}
}
|
go
|
func missingArg(o Option) *Error {
return &Error{
ErrorCode: MissingParameter,
Name: o.Name(),
Err: fmt.Errorf("missing parameter for %s", o.Name()),
}
}
|
[
"func",
"missingArg",
"(",
"o",
"Option",
")",
"*",
"Error",
"{",
"return",
"&",
"Error",
"{",
"ErrorCode",
":",
"MissingParameter",
",",
"Name",
":",
"o",
".",
"Name",
"(",
")",
",",
"Err",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"Name",
"(",
")",
")",
",",
"}",
"\n",
"}"
] |
// missingArg returns an Error inidicating option o was not passed
// a required paramter.
|
[
"missingArg",
"returns",
"an",
"Error",
"inidicating",
"option",
"o",
"was",
"not",
"passed",
"a",
"required",
"paramter",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/error.go#L65-L71
|
17,286 |
pborman/getopt
|
error.go
|
extraArg
|
func extraArg(o Option, value string) *Error {
return &Error{
ErrorCode: ExtraParameter,
Name: o.Name(),
Parameter: value,
Err: fmt.Errorf("unexpected parameter passed to %s: %q", o.Name(), value),
}
}
|
go
|
func extraArg(o Option, value string) *Error {
return &Error{
ErrorCode: ExtraParameter,
Name: o.Name(),
Parameter: value,
Err: fmt.Errorf("unexpected parameter passed to %s: %q", o.Name(), value),
}
}
|
[
"func",
"extraArg",
"(",
"o",
"Option",
",",
"value",
"string",
")",
"*",
"Error",
"{",
"return",
"&",
"Error",
"{",
"ErrorCode",
":",
"ExtraParameter",
",",
"Name",
":",
"o",
".",
"Name",
"(",
")",
",",
"Parameter",
":",
"value",
",",
"Err",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"Name",
"(",
")",
",",
"value",
")",
",",
"}",
"\n",
"}"
] |
// extraArg returns an Error inidicating option o was passed the
// unexpected paramter value.
|
[
"extraArg",
"returns",
"an",
"Error",
"inidicating",
"option",
"o",
"was",
"passed",
"the",
"unexpected",
"paramter",
"value",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/error.go#L75-L82
|
17,287 |
pborman/getopt
|
error.go
|
setError
|
func setError(o Option, value string, err error) *Error {
return &Error{
ErrorCode: Invalid,
Name: o.Name(),
Parameter: value,
Err: err,
}
}
|
go
|
func setError(o Option, value string, err error) *Error {
return &Error{
ErrorCode: Invalid,
Name: o.Name(),
Parameter: value,
Err: err,
}
}
|
[
"func",
"setError",
"(",
"o",
"Option",
",",
"value",
"string",
",",
"err",
"error",
")",
"*",
"Error",
"{",
"return",
"&",
"Error",
"{",
"ErrorCode",
":",
"Invalid",
",",
"Name",
":",
"o",
".",
"Name",
"(",
")",
",",
"Parameter",
":",
"value",
",",
"Err",
":",
"err",
",",
"}",
"\n",
"}"
] |
// setError returns an Error inidicating option o and the specified
// error while setting it to value.
|
[
"setError",
"returns",
"an",
"Error",
"inidicating",
"option",
"o",
"and",
"the",
"specified",
"error",
"while",
"setting",
"it",
"to",
"value",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/error.go#L86-L93
|
17,288 |
pborman/getopt
|
enum.go
|
Enum
|
func Enum(name rune, values []string, helpvalue ...string) *string {
return CommandLine.Enum(name, values, helpvalue...)
}
|
go
|
func Enum(name rune, values []string, helpvalue ...string) *string {
return CommandLine.Enum(name, values, helpvalue...)
}
|
[
"func",
"Enum",
"(",
"name",
"rune",
",",
"values",
"[",
"]",
"string",
",",
"helpvalue",
"...",
"string",
")",
"*",
"string",
"{",
"return",
"CommandLine",
".",
"Enum",
"(",
"name",
",",
"values",
",",
"helpvalue",
"...",
")",
"\n",
"}"
] |
// Enum creates an option that can only be set to one of the enumerated strings
// passed in values. Passing nil or an empty slice results in an option that
// will always fail.
|
[
"Enum",
"creates",
"an",
"option",
"that",
"can",
"only",
"be",
"set",
"to",
"one",
"of",
"the",
"enumerated",
"strings",
"passed",
"in",
"values",
".",
"Passing",
"nil",
"or",
"an",
"empty",
"slice",
"results",
"in",
"an",
"option",
"that",
"will",
"always",
"fail",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/enum.go#L32-L34
|
17,289 |
pborman/getopt
|
v2/duration.go
|
Duration
|
func Duration(name rune, value time.Duration, helpvalue ...string) *time.Duration {
CommandLine.FlagLong(&value, "", name, helpvalue...)
return &value
}
|
go
|
func Duration(name rune, value time.Duration, helpvalue ...string) *time.Duration {
CommandLine.FlagLong(&value, "", name, helpvalue...)
return &value
}
|
[
"func",
"Duration",
"(",
"name",
"rune",
",",
"value",
"time",
".",
"Duration",
",",
"helpvalue",
"...",
"string",
")",
"*",
"time",
".",
"Duration",
"{",
"CommandLine",
".",
"FlagLong",
"(",
"&",
"value",
",",
"\"",
"\"",
",",
"name",
",",
"helpvalue",
"...",
")",
"\n",
"return",
"&",
"value",
"\n",
"}"
] |
// Duration creates an option that parses its value as a time.Duration.
|
[
"Duration",
"creates",
"an",
"option",
"that",
"parses",
"its",
"value",
"as",
"a",
"time",
".",
"Duration",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/v2/duration.go#L10-L13
|
17,290 |
pborman/getopt
|
option.go
|
sortName
|
func (o *option) sortName() string {
if o.short != 0 {
return string(o.short) + o.long
}
return o.long[:1] + o.long
}
|
go
|
func (o *option) sortName() string {
if o.short != 0 {
return string(o.short) + o.long
}
return o.long[:1] + o.long
}
|
[
"func",
"(",
"o",
"*",
"option",
")",
"sortName",
"(",
")",
"string",
"{",
"if",
"o",
".",
"short",
"!=",
"0",
"{",
"return",
"string",
"(",
"o",
".",
"short",
")",
"+",
"o",
".",
"long",
"\n",
"}",
"\n",
"return",
"o",
".",
"long",
"[",
":",
"1",
"]",
"+",
"o",
".",
"long",
"\n",
"}"
] |
// sortName returns the name to sort the option on.
|
[
"sortName",
"returns",
"the",
"name",
"to",
"sort",
"the",
"option",
"on",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/option.go#L109-L114
|
17,291 |
pborman/getopt
|
option.go
|
Reset
|
func (o *option) Reset() {
o.isLong = false
o.count = 0
o.value.Set(o.defval, o)
}
|
go
|
func (o *option) Reset() {
o.isLong = false
o.count = 0
o.value.Set(o.defval, o)
}
|
[
"func",
"(",
"o",
"*",
"option",
")",
"Reset",
"(",
")",
"{",
"o",
".",
"isLong",
"=",
"false",
"\n",
"o",
".",
"count",
"=",
"0",
"\n",
"o",
".",
"value",
".",
"Set",
"(",
"o",
".",
"defval",
",",
"o",
")",
"\n",
"}"
] |
// Reset rests an option so that it appears it has not yet been seen.
|
[
"Reset",
"rests",
"an",
"option",
"so",
"that",
"it",
"appears",
"it",
"has",
"not",
"yet",
"been",
"seen",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/option.go#L138-L142
|
17,292 |
pborman/getopt
|
option.go
|
AddOption
|
func (s *Set) AddOption(o Option) {
opt := o.(*option)
for _, eopt := range s.options {
if opt == eopt {
return
}
}
if opt.short != 0 {
if oo, ok := s.shortOptions[opt.short]; ok {
fmt.Fprintf(stderr, "%s: -%c already declared at %s\n", opt.where, opt.short, oo.where)
exit(1)
}
s.shortOptions[opt.short] = opt
}
if opt.long != "" {
if oo, ok := s.longOptions[opt.long]; ok {
fmt.Fprintf(stderr, "%s: --%s already declared at %s\n", opt.where, opt.long, oo.where)
exit(1)
}
s.longOptions[opt.long] = opt
}
s.options = append(s.options, opt)
}
|
go
|
func (s *Set) AddOption(o Option) {
opt := o.(*option)
for _, eopt := range s.options {
if opt == eopt {
return
}
}
if opt.short != 0 {
if oo, ok := s.shortOptions[opt.short]; ok {
fmt.Fprintf(stderr, "%s: -%c already declared at %s\n", opt.where, opt.short, oo.where)
exit(1)
}
s.shortOptions[opt.short] = opt
}
if opt.long != "" {
if oo, ok := s.longOptions[opt.long]; ok {
fmt.Fprintf(stderr, "%s: --%s already declared at %s\n", opt.where, opt.long, oo.where)
exit(1)
}
s.longOptions[opt.long] = opt
}
s.options = append(s.options, opt)
}
|
[
"func",
"(",
"s",
"*",
"Set",
")",
"AddOption",
"(",
"o",
"Option",
")",
"{",
"opt",
":=",
"o",
".",
"(",
"*",
"option",
")",
"\n",
"for",
"_",
",",
"eopt",
":=",
"range",
"s",
".",
"options",
"{",
"if",
"opt",
"==",
"eopt",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"opt",
".",
"short",
"!=",
"0",
"{",
"if",
"oo",
",",
"ok",
":=",
"s",
".",
"shortOptions",
"[",
"opt",
".",
"short",
"]",
";",
"ok",
"{",
"fmt",
".",
"Fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
",",
"opt",
".",
"where",
",",
"opt",
".",
"short",
",",
"oo",
".",
"where",
")",
"\n",
"exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"s",
".",
"shortOptions",
"[",
"opt",
".",
"short",
"]",
"=",
"opt",
"\n",
"}",
"\n",
"if",
"opt",
".",
"long",
"!=",
"\"",
"\"",
"{",
"if",
"oo",
",",
"ok",
":=",
"s",
".",
"longOptions",
"[",
"opt",
".",
"long",
"]",
";",
"ok",
"{",
"fmt",
".",
"Fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
",",
"opt",
".",
"where",
",",
"opt",
".",
"long",
",",
"oo",
".",
"where",
")",
"\n",
"exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"s",
".",
"longOptions",
"[",
"opt",
".",
"long",
"]",
"=",
"opt",
"\n",
"}",
"\n",
"s",
".",
"options",
"=",
"append",
"(",
"s",
".",
"options",
",",
"opt",
")",
"\n",
"}"
] |
// AddOption add the option o to set s if o is not already in set s.
|
[
"AddOption",
"add",
"the",
"option",
"o",
"to",
"set",
"s",
"if",
"o",
"is",
"not",
"already",
"in",
"set",
"s",
"."
] |
ee0cd42419d3adee9239dbd1c375717fe482dac7
|
https://github.com/pborman/getopt/blob/ee0cd42419d3adee9239dbd1c375717fe482dac7/option.go#L171-L193
|
17,293 |
micro/go-rcache
|
options.go
|
WithTTL
|
func WithTTL(t time.Duration) Option {
return func(o *Options) {
o.TTL = t
}
}
|
go
|
func WithTTL(t time.Duration) Option {
return func(o *Options) {
o.TTL = t
}
}
|
[
"func",
"WithTTL",
"(",
"t",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"Options",
")",
"{",
"o",
".",
"TTL",
"=",
"t",
"\n",
"}",
"\n",
"}"
] |
// WithTTL sets the cache TTL
|
[
"WithTTL",
"sets",
"the",
"cache",
"TTL"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/options.go#L8-L12
|
17,294 |
micro/go-rcache
|
rcache.go
|
isValid
|
func (c *cache) isValid(services []*registry.Service, ttl time.Time) bool {
// no services exist
if len(services) == 0 {
return false
}
// ttl is invalid
if ttl.IsZero() {
return false
}
// time since ttl is longer than timeout
if time.Since(ttl) > c.opts.TTL {
return false
}
// ok
return true
}
|
go
|
func (c *cache) isValid(services []*registry.Service, ttl time.Time) bool {
// no services exist
if len(services) == 0 {
return false
}
// ttl is invalid
if ttl.IsZero() {
return false
}
// time since ttl is longer than timeout
if time.Since(ttl) > c.opts.TTL {
return false
}
// ok
return true
}
|
[
"func",
"(",
"c",
"*",
"cache",
")",
"isValid",
"(",
"services",
"[",
"]",
"*",
"registry",
".",
"Service",
",",
"ttl",
"time",
".",
"Time",
")",
"bool",
"{",
"// no services exist",
"if",
"len",
"(",
"services",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// ttl is invalid",
"if",
"ttl",
".",
"IsZero",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// time since ttl is longer than timeout",
"if",
"time",
".",
"Since",
"(",
"ttl",
")",
">",
"c",
".",
"opts",
".",
"TTL",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// ok",
"return",
"true",
"\n",
"}"
] |
// isValid checks if the service is valid
|
[
"isValid",
"checks",
"if",
"the",
"service",
"is",
"valid"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/rcache.go#L53-L71
|
17,295 |
micro/go-rcache
|
rcache.go
|
cp
|
func (c *cache) cp(current []*registry.Service) []*registry.Service {
var services []*registry.Service
for _, service := range current {
// copy service
s := new(registry.Service)
*s = *service
// copy nodes
var nodes []*registry.Node
for _, node := range service.Nodes {
n := new(registry.Node)
*n = *node
nodes = append(nodes, n)
}
s.Nodes = nodes
// copy endpoints
var eps []*registry.Endpoint
for _, ep := range service.Endpoints {
e := new(registry.Endpoint)
*e = *ep
eps = append(eps, e)
}
s.Endpoints = eps
// append service
services = append(services, s)
}
return services
}
|
go
|
func (c *cache) cp(current []*registry.Service) []*registry.Service {
var services []*registry.Service
for _, service := range current {
// copy service
s := new(registry.Service)
*s = *service
// copy nodes
var nodes []*registry.Node
for _, node := range service.Nodes {
n := new(registry.Node)
*n = *node
nodes = append(nodes, n)
}
s.Nodes = nodes
// copy endpoints
var eps []*registry.Endpoint
for _, ep := range service.Endpoints {
e := new(registry.Endpoint)
*e = *ep
eps = append(eps, e)
}
s.Endpoints = eps
// append service
services = append(services, s)
}
return services
}
|
[
"func",
"(",
"c",
"*",
"cache",
")",
"cp",
"(",
"current",
"[",
"]",
"*",
"registry",
".",
"Service",
")",
"[",
"]",
"*",
"registry",
".",
"Service",
"{",
"var",
"services",
"[",
"]",
"*",
"registry",
".",
"Service",
"\n\n",
"for",
"_",
",",
"service",
":=",
"range",
"current",
"{",
"// copy service",
"s",
":=",
"new",
"(",
"registry",
".",
"Service",
")",
"\n",
"*",
"s",
"=",
"*",
"service",
"\n\n",
"// copy nodes",
"var",
"nodes",
"[",
"]",
"*",
"registry",
".",
"Node",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"service",
".",
"Nodes",
"{",
"n",
":=",
"new",
"(",
"registry",
".",
"Node",
")",
"\n",
"*",
"n",
"=",
"*",
"node",
"\n",
"nodes",
"=",
"append",
"(",
"nodes",
",",
"n",
")",
"\n",
"}",
"\n",
"s",
".",
"Nodes",
"=",
"nodes",
"\n\n",
"// copy endpoints",
"var",
"eps",
"[",
"]",
"*",
"registry",
".",
"Endpoint",
"\n",
"for",
"_",
",",
"ep",
":=",
"range",
"service",
".",
"Endpoints",
"{",
"e",
":=",
"new",
"(",
"registry",
".",
"Endpoint",
")",
"\n",
"*",
"e",
"=",
"*",
"ep",
"\n",
"eps",
"=",
"append",
"(",
"eps",
",",
"e",
")",
"\n",
"}",
"\n",
"s",
".",
"Endpoints",
"=",
"eps",
"\n\n",
"// append service",
"services",
"=",
"append",
"(",
"services",
",",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"services",
"\n",
"}"
] |
// cp copies a service. Because we're caching handing back pointers would
// create a race condition, so we do this instead its fast enough
|
[
"cp",
"copies",
"a",
"service",
".",
"Because",
"we",
"re",
"caching",
"handing",
"back",
"pointers",
"would",
"create",
"a",
"race",
"condition",
"so",
"we",
"do",
"this",
"instead",
"its",
"fast",
"enough"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/rcache.go#L84-L115
|
17,296 |
micro/go-rcache
|
rcache.go
|
run
|
func (c *cache) run(service string) {
// set watcher
c.Lock()
c.watched[service] = true
c.Unlock()
// delete watcher on exit
defer func() {
c.Lock()
delete(c.watched, service)
c.Unlock()
}()
var a, b int
for {
// exit early if already dead
if c.quit() {
return
}
// jitter before starting
j := rand.Int63n(100)
time.Sleep(time.Duration(j) * time.Millisecond)
// create new watcher
w, err := c.Registry.Watch(
registry.WatchService(service),
)
if err != nil {
if c.quit() {
return
}
d := backoff(a)
if a > 3 {
log.Log("rcache: ", err, " backing off ", d)
a = 0
}
time.Sleep(d)
a++
continue
}
// reset a
a = 0
// watch for events
if err := c.watch(w); err != nil {
if c.quit() {
return
}
d := backoff(b)
if b > 3 {
log.Log("rcache: ", err, " backing off ", d)
b = 0
}
time.Sleep(d)
b++
continue
}
// reset b
b = 0
}
}
|
go
|
func (c *cache) run(service string) {
// set watcher
c.Lock()
c.watched[service] = true
c.Unlock()
// delete watcher on exit
defer func() {
c.Lock()
delete(c.watched, service)
c.Unlock()
}()
var a, b int
for {
// exit early if already dead
if c.quit() {
return
}
// jitter before starting
j := rand.Int63n(100)
time.Sleep(time.Duration(j) * time.Millisecond)
// create new watcher
w, err := c.Registry.Watch(
registry.WatchService(service),
)
if err != nil {
if c.quit() {
return
}
d := backoff(a)
if a > 3 {
log.Log("rcache: ", err, " backing off ", d)
a = 0
}
time.Sleep(d)
a++
continue
}
// reset a
a = 0
// watch for events
if err := c.watch(w); err != nil {
if c.quit() {
return
}
d := backoff(b)
if b > 3 {
log.Log("rcache: ", err, " backing off ", d)
b = 0
}
time.Sleep(d)
b++
continue
}
// reset b
b = 0
}
}
|
[
"func",
"(",
"c",
"*",
"cache",
")",
"run",
"(",
"service",
"string",
")",
"{",
"// set watcher",
"c",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"watched",
"[",
"service",
"]",
"=",
"true",
"\n",
"c",
".",
"Unlock",
"(",
")",
"\n\n",
"// delete watcher on exit",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"c",
".",
"watched",
",",
"service",
")",
"\n",
"c",
".",
"Unlock",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"a",
",",
"b",
"int",
"\n\n",
"for",
"{",
"// exit early if already dead",
"if",
"c",
".",
"quit",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// jitter before starting",
"j",
":=",
"rand",
".",
"Int63n",
"(",
"100",
")",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"j",
")",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"// create new watcher",
"w",
",",
"err",
":=",
"c",
".",
"Registry",
".",
"Watch",
"(",
"registry",
".",
"WatchService",
"(",
"service",
")",
",",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"c",
".",
"quit",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"d",
":=",
"backoff",
"(",
"a",
")",
"\n\n",
"if",
"a",
">",
"3",
"{",
"log",
".",
"Log",
"(",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"d",
")",
"\n",
"a",
"=",
"0",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"d",
")",
"\n",
"a",
"++",
"\n\n",
"continue",
"\n",
"}",
"\n\n",
"// reset a",
"a",
"=",
"0",
"\n\n",
"// watch for events",
"if",
"err",
":=",
"c",
".",
"watch",
"(",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"c",
".",
"quit",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"d",
":=",
"backoff",
"(",
"b",
")",
"\n\n",
"if",
"b",
">",
"3",
"{",
"log",
".",
"Log",
"(",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"d",
")",
"\n",
"b",
"=",
"0",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"d",
")",
"\n",
"b",
"++",
"\n\n",
"continue",
"\n",
"}",
"\n\n",
"// reset b",
"b",
"=",
"0",
"\n",
"}",
"\n",
"}"
] |
// run starts the cache watcher loop
// it creates a new watcher if there's a problem
|
[
"run",
"starts",
"the",
"cache",
"watcher",
"loop",
"it",
"creates",
"a",
"new",
"watcher",
"if",
"there",
"s",
"a",
"problem"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/rcache.go#L284-L357
|
17,297 |
micro/go-rcache
|
rcache.go
|
watch
|
func (c *cache) watch(w registry.Watcher) error {
defer w.Stop()
// manage this loop
go func() {
// wait for exit
<-c.exit
w.Stop()
}()
for {
res, err := w.Next()
if err != nil {
return err
}
c.update(res)
}
}
|
go
|
func (c *cache) watch(w registry.Watcher) error {
defer w.Stop()
// manage this loop
go func() {
// wait for exit
<-c.exit
w.Stop()
}()
for {
res, err := w.Next()
if err != nil {
return err
}
c.update(res)
}
}
|
[
"func",
"(",
"c",
"*",
"cache",
")",
"watch",
"(",
"w",
"registry",
".",
"Watcher",
")",
"error",
"{",
"defer",
"w",
".",
"Stop",
"(",
")",
"\n\n",
"// manage this loop",
"go",
"func",
"(",
")",
"{",
"// wait for exit",
"<-",
"c",
".",
"exit",
"\n",
"w",
".",
"Stop",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"for",
"{",
"res",
",",
"err",
":=",
"w",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"update",
"(",
"res",
")",
"\n",
"}",
"\n",
"}"
] |
// watch loops the next event and calls update
// it returns if there's an error
|
[
"watch",
"loops",
"the",
"next",
"event",
"and",
"calls",
"update",
"it",
"returns",
"if",
"there",
"s",
"an",
"error"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/rcache.go#L361-L378
|
17,298 |
micro/go-rcache
|
rcache.go
|
New
|
func New(r registry.Registry, opts ...Option) Cache {
rand.Seed(time.Now().UnixNano())
options := Options{
TTL: DefaultTTL,
}
for _, o := range opts {
o(&options)
}
return &cache{
Registry: r,
opts: options,
watched: make(map[string]bool),
cache: make(map[string][]*registry.Service),
ttls: make(map[string]time.Time),
exit: make(chan bool),
}
}
|
go
|
func New(r registry.Registry, opts ...Option) Cache {
rand.Seed(time.Now().UnixNano())
options := Options{
TTL: DefaultTTL,
}
for _, o := range opts {
o(&options)
}
return &cache{
Registry: r,
opts: options,
watched: make(map[string]bool),
cache: make(map[string][]*registry.Service),
ttls: make(map[string]time.Time),
exit: make(chan bool),
}
}
|
[
"func",
"New",
"(",
"r",
"registry",
".",
"Registry",
",",
"opts",
"...",
"Option",
")",
"Cache",
"{",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"\n",
"options",
":=",
"Options",
"{",
"TTL",
":",
"DefaultTTL",
",",
"}",
"\n\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"o",
"(",
"&",
"options",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"cache",
"{",
"Registry",
":",
"r",
",",
"opts",
":",
"options",
",",
"watched",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"cache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"registry",
".",
"Service",
")",
",",
"ttls",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"time",
".",
"Time",
")",
",",
"exit",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"}",
"\n",
"}"
] |
// New returns a new cache
|
[
"New",
"returns",
"a",
"new",
"cache"
] |
2c4d7ce6742999be1708c70a3638f2c0ce28f2cd
|
https://github.com/micro/go-rcache/blob/2c4d7ce6742999be1708c70a3638f2c0ce28f2cd/rcache.go#L410-L428
|
17,299 |
cloudfoundry-community/go-cfclient
|
appevents.go
|
ListAppEvents
|
func (c *Client) ListAppEvents(eventType string) ([]AppEventEntity, error) {
return c.ListAppEventsByQuery(eventType, nil)
}
|
go
|
func (c *Client) ListAppEvents(eventType string) ([]AppEventEntity, error) {
return c.ListAppEventsByQuery(eventType, nil)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ListAppEvents",
"(",
"eventType",
"string",
")",
"(",
"[",
"]",
"AppEventEntity",
",",
"error",
")",
"{",
"return",
"c",
".",
"ListAppEventsByQuery",
"(",
"eventType",
",",
"nil",
")",
"\n",
"}"
] |
// ListAppEvents returns all app events based on eventType
|
[
"ListAppEvents",
"returns",
"all",
"app",
"events",
"based",
"on",
"eventType"
] |
f136f9222381e2fea5099f62e4b751dcb660ff82
|
https://github.com/cloudfoundry-community/go-cfclient/blob/f136f9222381e2fea5099f62e4b751dcb660ff82/appevents.go#L110-L112
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.