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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9,800 | domainr/whois | response.go | ReadMIMEFile | func ReadMIMEFile(path string) (*Response, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return ReadMIME(f)
} | go | func ReadMIMEFile(path string) (*Response, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return ReadMIME(f)
} | [
"func",
"ReadMIMEFile",
"(",
"path",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"de... | // ReadMIMEFile opens and reads a response MIME file at path.
// Returns any errors. | [
"ReadMIMEFile",
"opens",
"and",
"reads",
"a",
"response",
"MIME",
"file",
"at",
"path",
".",
"Returns",
"any",
"errors",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L211-L218 |
9,801 | domainr/whois | request.go | NewRequest | func NewRequest(query string) (*Request, error) {
req := &Request{Query: query}
if err := req.Prepare(); err != nil {
return nil, err
}
return req, nil
} | go | func NewRequest(query string) (*Request, error) {
req := &Request{Query: query}
if err := req.Prepare(); err != nil {
return nil, err
}
return req, nil
} | [
"func",
"NewRequest",
"(",
"query",
"string",
")",
"(",
"*",
"Request",
",",
"error",
")",
"{",
"req",
":=",
"&",
"Request",
"{",
"Query",
":",
"query",
"}",
"\n",
"if",
"err",
":=",
"req",
".",
"Prepare",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // NewRequest returns a prepared Request ready to fetch.
// On error, returns a nil Request and the error. | [
"NewRequest",
"returns",
"a",
"prepared",
"Request",
"ready",
"to",
"fetch",
".",
"On",
"error",
"returns",
"a",
"nil",
"Request",
"and",
"the",
"error",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/request.go#L18-L24 |
9,802 | domainr/whois | request.go | Prepare | func (req *Request) Prepare() error {
var err error
if req.Host == "" {
if req.Host, req.URL, err = Server(req.Query); err != nil {
return err
}
}
return req.Adapter().Prepare(req)
} | go | func (req *Request) Prepare() error {
var err error
if req.Host == "" {
if req.Host, req.URL, err = Server(req.Query); err != nil {
return err
}
}
return req.Adapter().Prepare(req)
} | [
"func",
"(",
"req",
"*",
"Request",
")",
"Prepare",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"req",
".",
"Host",
"==",
"\"",
"\"",
"{",
"if",
"req",
".",
"Host",
",",
"req",
".",
"URL",
",",
"err",
"=",
"Server",
"(",
"req",
... | // Prepare prepares a Request with an appropriate Adapter.
// First resolves whois server in req.Host if not already set.
// Returns any errors. | [
"Prepare",
"prepares",
"a",
"Request",
"with",
"an",
"appropriate",
"Adapter",
".",
"First",
"resolves",
"whois",
"server",
"in",
"req",
".",
"Host",
"if",
"not",
"already",
"set",
".",
"Returns",
"any",
"errors",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/request.go#L29-L37 |
9,803 | domainr/whois | whois.go | Fetch | func Fetch(query string) (*Response, error) {
req, err := NewRequest(query)
if err != nil {
return nil, err
}
return DefaultClient.Fetch(req)
} | go | func Fetch(query string) (*Response, error) {
req, err := NewRequest(query)
if err != nil {
return nil, err
}
return DefaultClient.Fetch(req)
} | [
"func",
"Fetch",
"(",
"query",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"NewRequest",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"De... | // Fetch queries a whois server and returns a Response. | [
"Fetch",
"queries",
"a",
"whois",
"server",
"and",
"returns",
"a",
"Response",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/whois.go#L12-L18 |
9,804 | domainr/whois | whois.go | Server | func Server(query string) (string, string, error) {
// Queries on TLDs always against IANA
if strings.Index(query, ".") < 0 {
return IANA, "", nil
}
z := zonedb.PublicZone(query)
if z == nil {
return "", "", fmt.Errorf("no public zone found for %s", query)
}
host := z.WhoisServer()
wu := z.WhoisURL()
if host != "" {
return host, wu, nil
}
u, err := url.Parse(wu)
if err == nil && u.Host != "" {
return u.Host, wu, nil
}
return "", "", fmt.Errorf("no whois server found for %s", query)
} | go | func Server(query string) (string, string, error) {
// Queries on TLDs always against IANA
if strings.Index(query, ".") < 0 {
return IANA, "", nil
}
z := zonedb.PublicZone(query)
if z == nil {
return "", "", fmt.Errorf("no public zone found for %s", query)
}
host := z.WhoisServer()
wu := z.WhoisURL()
if host != "" {
return host, wu, nil
}
u, err := url.Parse(wu)
if err == nil && u.Host != "" {
return u.Host, wu, nil
}
return "", "", fmt.Errorf("no whois server found for %s", query)
} | [
"func",
"Server",
"(",
"query",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"// Queries on TLDs always against IANA",
"if",
"strings",
".",
"Index",
"(",
"query",
",",
"\"",
"\"",
")",
"<",
"0",
"{",
"return",
"IANA",
",",
"\"",
... | // Server returns the whois server and optional URL for a given query.
// Returns an error if it cannot resolve query to any known host. | [
"Server",
"returns",
"the",
"whois",
"server",
"and",
"optional",
"URL",
"for",
"a",
"given",
"query",
".",
"Returns",
"an",
"error",
"if",
"it",
"cannot",
"resolve",
"query",
"to",
"any",
"known",
"host",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/whois.go#L22-L41 |
9,805 | domainr/whois | client.go | Fetch | func (c *Client) Fetch(req *Request) (*Response, error) {
return c.FetchContext(context.Background(), req)
} | go | func (c *Client) Fetch(req *Request) (*Response, error) {
return c.FetchContext(context.Background(), req)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Fetch",
"(",
"req",
"*",
"Request",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"return",
"c",
".",
"FetchContext",
"(",
"context",
".",
"Background",
"(",
")",
",",
"req",
")",
"\n",
"}"
] | // Fetch sends the Request to a whois server. | [
"Fetch",
"sends",
"the",
"Request",
"to",
"a",
"whois",
"server",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/client.go#L77-L79 |
9,806 | domainr/whois | client.go | FetchContext | func (c *Client) FetchContext(ctx context.Context, req *Request) (*Response, error) {
if c.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, c.Timeout)
defer cancel()
}
if req.URL != "" {
return c.fetchHTTP(ctx, req)
}
return c.fetchWhois(ctx, req)
} | go | func (c *Client) FetchContext(ctx context.Context, req *Request) (*Response, error) {
if c.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, c.Timeout)
defer cancel()
}
if req.URL != "" {
return c.fetchHTTP(ctx, req)
}
return c.fetchWhois(ctx, req)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"FetchContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"Request",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"if",
"c",
".",
"Timeout",
">",
"0",
"{",
"var",
"cancel",
"context",
".",
... | // FetchContext sends the Request to a whois server.
// If ctx cancels or times out before the request completes, it will return an error. | [
"FetchContext",
"sends",
"the",
"Request",
"to",
"a",
"whois",
"server",
".",
"If",
"ctx",
"cancels",
"or",
"times",
"out",
"before",
"the",
"request",
"completes",
"it",
"will",
"return",
"an",
"error",
"."
] | 975c7833b02e9b09b05f41cb5650339b4e913467 | https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/client.go#L83-L93 |
9,807 | sarulabs/di | scope.go | Copy | func (l ScopeList) Copy() ScopeList {
scopes := make(ScopeList, len(l))
copy(scopes, l)
return scopes
} | go | func (l ScopeList) Copy() ScopeList {
scopes := make(ScopeList, len(l))
copy(scopes, l)
return scopes
} | [
"func",
"(",
"l",
"ScopeList",
")",
"Copy",
"(",
")",
"ScopeList",
"{",
"scopes",
":=",
"make",
"(",
"ScopeList",
",",
"len",
"(",
"l",
")",
")",
"\n",
"copy",
"(",
"scopes",
",",
"l",
")",
"\n",
"return",
"scopes",
"\n",
"}"
] | // Copy returns a copy of the ScopeList. | [
"Copy",
"returns",
"a",
"copy",
"of",
"the",
"ScopeList",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/scope.go#L16-L20 |
9,808 | sarulabs/di | scope.go | ParentScopes | func (l ScopeList) ParentScopes(scope string) ScopeList {
scopes := l.Copy()
for i, s := range scopes {
if s == scope {
return scopes[:i]
}
}
return ScopeList{}
} | go | func (l ScopeList) ParentScopes(scope string) ScopeList {
scopes := l.Copy()
for i, s := range scopes {
if s == scope {
return scopes[:i]
}
}
return ScopeList{}
} | [
"func",
"(",
"l",
"ScopeList",
")",
"ParentScopes",
"(",
"scope",
"string",
")",
"ScopeList",
"{",
"scopes",
":=",
"l",
".",
"Copy",
"(",
")",
"\n\n",
"for",
"i",
",",
"s",
":=",
"range",
"scopes",
"{",
"if",
"s",
"==",
"scope",
"{",
"return",
"sco... | // ParentScopes returns the scopes before the one given as parameter. | [
"ParentScopes",
"returns",
"the",
"scopes",
"before",
"the",
"one",
"given",
"as",
"parameter",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/scope.go#L23-L33 |
9,809 | sarulabs/di | scope.go | Contains | func (l ScopeList) Contains(scope string) bool {
for _, s := range l {
if scope == s {
return true
}
}
return false
} | go | func (l ScopeList) Contains(scope string) bool {
for _, s := range l {
if scope == s {
return true
}
}
return false
} | [
"func",
"(",
"l",
"ScopeList",
")",
"Contains",
"(",
"scope",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"l",
"{",
"if",
"scope",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Contains returns true if the ScopeList contains the given scope. | [
"Contains",
"returns",
"true",
"if",
"the",
"ScopeList",
"contains",
"the",
"given",
"scope",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/scope.go#L49-L57 |
9,810 | sarulabs/di | definition.go | Copy | func (m DefMap) Copy() DefMap {
defs := DefMap{}
for name, def := range m {
defs[name] = def
}
return defs
} | go | func (m DefMap) Copy() DefMap {
defs := DefMap{}
for name, def := range m {
defs[name] = def
}
return defs
} | [
"func",
"(",
"m",
"DefMap",
")",
"Copy",
"(",
")",
"DefMap",
"{",
"defs",
":=",
"DefMap",
"{",
"}",
"\n\n",
"for",
"name",
",",
"def",
":=",
"range",
"m",
"{",
"defs",
"[",
"name",
"]",
"=",
"def",
"\n",
"}",
"\n\n",
"return",
"defs",
"\n",
"}"... | // Copy returns a copy of the DefMap. | [
"Copy",
"returns",
"a",
"copy",
"of",
"the",
"DefMap",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/definition.go#L23-L31 |
9,811 | sarulabs/di | utils.go | Add | func (l builtList) Add(name string) builtList {
if l == nil {
return builtList{name: 0}
}
l[name] = len(l)
return l
} | go | func (l builtList) Add(name string) builtList {
if l == nil {
return builtList{name: 0}
}
l[name] = len(l)
return l
} | [
"func",
"(",
"l",
"builtList",
")",
"Add",
"(",
"name",
"string",
")",
"builtList",
"{",
"if",
"l",
"==",
"nil",
"{",
"return",
"builtList",
"{",
"name",
":",
"0",
"}",
"\n",
"}",
"\n",
"l",
"[",
"name",
"]",
"=",
"len",
"(",
"l",
")",
"\n",
... | // Add adds an element in the map. | [
"Add",
"adds",
"an",
"element",
"in",
"the",
"map",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L18-L24 |
9,812 | sarulabs/di | utils.go | Has | func (l builtList) Has(name string) bool {
_, ok := l[name]
return ok
} | go | func (l builtList) Has(name string) bool {
_, ok := l[name]
return ok
} | [
"func",
"(",
"l",
"builtList",
")",
"Has",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"l",
"[",
"name",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // Has checks if the map contains the given element. | [
"Has",
"checks",
"if",
"the",
"map",
"contains",
"the",
"given",
"element",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L27-L30 |
9,813 | sarulabs/di | utils.go | OrderedList | func (l builtList) OrderedList() []string {
s := make([]string, len(l))
for name, i := range l {
s[i] = name
}
return s
} | go | func (l builtList) OrderedList() []string {
s := make([]string, len(l))
for name, i := range l {
s[i] = name
}
return s
} | [
"func",
"(",
"l",
"builtList",
")",
"OrderedList",
"(",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"l",
")",
")",
"\n\n",
"for",
"name",
",",
"i",
":=",
"range",
"l",
"{",
"s",
"[",
"i",
"]",
... | // OrderedList returns the list of elements in the order
// they were inserted. | [
"OrderedList",
"returns",
"the",
"list",
"of",
"elements",
"in",
"the",
"order",
"they",
"were",
"inserted",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L34-L42 |
9,814 | sarulabs/di | utils.go | Add | func (b *multiErrBuilder) Add(err error) {
if err != nil {
b.errs = append(b.errs, err)
}
} | go | func (b *multiErrBuilder) Add(err error) {
if err != nil {
b.errs = append(b.errs, err)
}
} | [
"func",
"(",
"b",
"*",
"multiErrBuilder",
")",
"Add",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"b",
".",
"errs",
"=",
"append",
"(",
"b",
".",
"errs",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // Add adds an error in the multiErrBuilder. | [
"Add",
"adds",
"an",
"error",
"in",
"the",
"multiErrBuilder",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L50-L54 |
9,815 | sarulabs/di | utils.go | Build | func (b *multiErrBuilder) Build() error {
if len(b.errs) == 0 {
return nil
}
msgs := make([]string, len(b.errs))
for i, err := range b.errs {
msgs[i] = err.Error()
}
return errors.New(strings.Join(msgs, " AND "))
} | go | func (b *multiErrBuilder) Build() error {
if len(b.errs) == 0 {
return nil
}
msgs := make([]string, len(b.errs))
for i, err := range b.errs {
msgs[i] = err.Error()
}
return errors.New(strings.Join(msgs, " AND "))
} | [
"func",
"(",
"b",
"*",
"multiErrBuilder",
")",
"Build",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"b",
".",
"errs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"msgs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"b",
... | // Build returns an errors containing all the messages
// of the accumulated errors. If there is no error
// in the builder, it returns nil. | [
"Build",
"returns",
"an",
"errors",
"containing",
"all",
"the",
"messages",
"of",
"the",
"accumulated",
"errors",
".",
"If",
"there",
"is",
"no",
"error",
"in",
"the",
"builder",
"it",
"returns",
"nil",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L59-L71 |
9,816 | sarulabs/di | utils.go | fill | func fill(src, dest interface{}) (err error) {
defer func() {
if r := recover(); r != nil {
d := reflect.TypeOf(dest)
s := reflect.TypeOf(src)
err = fmt.Errorf("the fill destination should be a pointer to a `%s`, but you used a `%s`", s, d)
}
}()
reflect.ValueOf(dest).Elem().Set(reflect.ValueOf(src))
return err
} | go | func fill(src, dest interface{}) (err error) {
defer func() {
if r := recover(); r != nil {
d := reflect.TypeOf(dest)
s := reflect.TypeOf(src)
err = fmt.Errorf("the fill destination should be a pointer to a `%s`, but you used a `%s`", s, d)
}
}()
reflect.ValueOf(dest).Elem().Set(reflect.ValueOf(src))
return err
} | [
"func",
"fill",
"(",
"src",
",",
"dest",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"d",
":=",
"reflect",
".",
"TypeOf",
"(",
"d... | // fill copies src in dest. dest should be a pointer to src type. | [
"fill",
"copies",
"src",
"in",
"dest",
".",
"dest",
"should",
"be",
"a",
"pointer",
"to",
"src",
"type",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/utils.go#L74-L86 |
9,817 | sarulabs/di | builder.go | IsDefined | func (b *Builder) IsDefined(name string) bool {
_, ok := b.definitions[name]
return ok
} | go | func (b *Builder) IsDefined(name string) bool {
_, ok := b.definitions[name]
return ok
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"IsDefined",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"b",
".",
"definitions",
"[",
"name",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // IsDefined returns true if there is a definition with the given name. | [
"IsDefined",
"returns",
"true",
"if",
"there",
"is",
"a",
"definition",
"with",
"the",
"given",
"name",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/builder.go#L68-L71 |
9,818 | sarulabs/di | builder.go | Add | func (b *Builder) Add(defs ...Def) error {
for _, def := range defs {
if err := b.add(def); err != nil {
return err
}
}
return nil
} | go | func (b *Builder) Add(defs ...Def) error {
for _, def := range defs {
if err := b.add(def); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Add",
"(",
"defs",
"...",
"Def",
")",
"error",
"{",
"for",
"_",
",",
"def",
":=",
"range",
"defs",
"{",
"if",
"err",
":=",
"b",
".",
"add",
"(",
"def",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err"... | // Add adds one or more definitions in the Builder.
// It returns an error if a definition can not be added. | [
"Add",
"adds",
"one",
"or",
"more",
"definitions",
"in",
"the",
"Builder",
".",
"It",
"returns",
"an",
"error",
"if",
"a",
"definition",
"can",
"not",
"be",
"added",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/builder.go#L75-L83 |
9,819 | sarulabs/di | builder.go | Build | func (b *Builder) Build() Container {
if err := checkScopes(b.scopes); err != nil {
return nil
}
defs := b.Definitions()
for name, def := range defs {
if def.Scope == "" {
def.Scope = b.scopes[0]
defs[name] = def
}
}
return &container{
containerCore: &containerCore{
scopes: b.scopes,
scope: b.scopes[0],
definitions: defs,
parent: nil,
children: map[*containerCore]struct{}{},
objects: map[string]interface{}{},
},
}
} | go | func (b *Builder) Build() Container {
if err := checkScopes(b.scopes); err != nil {
return nil
}
defs := b.Definitions()
for name, def := range defs {
if def.Scope == "" {
def.Scope = b.scopes[0]
defs[name] = def
}
}
return &container{
containerCore: &containerCore{
scopes: b.scopes,
scope: b.scopes[0],
definitions: defs,
parent: nil,
children: map[*containerCore]struct{}{},
objects: map[string]interface{}{},
},
}
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Build",
"(",
")",
"Container",
"{",
"if",
"err",
":=",
"checkScopes",
"(",
"b",
".",
"scopes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"defs",
":=",
"b",
".",
"Definitions",
"... | // Build creates a Container in the most generic scope
// with all the definitions registered in the Builder. | [
"Build",
"creates",
"a",
"Container",
"in",
"the",
"most",
"generic",
"scope",
"with",
"all",
"the",
"definitions",
"registered",
"in",
"the",
"Builder",
"."
] | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/builder.go#L119-L143 |
9,820 | sarulabs/di | http.go | HTTPMiddleware | func HTTPMiddleware(h http.HandlerFunc, app Container, logFunc func(msg string)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// create a request container from tha app container
ctn, err := app.SubContainer()
if err != nil {
panic(err)
}
defer func() {
if err := ctn.Delete(); err != nil && logFunc != nil {
logFunc(err.Error())
}
}()
// call the handler with a new request
// containing the container in its context
h(w, r.WithContext(
context.WithValue(r.Context(), ContainerKey("di"), ctn),
))
}
} | go | func HTTPMiddleware(h http.HandlerFunc, app Container, logFunc func(msg string)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// create a request container from tha app container
ctn, err := app.SubContainer()
if err != nil {
panic(err)
}
defer func() {
if err := ctn.Delete(); err != nil && logFunc != nil {
logFunc(err.Error())
}
}()
// call the handler with a new request
// containing the container in its context
h(w, r.WithContext(
context.WithValue(r.Context(), ContainerKey("di"), ctn),
))
}
} | [
"func",
"HTTPMiddleware",
"(",
"h",
"http",
".",
"HandlerFunc",
",",
"app",
"Container",
",",
"logFunc",
"func",
"(",
"msg",
"string",
")",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
... | // HTTPMiddleware adds a container in the request context.
//
// The container injected in each request, is a new sub-container
// of the app container given as parameter.
//
// It can panic, so it should be used with another middleware
// to recover from the panic, and to log the error.
//
// It uses logFunc, a function that can log an error.
// logFunc is used to log the errors during the container deletion. | [
"HTTPMiddleware",
"adds",
"a",
"container",
"in",
"the",
"request",
"context",
".",
"The",
"container",
"injected",
"in",
"each",
"request",
"is",
"a",
"new",
"sub",
"-",
"container",
"of",
"the",
"app",
"container",
"given",
"as",
"parameter",
".",
"It",
... | 20b162abade70d47e85fe67047e40a56c8c6b3a9 | https://github.com/sarulabs/di/blob/20b162abade70d47e85fe67047e40a56c8c6b3a9/http.go#L23-L42 |
9,821 | o1egl/paseto | parser.go | ParseFooter | func ParseFooter(token string, footer interface{}) error {
parts := strings.Split(token, ".")
if len(parts) == 4 {
b, err := tokenEncoder.DecodeString(parts[3])
if err != nil {
return errors.Wrap(err, "failed to decode token")
}
return errors.Wrap(fillValue(b, footer), "failed to decode footer")
}
if len(parts) < 3 {
return ErrIncorrectTokenFormat
}
return nil
} | go | func ParseFooter(token string, footer interface{}) error {
parts := strings.Split(token, ".")
if len(parts) == 4 {
b, err := tokenEncoder.DecodeString(parts[3])
if err != nil {
return errors.Wrap(err, "failed to decode token")
}
return errors.Wrap(fillValue(b, footer), "failed to decode footer")
}
if len(parts) < 3 {
return ErrIncorrectTokenFormat
}
return nil
} | [
"func",
"ParseFooter",
"(",
"token",
"string",
",",
"footer",
"interface",
"{",
"}",
")",
"error",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"token",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"4",
"{",
"b",
",",
"e... | // ParseFooter parses the footer from the token and returns it. | [
"ParseFooter",
"parses",
"the",
"footer",
"from",
"the",
"token",
"and",
"returns",
"it",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/parser.go#L71-L84 |
9,822 | o1egl/paseto | token_validator.go | ForAudience | func ForAudience(audience string) Validator {
return func(token *JSONToken) error {
if token.Audience != audience {
return errors.Wrapf(ErrTokenValidationError, `token was not intended for "%s" audience`, audience)
}
return nil
}
} | go | func ForAudience(audience string) Validator {
return func(token *JSONToken) error {
if token.Audience != audience {
return errors.Wrapf(ErrTokenValidationError, `token was not intended for "%s" audience`, audience)
}
return nil
}
} | [
"func",
"ForAudience",
"(",
"audience",
"string",
")",
"Validator",
"{",
"return",
"func",
"(",
"token",
"*",
"JSONToken",
")",
"error",
"{",
"if",
"token",
".",
"Audience",
"!=",
"audience",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"ErrTokenValidationErr... | // ForAudience validates that the JSONToken audience has the specified value. | [
"ForAudience",
"validates",
"that",
"the",
"JSONToken",
"audience",
"has",
"the",
"specified",
"value",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/token_validator.go#L13-L20 |
9,823 | o1egl/paseto | token_validator.go | IdentifiedBy | func IdentifiedBy(jti string) Validator {
return func(token *JSONToken) error {
if token.Jti != jti {
return errors.Wrapf(ErrTokenValidationError, `token was expected to be identified by "%s"`, jti)
}
return nil
}
} | go | func IdentifiedBy(jti string) Validator {
return func(token *JSONToken) error {
if token.Jti != jti {
return errors.Wrapf(ErrTokenValidationError, `token was expected to be identified by "%s"`, jti)
}
return nil
}
} | [
"func",
"IdentifiedBy",
"(",
"jti",
"string",
")",
"Validator",
"{",
"return",
"func",
"(",
"token",
"*",
"JSONToken",
")",
"error",
"{",
"if",
"token",
".",
"Jti",
"!=",
"jti",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"ErrTokenValidationError",
",",
... | // IdentifiedBy validates that the JSONToken JTI has the specified value. | [
"IdentifiedBy",
"validates",
"that",
"the",
"JSONToken",
"JTI",
"has",
"the",
"specified",
"value",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/token_validator.go#L23-L30 |
9,824 | o1egl/paseto | token_validator.go | IssuedBy | func IssuedBy(issuer string) Validator {
return func(token *JSONToken) error {
if token.Issuer != issuer {
return errors.Wrapf(ErrTokenValidationError, `token was not issued by "%s"`, issuer)
}
return nil
}
} | go | func IssuedBy(issuer string) Validator {
return func(token *JSONToken) error {
if token.Issuer != issuer {
return errors.Wrapf(ErrTokenValidationError, `token was not issued by "%s"`, issuer)
}
return nil
}
} | [
"func",
"IssuedBy",
"(",
"issuer",
"string",
")",
"Validator",
"{",
"return",
"func",
"(",
"token",
"*",
"JSONToken",
")",
"error",
"{",
"if",
"token",
".",
"Issuer",
"!=",
"issuer",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"ErrTokenValidationError",
",... | // IssuedBy validates that the JSONToken issuer has the specified value. | [
"IssuedBy",
"validates",
"that",
"the",
"JSONToken",
"issuer",
"has",
"the",
"specified",
"value",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/token_validator.go#L33-L40 |
9,825 | o1egl/paseto | token_validator.go | Subject | func Subject(subject string) Validator {
return func(token *JSONToken) error {
if token.Subject != subject {
return errors.Wrapf(ErrTokenValidationError, `token was not related to subject "%s"`, subject)
}
return nil
}
} | go | func Subject(subject string) Validator {
return func(token *JSONToken) error {
if token.Subject != subject {
return errors.Wrapf(ErrTokenValidationError, `token was not related to subject "%s"`, subject)
}
return nil
}
} | [
"func",
"Subject",
"(",
"subject",
"string",
")",
"Validator",
"{",
"return",
"func",
"(",
"token",
"*",
"JSONToken",
")",
"error",
"{",
"if",
"token",
".",
"Subject",
"!=",
"subject",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"ErrTokenValidationError",
... | // Subject validates that the JSONToken subject has the specified value. | [
"Subject",
"validates",
"that",
"the",
"JSONToken",
"subject",
"has",
"the",
"specified",
"value",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/token_validator.go#L43-L50 |
9,826 | o1egl/paseto | token_validator.go | ValidAt | func ValidAt(t time.Time) Validator {
return func(token *JSONToken) error {
if !token.IssuedAt.IsZero() && t.Before(token.IssuedAt) {
return errors.Wrapf(ErrTokenValidationError, "token was issued in the future")
}
if !token.NotBefore.IsZero() && t.Before(token.NotBefore) {
return errors.Wrapf(ErrTokenValidationError, "token cannot be used yet")
}
if !token.Expiration.IsZero() && t.After(token.Expiration) {
return errors.Wrapf(ErrTokenValidationError, "token has expired")
}
return nil
}
} | go | func ValidAt(t time.Time) Validator {
return func(token *JSONToken) error {
if !token.IssuedAt.IsZero() && t.Before(token.IssuedAt) {
return errors.Wrapf(ErrTokenValidationError, "token was issued in the future")
}
if !token.NotBefore.IsZero() && t.Before(token.NotBefore) {
return errors.Wrapf(ErrTokenValidationError, "token cannot be used yet")
}
if !token.Expiration.IsZero() && t.After(token.Expiration) {
return errors.Wrapf(ErrTokenValidationError, "token has expired")
}
return nil
}
} | [
"func",
"ValidAt",
"(",
"t",
"time",
".",
"Time",
")",
"Validator",
"{",
"return",
"func",
"(",
"token",
"*",
"JSONToken",
")",
"error",
"{",
"if",
"!",
"token",
".",
"IssuedAt",
".",
"IsZero",
"(",
")",
"&&",
"t",
".",
"Before",
"(",
"token",
".",... | // ValidAt validates whether the token is valid at the specified time, based on
// the values of the IssuedAt, NotBefore and Expiration claims in the token. | [
"ValidAt",
"validates",
"whether",
"the",
"token",
"is",
"valid",
"at",
"the",
"specified",
"time",
"based",
"on",
"the",
"values",
"of",
"the",
"IssuedAt",
"NotBefore",
"and",
"Expiration",
"claims",
"in",
"the",
"token",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/token_validator.go#L54-L67 |
9,827 | o1egl/paseto | v2.go | Sign | func (*V2) Sign(privateKey crypto.PrivateKey, payload interface{}, footer interface{}) (string, error) {
key, ok := privateKey.(ed25519.PrivateKey)
if !ok {
return "", ErrIncorrectPrivateKeyType
}
payloadBytes, err := infToByteArr(payload)
if err != nil {
return "", errors.Wrap(err, "failed to encode payload to []byte")
}
footerBytes, err := infToByteArr(footer)
if err != nil {
return "", errors.Wrap(err, "failed to encode footer to []byte")
}
sig := ed25519.Sign(key, preAuthEncode(headerV2Public, payloadBytes, footerBytes))
return createToken(headerV2Public, append(payloadBytes, sig...), footerBytes), nil
} | go | func (*V2) Sign(privateKey crypto.PrivateKey, payload interface{}, footer interface{}) (string, error) {
key, ok := privateKey.(ed25519.PrivateKey)
if !ok {
return "", ErrIncorrectPrivateKeyType
}
payloadBytes, err := infToByteArr(payload)
if err != nil {
return "", errors.Wrap(err, "failed to encode payload to []byte")
}
footerBytes, err := infToByteArr(footer)
if err != nil {
return "", errors.Wrap(err, "failed to encode footer to []byte")
}
sig := ed25519.Sign(key, preAuthEncode(headerV2Public, payloadBytes, footerBytes))
return createToken(headerV2Public, append(payloadBytes, sig...), footerBytes), nil
} | [
"func",
"(",
"*",
"V2",
")",
"Sign",
"(",
"privateKey",
"crypto",
".",
"PrivateKey",
",",
"payload",
"interface",
"{",
"}",
",",
"footer",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"key",
",",
"ok",
":=",
"privateKey",
".",
... | // Sign implements Protocol.Sign | [
"Sign",
"implements",
"Protocol",
".",
"Sign"
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/v2.go#L115-L134 |
9,828 | o1egl/paseto | v2.go | Verify | func (*V2) Verify(token string, publicKey crypto.PublicKey, payload interface{}, footer interface{}) error {
pub, ok := publicKey.(ed25519.PublicKey)
if !ok {
return ErrIncorrectPublicKeyType
}
data, footerBytes, err := splitToken([]byte(token), headerV2Public)
if err != nil {
return errors.Wrap(err, "failed to decode token")
}
if len(data) < v2SignSize {
return errors.Wrap(ErrIncorrectTokenFormat, "incorrect token size")
}
payloadBytes := data[:len(data)-v2SignSize]
signature := data[len(data)-v2SignSize:]
if !ed25519.Verify(pub, preAuthEncode(headerV2Public, payloadBytes, footerBytes), signature) {
return ErrInvalidSignature
}
if payload != nil {
if err := fillValue(payloadBytes, payload); err != nil {
return errors.Wrap(err, "failed to decode payload")
}
}
if footer != nil {
if err := fillValue(footerBytes, footer); err != nil {
return errors.Wrap(err, "failed to decode footer")
}
}
return nil
} | go | func (*V2) Verify(token string, publicKey crypto.PublicKey, payload interface{}, footer interface{}) error {
pub, ok := publicKey.(ed25519.PublicKey)
if !ok {
return ErrIncorrectPublicKeyType
}
data, footerBytes, err := splitToken([]byte(token), headerV2Public)
if err != nil {
return errors.Wrap(err, "failed to decode token")
}
if len(data) < v2SignSize {
return errors.Wrap(ErrIncorrectTokenFormat, "incorrect token size")
}
payloadBytes := data[:len(data)-v2SignSize]
signature := data[len(data)-v2SignSize:]
if !ed25519.Verify(pub, preAuthEncode(headerV2Public, payloadBytes, footerBytes), signature) {
return ErrInvalidSignature
}
if payload != nil {
if err := fillValue(payloadBytes, payload); err != nil {
return errors.Wrap(err, "failed to decode payload")
}
}
if footer != nil {
if err := fillValue(footerBytes, footer); err != nil {
return errors.Wrap(err, "failed to decode footer")
}
}
return nil
} | [
"func",
"(",
"*",
"V2",
")",
"Verify",
"(",
"token",
"string",
",",
"publicKey",
"crypto",
".",
"PublicKey",
",",
"payload",
"interface",
"{",
"}",
",",
"footer",
"interface",
"{",
"}",
")",
"error",
"{",
"pub",
",",
"ok",
":=",
"publicKey",
".",
"("... | // Verify implements Protocol.Verify | [
"Verify",
"implements",
"Protocol",
".",
"Verify"
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/v2.go#L137-L172 |
9,829 | o1egl/paseto | json_token.go | Set | func (t *JSONToken) Set(key string, value string) {
if t.claims == nil {
t.claims = make(map[string]string)
}
t.claims[key] = value
} | go | func (t *JSONToken) Set(key string, value string) {
if t.claims == nil {
t.claims = make(map[string]string)
}
t.claims[key] = value
} | [
"func",
"(",
"t",
"*",
"JSONToken",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"string",
")",
"{",
"if",
"t",
".",
"claims",
"==",
"nil",
"{",
"t",
".",
"claims",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",... | // Set sets the value of a custom claim to the string value provided. | [
"Set",
"sets",
"the",
"value",
"of",
"a",
"custom",
"claim",
"to",
"the",
"string",
"value",
"provided",
"."
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/json_token.go#L43-L48 |
9,830 | o1egl/paseto | json_token.go | MarshalJSON | func (t JSONToken) MarshalJSON() ([]byte, error) {
if t.claims == nil {
t.claims = make(map[string]string)
}
if t.Audience != "" {
t.claims["aud"] = t.Audience
}
if t.Issuer != "" {
t.claims["iss"] = t.Issuer
}
if t.Jti != "" {
t.claims["jti"] = t.Jti
}
if t.Subject != "" {
t.claims["sub"] = t.Subject
}
if !t.Expiration.IsZero() {
t.claims["exp"] = t.Expiration.Format(time.RFC3339)
}
if !t.IssuedAt.IsZero() {
t.claims["iat"] = t.IssuedAt.Format(time.RFC3339)
}
if !t.NotBefore.IsZero() {
t.claims["nbf"] = t.NotBefore.Format(time.RFC3339)
}
return json.Marshal(t.claims)
} | go | func (t JSONToken) MarshalJSON() ([]byte, error) {
if t.claims == nil {
t.claims = make(map[string]string)
}
if t.Audience != "" {
t.claims["aud"] = t.Audience
}
if t.Issuer != "" {
t.claims["iss"] = t.Issuer
}
if t.Jti != "" {
t.claims["jti"] = t.Jti
}
if t.Subject != "" {
t.claims["sub"] = t.Subject
}
if !t.Expiration.IsZero() {
t.claims["exp"] = t.Expiration.Format(time.RFC3339)
}
if !t.IssuedAt.IsZero() {
t.claims["iat"] = t.IssuedAt.Format(time.RFC3339)
}
if !t.NotBefore.IsZero() {
t.claims["nbf"] = t.NotBefore.Format(time.RFC3339)
}
return json.Marshal(t.claims)
} | [
"func",
"(",
"t",
"JSONToken",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"t",
".",
"claims",
"==",
"nil",
"{",
"t",
".",
"claims",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
... | // MarshalJSON implements json.Marshaler interface | [
"MarshalJSON",
"implements",
"json",
".",
"Marshaler",
"interface"
] | 223ee0b022390c3bc4201998440f89515555d362 | https://github.com/o1egl/paseto/blob/223ee0b022390c3bc4201998440f89515555d362/json_token.go#L51-L78 |
9,831 | carlescere/scheduler | scheduler.go | NotImmediately | func (j *Job) NotImmediately() *Job {
rj, ok := j.schedule.(*recurrent)
if !ok {
j.err = errors.New("bad function chaining")
return j
}
rj.done = true
return j
} | go | func (j *Job) NotImmediately() *Job {
rj, ok := j.schedule.(*recurrent)
if !ok {
j.err = errors.New("bad function chaining")
return j
}
rj.done = true
return j
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"NotImmediately",
"(",
")",
"*",
"Job",
"{",
"rj",
",",
"ok",
":=",
"j",
".",
"schedule",
".",
"(",
"*",
"recurrent",
")",
"\n",
"if",
"!",
"ok",
"{",
"j",
".",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
... | // NotImmediately allows recurrent jobs not to be executed immediatelly after
// definition. If a job is declared hourly won't start executing until the first hour
// passed. | [
"NotImmediately",
"allows",
"recurrent",
"jobs",
"not",
"to",
"be",
"executed",
"immediatelly",
"after",
"definition",
".",
"If",
"a",
"job",
"is",
"declared",
"hourly",
"won",
"t",
"start",
"executing",
"until",
"the",
"first",
"hour",
"passed",
"."
] | ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5 | https://github.com/carlescere/scheduler/blob/ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5/scheduler.go#L119-L127 |
9,832 | carlescere/scheduler | scheduler.go | Run | func (j *Job) Run(f func()) (*Job, error) {
if j.err != nil {
return nil, j.err
}
var next time.Duration
var err error
j.Quit = make(chan bool, 1)
j.SkipWait = make(chan bool, 1)
j.fn = f
// Check for possible errors in scheduling
next, err = j.schedule.nextRun()
if err != nil {
return nil, err
}
go func(j *Job) {
for {
select {
case <-j.Quit:
return
case <-j.SkipWait:
go runJob(j)
case <-time.After(next):
go runJob(j)
}
next, _ = j.schedule.nextRun()
}
}(j)
return j, nil
} | go | func (j *Job) Run(f func()) (*Job, error) {
if j.err != nil {
return nil, j.err
}
var next time.Duration
var err error
j.Quit = make(chan bool, 1)
j.SkipWait = make(chan bool, 1)
j.fn = f
// Check for possible errors in scheduling
next, err = j.schedule.nextRun()
if err != nil {
return nil, err
}
go func(j *Job) {
for {
select {
case <-j.Quit:
return
case <-j.SkipWait:
go runJob(j)
case <-time.After(next):
go runJob(j)
}
next, _ = j.schedule.nextRun()
}
}(j)
return j, nil
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"Run",
"(",
"f",
"func",
"(",
")",
")",
"(",
"*",
"Job",
",",
"error",
")",
"{",
"if",
"j",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"j",
".",
"err",
"\n",
"}",
"\n",
"var",
"next",
"time",
".... | // Run sets the job to the schedule and returns the pointer to the job so it may be
// stopped or executed without waiting or an error. | [
"Run",
"sets",
"the",
"job",
"to",
"the",
"schedule",
"and",
"returns",
"the",
"pointer",
"to",
"the",
"job",
"so",
"it",
"may",
"be",
"stopped",
"or",
"executed",
"without",
"waiting",
"or",
"an",
"error",
"."
] | ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5 | https://github.com/carlescere/scheduler/blob/ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5/scheduler.go#L160-L188 |
9,833 | carlescere/scheduler | scheduler.go | Day | func (j *Job) Day() *Job {
if j.schedule != nil {
j.err = errors.New("bad function chaining")
}
j.schedule = daily{}
return j
} | go | func (j *Job) Day() *Job {
if j.schedule != nil {
j.err = errors.New("bad function chaining")
}
j.schedule = daily{}
return j
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"Day",
"(",
")",
"*",
"Job",
"{",
"if",
"j",
".",
"schedule",
"!=",
"nil",
"{",
"j",
".",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"j",
".",
"schedule",
"=",
"daily",
"{",
... | // Day sets the job to run every day. | [
"Day",
"sets",
"the",
"job",
"to",
"run",
"every",
"day",
"."
] | ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5 | https://github.com/carlescere/scheduler/blob/ee74d2f83d82cd1d2e92ed3ec3dbaf162ca5ece5/scheduler.go#L287-L293 |
9,834 | aerospike/aerospike-client-go | info.go | newInfo | func newInfo(conn *Connection, commands ...string) (*info, error) {
commandStr := strings.Trim(strings.Join(commands, "\n"), " ")
if strings.Trim(commandStr, " ") != "" {
commandStr += "\n"
}
newInfo := &info{
msg: NewMessage(MSG_INFO, []byte(commandStr)),
}
if err := newInfo.sendCommand(conn); err != nil {
return nil, err
}
return newInfo, nil
} | go | func newInfo(conn *Connection, commands ...string) (*info, error) {
commandStr := strings.Trim(strings.Join(commands, "\n"), " ")
if strings.Trim(commandStr, " ") != "" {
commandStr += "\n"
}
newInfo := &info{
msg: NewMessage(MSG_INFO, []byte(commandStr)),
}
if err := newInfo.sendCommand(conn); err != nil {
return nil, err
}
return newInfo, nil
} | [
"func",
"newInfo",
"(",
"conn",
"*",
"Connection",
",",
"commands",
"...",
"string",
")",
"(",
"*",
"info",
",",
"error",
")",
"{",
"commandStr",
":=",
"strings",
".",
"Trim",
"(",
"strings",
".",
"Join",
"(",
"commands",
",",
"\"",
"\\n",
"\"",
")",... | // Send multiple commands to server and store results.
// Timeout should already be set on the connection. | [
"Send",
"multiple",
"commands",
"to",
"server",
"and",
"store",
"results",
".",
"Timeout",
"should",
"already",
"be",
"set",
"on",
"the",
"connection",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/info.go#L39-L52 |
9,835 | aerospike/aerospike-client-go | info.go | RequestInfo | func RequestInfo(conn *Connection, names ...string) (map[string]string, error) {
info, err := newInfo(conn, names...)
if err != nil {
return nil, err
}
return info.parseMultiResponse()
} | go | func RequestInfo(conn *Connection, names ...string) (map[string]string, error) {
info, err := newInfo(conn, names...)
if err != nil {
return nil, err
}
return info.parseMultiResponse()
} | [
"func",
"RequestInfo",
"(",
"conn",
"*",
"Connection",
",",
"names",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"newInfo",
"(",
"conn",
",",
"names",
"...",
")",
"\n",
"if",
"er... | // RequestInfo gets info values by name from the specified connection.
// Timeout should already be set on the connection. | [
"RequestInfo",
"gets",
"info",
"values",
"by",
"name",
"from",
"the",
"specified",
"connection",
".",
"Timeout",
"should",
"already",
"be",
"set",
"on",
"the",
"connection",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/info.go#L56-L62 |
9,836 | aerospike/aerospike-client-go | info.go | sendCommand | func (nfo *info) sendCommand(conn *Connection) error {
// Write.
if _, err := conn.Write(nfo.msg.Serialize()); err != nil {
Logger.Debug("Failed to send command.")
return err
}
// Read - reuse input buffer.
header := bytes.NewBuffer(make([]byte, MSG_HEADER_SIZE))
if _, err := conn.Read(header.Bytes(), MSG_HEADER_SIZE); err != nil {
return err
}
if err := binary.Read(header, binary.BigEndian, &nfo.msg.MessageHeader); err != nil {
Logger.Debug("Failed to read command response.")
return err
}
// Logger.Debug("Header Response: %v %v %v %v", t.Type, t.Version, t.Length(), t.DataLen)
if err := nfo.msg.Resize(nfo.msg.Length()); err != nil {
return err
}
_, err := conn.Read(nfo.msg.Data, len(nfo.msg.Data))
return err
} | go | func (nfo *info) sendCommand(conn *Connection) error {
// Write.
if _, err := conn.Write(nfo.msg.Serialize()); err != nil {
Logger.Debug("Failed to send command.")
return err
}
// Read - reuse input buffer.
header := bytes.NewBuffer(make([]byte, MSG_HEADER_SIZE))
if _, err := conn.Read(header.Bytes(), MSG_HEADER_SIZE); err != nil {
return err
}
if err := binary.Read(header, binary.BigEndian, &nfo.msg.MessageHeader); err != nil {
Logger.Debug("Failed to read command response.")
return err
}
// Logger.Debug("Header Response: %v %v %v %v", t.Type, t.Version, t.Length(), t.DataLen)
if err := nfo.msg.Resize(nfo.msg.Length()); err != nil {
return err
}
_, err := conn.Read(nfo.msg.Data, len(nfo.msg.Data))
return err
} | [
"func",
"(",
"nfo",
"*",
"info",
")",
"sendCommand",
"(",
"conn",
"*",
"Connection",
")",
"error",
"{",
"// Write.",
"if",
"_",
",",
"err",
":=",
"conn",
".",
"Write",
"(",
"nfo",
".",
"msg",
".",
"Serialize",
"(",
")",
")",
";",
"err",
"!=",
"ni... | // Issue request and set results buffer. This method is used internally.
// The static request methods should be used instead. | [
"Issue",
"request",
"and",
"set",
"results",
"buffer",
".",
"This",
"method",
"is",
"used",
"internally",
".",
"The",
"static",
"request",
"methods",
"should",
"be",
"used",
"instead",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/info.go#L66-L89 |
9,837 | aerospike/aerospike-client-go | host.go | NewHost | func NewHost(name string, port int) *Host {
return &Host{Name: name, Port: port}
} | go | func NewHost(name string, port int) *Host {
return &Host{Name: name, Port: port}
} | [
"func",
"NewHost",
"(",
"name",
"string",
",",
"port",
"int",
")",
"*",
"Host",
"{",
"return",
"&",
"Host",
"{",
"Name",
":",
"name",
",",
"Port",
":",
"port",
"}",
"\n",
"}"
] | // NewHost initializes new host instance. | [
"NewHost",
"initializes",
"new",
"host",
"instance",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/host.go#L36-L38 |
9,838 | aerospike/aerospike-client-go | cluster.go | NewCluster | func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
// Default TLS names when TLS enabled.
newHosts := make([]*Host, 0, len(hosts))
if policy.TlsConfig != nil && !policy.TlsConfig.InsecureSkipVerify {
useClusterName := len(policy.ClusterName) > 0
for _, host := range hosts {
nh := *host
if nh.TLSName == "" {
if useClusterName {
nh.TLSName = policy.ClusterName
} else {
nh.TLSName = host.Name
}
}
newHosts = append(newHosts, &nh)
}
hosts = newHosts
}
newCluster := &Cluster{
clientPolicy: *policy,
infoPolicy: InfoPolicy{Timeout: policy.Timeout},
tendChannel: make(chan struct{}),
seeds: NewSyncVal(hosts),
aliases: NewSyncVal(make(map[Host]*Node)),
nodesMap: NewSyncVal(make(map[string]*Node)),
nodes: NewSyncVal([]*Node{}),
stats: map[string]*nodeStats{},
password: NewSyncVal(nil),
supportsFloat: NewAtomicBool(false),
supportsBatchIndex: NewAtomicBool(false),
supportsReplicasAll: NewAtomicBool(false),
supportsGeo: NewAtomicBool(false),
}
newCluster.partitionWriteMap.Store(make(partitionMap))
// setup auth info for cluster
if policy.RequiresAuthentication() {
if policy.AuthMode == AuthModeExternal && policy.TlsConfig == nil {
return nil, errors.New("External Authentication requires TLS configuration to be set, because it sends clear password on the wire.")
}
newCluster.user = policy.User
hashedPass, err := hashPassword(policy.Password)
if err != nil {
return nil, err
}
newCluster.password = NewSyncVal(hashedPass)
}
// try to seed connections for first use
err := newCluster.waitTillStabilized()
// apply policy rules
if policy.FailIfNotConnected && !newCluster.IsConnected() {
if err != nil {
return nil, err
}
return nil, fmt.Errorf("Failed to connect to host(s): %v. The network connection(s) to cluster nodes may have timed out, or the cluster may be in a state of flux.", hosts)
}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(&newCluster.clientPolicy)
if err == nil {
Logger.Debug("New cluster initialized and ready to be used...")
} else {
Logger.Error("New cluster was not initialized successfully, but the client will keep trying to connect to the database. Error: %s", err.Error())
}
return newCluster, err
} | go | func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, error) {
// Default TLS names when TLS enabled.
newHosts := make([]*Host, 0, len(hosts))
if policy.TlsConfig != nil && !policy.TlsConfig.InsecureSkipVerify {
useClusterName := len(policy.ClusterName) > 0
for _, host := range hosts {
nh := *host
if nh.TLSName == "" {
if useClusterName {
nh.TLSName = policy.ClusterName
} else {
nh.TLSName = host.Name
}
}
newHosts = append(newHosts, &nh)
}
hosts = newHosts
}
newCluster := &Cluster{
clientPolicy: *policy,
infoPolicy: InfoPolicy{Timeout: policy.Timeout},
tendChannel: make(chan struct{}),
seeds: NewSyncVal(hosts),
aliases: NewSyncVal(make(map[Host]*Node)),
nodesMap: NewSyncVal(make(map[string]*Node)),
nodes: NewSyncVal([]*Node{}),
stats: map[string]*nodeStats{},
password: NewSyncVal(nil),
supportsFloat: NewAtomicBool(false),
supportsBatchIndex: NewAtomicBool(false),
supportsReplicasAll: NewAtomicBool(false),
supportsGeo: NewAtomicBool(false),
}
newCluster.partitionWriteMap.Store(make(partitionMap))
// setup auth info for cluster
if policy.RequiresAuthentication() {
if policy.AuthMode == AuthModeExternal && policy.TlsConfig == nil {
return nil, errors.New("External Authentication requires TLS configuration to be set, because it sends clear password on the wire.")
}
newCluster.user = policy.User
hashedPass, err := hashPassword(policy.Password)
if err != nil {
return nil, err
}
newCluster.password = NewSyncVal(hashedPass)
}
// try to seed connections for first use
err := newCluster.waitTillStabilized()
// apply policy rules
if policy.FailIfNotConnected && !newCluster.IsConnected() {
if err != nil {
return nil, err
}
return nil, fmt.Errorf("Failed to connect to host(s): %v. The network connection(s) to cluster nodes may have timed out, or the cluster may be in a state of flux.", hosts)
}
// start up cluster maintenance go routine
newCluster.wgTend.Add(1)
go newCluster.clusterBoss(&newCluster.clientPolicy)
if err == nil {
Logger.Debug("New cluster initialized and ready to be used...")
} else {
Logger.Error("New cluster was not initialized successfully, but the client will keep trying to connect to the database. Error: %s", err.Error())
}
return newCluster, err
} | [
"func",
"NewCluster",
"(",
"policy",
"*",
"ClientPolicy",
",",
"hosts",
"[",
"]",
"*",
"Host",
")",
"(",
"*",
"Cluster",
",",
"error",
")",
"{",
"// Default TLS names when TLS enabled.",
"newHosts",
":=",
"make",
"(",
"[",
"]",
"*",
"Host",
",",
"0",
","... | // NewCluster generates a Cluster instance. | [
"NewCluster",
"generates",
"a",
"Cluster",
"instance",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L78-L155 |
9,839 | aerospike/aerospike-client-go | cluster.go | clusterBoss | func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
Logger.Info("Starting the cluster tend goroutine...")
defer func() {
if r := recover(); r != nil {
Logger.Error("Cluster tend goroutine crashed: %s", debug.Stack())
go clstr.clusterBoss(&clstr.clientPolicy)
}
}()
defer clstr.wgTend.Done()
tendInterval := policy.TendInterval
if tendInterval <= 10*time.Millisecond {
tendInterval = 10 * time.Millisecond
}
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
Logger.Debug("Tend channel closed. Shutting down the cluster...")
break Loop
case <-time.After(tendInterval):
tm := time.Now()
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
// Tending took longer than requested tend interval.
// Tending is too slow for the cluster, and may be falling behind scheule.
if tendDuration := time.Since(tm); tendDuration > clstr.clientPolicy.TendInterval {
Logger.Warn("Tending took %s, while your requested ClientPolicy.TendInterval is %s. Tends are slower than the interval, and may be falling behind the changes in the cluster.", tendDuration, clstr.clientPolicy.TendInterval)
}
}
}
// cleanup code goes here
// close the nodes
nodeArray := clstr.GetNodes()
for _, node := range nodeArray {
node.Close()
}
} | go | func (clstr *Cluster) clusterBoss(policy *ClientPolicy) {
Logger.Info("Starting the cluster tend goroutine...")
defer func() {
if r := recover(); r != nil {
Logger.Error("Cluster tend goroutine crashed: %s", debug.Stack())
go clstr.clusterBoss(&clstr.clientPolicy)
}
}()
defer clstr.wgTend.Done()
tendInterval := policy.TendInterval
if tendInterval <= 10*time.Millisecond {
tendInterval = 10 * time.Millisecond
}
Loop:
for {
select {
case <-clstr.tendChannel:
// tend channel closed
Logger.Debug("Tend channel closed. Shutting down the cluster...")
break Loop
case <-time.After(tendInterval):
tm := time.Now()
if err := clstr.tend(); err != nil {
Logger.Warn(err.Error())
}
// Tending took longer than requested tend interval.
// Tending is too slow for the cluster, and may be falling behind scheule.
if tendDuration := time.Since(tm); tendDuration > clstr.clientPolicy.TendInterval {
Logger.Warn("Tending took %s, while your requested ClientPolicy.TendInterval is %s. Tends are slower than the interval, and may be falling behind the changes in the cluster.", tendDuration, clstr.clientPolicy.TendInterval)
}
}
}
// cleanup code goes here
// close the nodes
nodeArray := clstr.GetNodes()
for _, node := range nodeArray {
node.Close()
}
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"clusterBoss",
"(",
"policy",
"*",
"ClientPolicy",
")",
"{",
"Logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"ni... | // Maintains the cluster on intervals.
// All clean up code for cluster is here as well. | [
"Maintains",
"the",
"cluster",
"on",
"intervals",
".",
"All",
"clean",
"up",
"code",
"for",
"cluster",
"is",
"here",
"as",
"well",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L164-L208 |
9,840 | aerospike/aerospike-client-go | cluster.go | AddSeeds | func (clstr *Cluster) AddSeeds(hosts []*Host) {
clstr.seeds.Update(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
seeds = append(seeds, hosts...)
return seeds, nil
})
} | go | func (clstr *Cluster) AddSeeds(hosts []*Host) {
clstr.seeds.Update(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
seeds = append(seeds, hosts...)
return seeds, nil
})
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"AddSeeds",
"(",
"hosts",
"[",
"]",
"*",
"Host",
")",
"{",
"clstr",
".",
"seeds",
".",
"Update",
"(",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
... | // AddSeeds adds new hosts to the cluster.
// They will be added to the cluster on next tend call. | [
"AddSeeds",
"adds",
"new",
"hosts",
"to",
"the",
"cluster",
".",
"They",
"will",
"be",
"added",
"to",
"the",
"cluster",
"on",
"next",
"tend",
"call",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L212-L218 |
9,841 | aerospike/aerospike-client-go | cluster.go | waitTillStabilized | func (clstr *Cluster) waitTillStabilized() error {
count := -1
doneCh := make(chan error, 10)
// will run until the cluster is stabilized
go func() {
var err error
for {
if err = clstr.tend(); err != nil {
if aerr, ok := err.(AerospikeError); ok {
switch aerr.ResultCode() {
case NOT_AUTHENTICATED, CLUSTER_NAME_MISMATCH_ERROR:
doneCh <- err
return
}
}
Logger.Warn(err.Error())
}
// // if there are no errors in connecting to the cluster, then validate the partition table
// if err == nil {
// err = clstr.getPartitions().validate()
// }
// Check to see if cluster has changed since the last Tend().
// If not, assume cluster has stabilized and return.
if count == len(clstr.GetNodes()) {
break
}
time.Sleep(time.Millisecond)
count = len(clstr.GetNodes())
}
doneCh <- err
}()
select {
case <-time.After(clstr.clientPolicy.Timeout):
if clstr.clientPolicy.FailIfNotConnected {
clstr.Close()
}
return errors.New("Connecting to the cluster timed out.")
case err := <-doneCh:
if err != nil && clstr.clientPolicy.FailIfNotConnected {
clstr.Close()
}
return err
}
} | go | func (clstr *Cluster) waitTillStabilized() error {
count := -1
doneCh := make(chan error, 10)
// will run until the cluster is stabilized
go func() {
var err error
for {
if err = clstr.tend(); err != nil {
if aerr, ok := err.(AerospikeError); ok {
switch aerr.ResultCode() {
case NOT_AUTHENTICATED, CLUSTER_NAME_MISMATCH_ERROR:
doneCh <- err
return
}
}
Logger.Warn(err.Error())
}
// // if there are no errors in connecting to the cluster, then validate the partition table
// if err == nil {
// err = clstr.getPartitions().validate()
// }
// Check to see if cluster has changed since the last Tend().
// If not, assume cluster has stabilized and return.
if count == len(clstr.GetNodes()) {
break
}
time.Sleep(time.Millisecond)
count = len(clstr.GetNodes())
}
doneCh <- err
}()
select {
case <-time.After(clstr.clientPolicy.Timeout):
if clstr.clientPolicy.FailIfNotConnected {
clstr.Close()
}
return errors.New("Connecting to the cluster timed out.")
case err := <-doneCh:
if err != nil && clstr.clientPolicy.FailIfNotConnected {
clstr.Close()
}
return err
}
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"waitTillStabilized",
"(",
")",
"error",
"{",
"count",
":=",
"-",
"1",
"\n\n",
"doneCh",
":=",
"make",
"(",
"chan",
"error",
",",
"10",
")",
"\n\n",
"// will run until the cluster is stabilized",
"go",
"func",
"(",
... | // Tend the cluster until it has stabilized and return control.
// This helps avoid initial database request timeout issues when
// a large number of threads are initiated at client startup.
//
// If the cluster has not stabilized by the timeout, return
// control as well. Do not return an error since future
// database requests may still succeed. | [
"Tend",
"the",
"cluster",
"until",
"it",
"has",
"stabilized",
"and",
"return",
"control",
".",
"This",
"helps",
"avoid",
"initial",
"database",
"request",
"timeout",
"issues",
"when",
"a",
"large",
"number",
"of",
"threads",
"are",
"initiated",
"at",
"client",... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L465-L515 |
9,842 | aerospike/aerospike-client-go | cluster.go | seedNodes | func (clstr *Cluster) seedNodes() (bool, error) {
// Must copy array reference for copy on write semantics to work.
seedArrayIfc, _ := clstr.seeds.GetSyncedVia(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
seeds_copy := make([]*Host, len(seeds))
copy(seeds_copy, seeds)
return seeds_copy, nil
})
seedArray := seedArrayIfc.([]*Host)
successChan := make(chan struct{}, len(seedArray))
errChan := make(chan error, len(seedArray))
Logger.Info("Seeding the cluster. Seeds count: %d", len(seedArray))
// Add all nodes at once to avoid copying entire array multiple times.
for i, seed := range seedArray {
go func(index int, seed *Host) {
nodesToAdd := make(nodesToAddT, 128)
nv := nodeValidator{}
err := nv.seedNodes(clstr, seed, nodesToAdd)
if err != nil {
Logger.Warn("Seed %s failed: %s", seed.String(), err.Error())
errChan <- err
return
}
clstr.addNodes(nodesToAdd)
successChan <- struct{}{}
}(i, seed)
}
errorList := make([]error, 0, len(seedArray))
seedCount := len(seedArray)
L:
for {
select {
case err := <-errChan:
errorList = append(errorList, err)
seedCount--
if seedCount <= 0 {
break L
}
case <-successChan:
// even one seed is enough
return true, nil
case <-time.After(clstr.clientPolicy.Timeout):
// time is up, no seeds found
break L
}
}
var errStrs []string
for _, err := range errorList {
if err != nil {
if aerr, ok := err.(AerospikeError); ok {
switch aerr.ResultCode() {
case NOT_AUTHENTICATED:
return false, NewAerospikeError(NOT_AUTHENTICATED)
case CLUSTER_NAME_MISMATCH_ERROR:
return false, aerr
}
}
errStrs = append(errStrs, err.Error())
}
}
return false, NewAerospikeError(INVALID_NODE_ERROR, "Failed to connect to hosts:"+strings.Join(errStrs, "\n"))
} | go | func (clstr *Cluster) seedNodes() (bool, error) {
// Must copy array reference for copy on write semantics to work.
seedArrayIfc, _ := clstr.seeds.GetSyncedVia(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
seeds_copy := make([]*Host, len(seeds))
copy(seeds_copy, seeds)
return seeds_copy, nil
})
seedArray := seedArrayIfc.([]*Host)
successChan := make(chan struct{}, len(seedArray))
errChan := make(chan error, len(seedArray))
Logger.Info("Seeding the cluster. Seeds count: %d", len(seedArray))
// Add all nodes at once to avoid copying entire array multiple times.
for i, seed := range seedArray {
go func(index int, seed *Host) {
nodesToAdd := make(nodesToAddT, 128)
nv := nodeValidator{}
err := nv.seedNodes(clstr, seed, nodesToAdd)
if err != nil {
Logger.Warn("Seed %s failed: %s", seed.String(), err.Error())
errChan <- err
return
}
clstr.addNodes(nodesToAdd)
successChan <- struct{}{}
}(i, seed)
}
errorList := make([]error, 0, len(seedArray))
seedCount := len(seedArray)
L:
for {
select {
case err := <-errChan:
errorList = append(errorList, err)
seedCount--
if seedCount <= 0 {
break L
}
case <-successChan:
// even one seed is enough
return true, nil
case <-time.After(clstr.clientPolicy.Timeout):
// time is up, no seeds found
break L
}
}
var errStrs []string
for _, err := range errorList {
if err != nil {
if aerr, ok := err.(AerospikeError); ok {
switch aerr.ResultCode() {
case NOT_AUTHENTICATED:
return false, NewAerospikeError(NOT_AUTHENTICATED)
case CLUSTER_NAME_MISMATCH_ERROR:
return false, aerr
}
}
errStrs = append(errStrs, err.Error())
}
}
return false, NewAerospikeError(INVALID_NODE_ERROR, "Failed to connect to hosts:"+strings.Join(errStrs, "\n"))
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"seedNodes",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Must copy array reference for copy on write semantics to work.",
"seedArrayIfc",
",",
"_",
":=",
"clstr",
".",
"seeds",
".",
"GetSyncedVia",
"(",
"func",
"... | // Adds seeds to the cluster | [
"Adds",
"seeds",
"to",
"the",
"cluster"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L539-L607 |
9,843 | aerospike/aerospike-client-go | cluster.go | findNodeName | func (clstr *Cluster) findNodeName(list []*Node, name string) bool {
for _, node := range list {
if node.GetName() == name {
return true
}
}
return false
} | go | func (clstr *Cluster) findNodeName(list []*Node, name string) bool {
for _, node := range list {
if node.GetName() == name {
return true
}
}
return false
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"findNodeName",
"(",
"list",
"[",
"]",
"*",
"Node",
",",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"node",
":=",
"range",
"list",
"{",
"if",
"node",
".",
"GetName",
"(",
")",
"==",
"name",
"{"... | // Finds a node by name in a list of nodes | [
"Finds",
"a",
"node",
"by",
"name",
"in",
"a",
"list",
"of",
"nodes"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L614-L621 |
9,844 | aerospike/aerospike-client-go | cluster.go | getSameRackNode | func (clstr *Cluster) getSameRackNode(partition *Partition, seq *int) (*Node, error) {
// RackAware has not been enabled in client policy.
if !clstr.clientPolicy.RackAware {
return nil, NewAerospikeError(UNSUPPORTED_FEATURE, "ReplicaPolicy is set to PREFER_RACK but ClientPolicy.RackAware is not set.")
}
pmap := clstr.getPartitions()
partitions := pmap[partition.Namespace]
if partitions == nil {
return nil, NewAerospikeError(PARTITION_UNAVAILABLE, "Invalid namespace in partition table:", partition.Namespace)
}
// CP mode (Strong Consistency) does not support the RackAware feature.
if partitions.CPMode {
return nil, NewAerospikeError(UNSUPPORTED_FEATURE, "ReplicaPolicy is set to PREFER_RACK but the cluster is in Strong Consistency Mode.")
}
replicaArray := partitions.Replicas
var seqNode *Node
for range replicaArray {
index := *seq % len(replicaArray)
node := replicaArray[index][partition.PartitionId]
*seq++
if node != nil {
// assign a node to seqNode in case no node was found on the same rack was found
if seqNode == nil {
seqNode = node
}
// if the node didn't belong to rack for that namespace, continue
nodeRack, err := node.Rack(partition.Namespace)
if err != nil {
continue
}
if node.IsActive() && nodeRack == clstr.clientPolicy.RackId {
return node, nil
}
}
}
// if no nodes were found belonging to the same rack, and no other node was also found
// then the partition table replicas are empty for that namespace
if seqNode == nil {
return nil, newInvalidNodeError(len(clstr.GetNodes()), partition)
}
return seqNode, nil
} | go | func (clstr *Cluster) getSameRackNode(partition *Partition, seq *int) (*Node, error) {
// RackAware has not been enabled in client policy.
if !clstr.clientPolicy.RackAware {
return nil, NewAerospikeError(UNSUPPORTED_FEATURE, "ReplicaPolicy is set to PREFER_RACK but ClientPolicy.RackAware is not set.")
}
pmap := clstr.getPartitions()
partitions := pmap[partition.Namespace]
if partitions == nil {
return nil, NewAerospikeError(PARTITION_UNAVAILABLE, "Invalid namespace in partition table:", partition.Namespace)
}
// CP mode (Strong Consistency) does not support the RackAware feature.
if partitions.CPMode {
return nil, NewAerospikeError(UNSUPPORTED_FEATURE, "ReplicaPolicy is set to PREFER_RACK but the cluster is in Strong Consistency Mode.")
}
replicaArray := partitions.Replicas
var seqNode *Node
for range replicaArray {
index := *seq % len(replicaArray)
node := replicaArray[index][partition.PartitionId]
*seq++
if node != nil {
// assign a node to seqNode in case no node was found on the same rack was found
if seqNode == nil {
seqNode = node
}
// if the node didn't belong to rack for that namespace, continue
nodeRack, err := node.Rack(partition.Namespace)
if err != nil {
continue
}
if node.IsActive() && nodeRack == clstr.clientPolicy.RackId {
return node, nil
}
}
}
// if no nodes were found belonging to the same rack, and no other node was also found
// then the partition table replicas are empty for that namespace
if seqNode == nil {
return nil, newInvalidNodeError(len(clstr.GetNodes()), partition)
}
return seqNode, nil
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"getSameRackNode",
"(",
"partition",
"*",
"Partition",
",",
"seq",
"*",
"int",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"// RackAware has not been enabled in client policy.",
"if",
"!",
"clstr",
".",
"clientPoli... | // getSameRackNode returns either a node on the same rack, or in Replica Sequence | [
"getSameRackNode",
"returns",
"either",
"a",
"node",
"on",
"the",
"same",
"rack",
"or",
"in",
"Replica",
"Sequence"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L803-L853 |
9,845 | aerospike/aerospike-client-go | cluster.go | GetRandomNode | func (clstr *Cluster) GetRandomNode() (*Node, error) {
// Must copy array reference for copy on write semantics to work.
nodeArray := clstr.GetNodes()
length := len(nodeArray)
for i := 0; i < length; i++ {
// Must handle concurrency with other non-tending goroutines, so nodeIndex is consistent.
index := int(atomic.AddUint64(&clstr.nodeIndex, 1) % uint64(length))
node := nodeArray[index]
if node != nil && node.IsActive() {
// Logger.Debug("Node `%s` is active. index=%d", node, index)
return node, nil
}
}
return nil, NewAerospikeError(INVALID_NODE_ERROR, "Cluster is empty.")
} | go | func (clstr *Cluster) GetRandomNode() (*Node, error) {
// Must copy array reference for copy on write semantics to work.
nodeArray := clstr.GetNodes()
length := len(nodeArray)
for i := 0; i < length; i++ {
// Must handle concurrency with other non-tending goroutines, so nodeIndex is consistent.
index := int(atomic.AddUint64(&clstr.nodeIndex, 1) % uint64(length))
node := nodeArray[index]
if node != nil && node.IsActive() {
// Logger.Debug("Node `%s` is active. index=%d", node, index)
return node, nil
}
}
return nil, NewAerospikeError(INVALID_NODE_ERROR, "Cluster is empty.")
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"GetRandomNode",
"(",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"// Must copy array reference for copy on write semantics to work.",
"nodeArray",
":=",
"clstr",
".",
"GetNodes",
"(",
")",
"\n",
"length",
":=",
"len... | // GetRandomNode returns a random node on the cluster | [
"GetRandomNode",
"returns",
"a",
"random",
"node",
"on",
"the",
"cluster"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L915-L931 |
9,846 | aerospike/aerospike-client-go | cluster.go | GetSeeds | func (clstr *Cluster) GetSeeds() []Host {
res, _ := clstr.seeds.GetSyncedVia(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
res := make([]Host, 0, len(seeds))
for _, seed := range seeds {
res = append(res, *seed)
}
return res, nil
})
return res.([]Host)
} | go | func (clstr *Cluster) GetSeeds() []Host {
res, _ := clstr.seeds.GetSyncedVia(func(val interface{}) (interface{}, error) {
seeds := val.([]*Host)
res := make([]Host, 0, len(seeds))
for _, seed := range seeds {
res = append(res, *seed)
}
return res, nil
})
return res.([]Host)
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"GetSeeds",
"(",
")",
"[",
"]",
"Host",
"{",
"res",
",",
"_",
":=",
"clstr",
".",
"seeds",
".",
"GetSyncedVia",
"(",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"erro... | // GetSeeds returns a list of all seed nodes in the cluster | [
"GetSeeds",
"returns",
"a",
"list",
"of",
"all",
"seed",
"nodes",
"in",
"the",
"cluster"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L940-L952 |
9,847 | aerospike/aerospike-client-go | cluster.go | GetAliases | func (clstr *Cluster) GetAliases() map[Host]*Node {
res, _ := clstr.aliases.GetSyncedVia(func(val interface{}) (interface{}, error) {
aliases := val.(map[Host]*Node)
res := make(map[Host]*Node, len(aliases))
for h, n := range aliases {
res[h] = n
}
return res, nil
})
return res.(map[Host]*Node)
} | go | func (clstr *Cluster) GetAliases() map[Host]*Node {
res, _ := clstr.aliases.GetSyncedVia(func(val interface{}) (interface{}, error) {
aliases := val.(map[Host]*Node)
res := make(map[Host]*Node, len(aliases))
for h, n := range aliases {
res[h] = n
}
return res, nil
})
return res.(map[Host]*Node)
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"GetAliases",
"(",
")",
"map",
"[",
"Host",
"]",
"*",
"Node",
"{",
"res",
",",
"_",
":=",
"clstr",
".",
"aliases",
".",
"GetSyncedVia",
"(",
"func",
"(",
"val",
"interface",
"{",
"}",
")",
"(",
"interface"... | // GetAliases returns a list of all node aliases in the cluster | [
"GetAliases",
"returns",
"a",
"list",
"of",
"all",
"node",
"aliases",
"in",
"the",
"cluster"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L955-L967 |
9,848 | aerospike/aerospike-client-go | cluster.go | GetNodeByName | func (clstr *Cluster) GetNodeByName(nodeName string) (*Node, error) {
node := clstr.findNodeByName(nodeName)
if node == nil {
return nil, NewAerospikeError(INVALID_NODE_ERROR, "Invalid node name"+nodeName)
}
return node, nil
} | go | func (clstr *Cluster) GetNodeByName(nodeName string) (*Node, error) {
node := clstr.findNodeByName(nodeName)
if node == nil {
return nil, NewAerospikeError(INVALID_NODE_ERROR, "Invalid node name"+nodeName)
}
return node, nil
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"GetNodeByName",
"(",
"nodeName",
"string",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"node",
":=",
"clstr",
".",
"findNodeByName",
"(",
"nodeName",
")",
"\n\n",
"if",
"node",
"==",
"nil",
"{",
"return",
... | // GetNodeByName finds a node by name and returns an
// error if the node is not found. | [
"GetNodeByName",
"finds",
"a",
"node",
"by",
"name",
"and",
"returns",
"an",
"error",
"if",
"the",
"node",
"is",
"not",
"found",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L971-L978 |
9,849 | aerospike/aerospike-client-go | cluster.go | Close | func (clstr *Cluster) Close() {
if clstr.closed.CompareAndToggle(false) {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
} | go | func (clstr *Cluster) Close() {
if clstr.closed.CompareAndToggle(false) {
// send close signal to maintenance channel
close(clstr.tendChannel)
// wait until tend is over
clstr.wgTend.Wait()
}
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"Close",
"(",
")",
"{",
"if",
"clstr",
".",
"closed",
".",
"CompareAndToggle",
"(",
"false",
")",
"{",
"// send close signal to maintenance channel",
"close",
"(",
"clstr",
".",
"tendChannel",
")",
"\n\n",
"// wait un... | // Close closes all cached connections to the cluster nodes
// and stops the tend goroutine. | [
"Close",
"closes",
"all",
"cached",
"connections",
"to",
"the",
"cluster",
"nodes",
"and",
"stops",
"the",
"tend",
"goroutine",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L992-L1000 |
9,850 | aerospike/aerospike-client-go | cluster.go | MigrationInProgress | func (clstr *Cluster) MigrationInProgress(timeout time.Duration) (res bool, err error) {
if timeout <= 0 {
timeout = _DEFAULT_TIMEOUT
}
done := make(chan bool, 1)
go func() {
// this function is guaranteed to return after _DEFAULT_TIMEOUT
nodes := clstr.GetNodes()
for _, node := range nodes {
if node.IsActive() {
if res, err = node.MigrationInProgress(); res || err != nil {
done <- true
return
}
}
}
res, err = false, nil
done <- false
}()
dealine := time.After(timeout)
for {
select {
case <-dealine:
return false, NewAerospikeError(TIMEOUT)
case <-done:
return res, err
}
}
} | go | func (clstr *Cluster) MigrationInProgress(timeout time.Duration) (res bool, err error) {
if timeout <= 0 {
timeout = _DEFAULT_TIMEOUT
}
done := make(chan bool, 1)
go func() {
// this function is guaranteed to return after _DEFAULT_TIMEOUT
nodes := clstr.GetNodes()
for _, node := range nodes {
if node.IsActive() {
if res, err = node.MigrationInProgress(); res || err != nil {
done <- true
return
}
}
}
res, err = false, nil
done <- false
}()
dealine := time.After(timeout)
for {
select {
case <-dealine:
return false, NewAerospikeError(TIMEOUT)
case <-done:
return res, err
}
}
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"MigrationInProgress",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"res",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"timeout",
"<=",
"0",
"{",
"timeout",
"=",
"_DEFAULT_TIMEOUT",
"\n",
"}",
"\n\n",
"... | // MigrationInProgress determines if any node in the cluster
// is participating in a data migration | [
"MigrationInProgress",
"determines",
"if",
"any",
"node",
"in",
"the",
"cluster",
"is",
"participating",
"in",
"a",
"data",
"migration"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L1004-L1036 |
9,851 | aerospike/aerospike-client-go | cluster.go | WaitUntillMigrationIsFinished | func (clstr *Cluster) WaitUntillMigrationIsFinished(timeout time.Duration) (err error) {
if timeout <= 0 {
timeout = _NO_TIMEOUT
}
done := make(chan error, 1)
go func() {
// this function is guaranteed to return after timeout
// no go routines will be leaked
for {
if res, err := clstr.MigrationInProgress(timeout); err != nil || !res {
done <- err
return
}
}
}()
dealine := time.After(timeout)
select {
case <-dealine:
return NewAerospikeError(TIMEOUT)
case err = <-done:
return err
}
} | go | func (clstr *Cluster) WaitUntillMigrationIsFinished(timeout time.Duration) (err error) {
if timeout <= 0 {
timeout = _NO_TIMEOUT
}
done := make(chan error, 1)
go func() {
// this function is guaranteed to return after timeout
// no go routines will be leaked
for {
if res, err := clstr.MigrationInProgress(timeout); err != nil || !res {
done <- err
return
}
}
}()
dealine := time.After(timeout)
select {
case <-dealine:
return NewAerospikeError(TIMEOUT)
case err = <-done:
return err
}
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"WaitUntillMigrationIsFinished",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"if",
"timeout",
"<=",
"0",
"{",
"timeout",
"=",
"_NO_TIMEOUT",
"\n",
"}",
"\n",
"done",
":=",
"make"... | // WaitUntillMigrationIsFinished will block until all
// migration operations in the cluster all finished. | [
"WaitUntillMigrationIsFinished",
"will",
"block",
"until",
"all",
"migration",
"operations",
"in",
"the",
"cluster",
"all",
"finished",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L1040-L1064 |
9,852 | aerospike/aerospike-client-go | cluster.go | Password | func (clstr *Cluster) Password() (res []byte) {
pass := clstr.password.Get()
if pass != nil {
return pass.([]byte)
}
return nil
} | go | func (clstr *Cluster) Password() (res []byte) {
pass := clstr.password.Get()
if pass != nil {
return pass.([]byte)
}
return nil
} | [
"func",
"(",
"clstr",
"*",
"Cluster",
")",
"Password",
"(",
")",
"(",
"res",
"[",
"]",
"byte",
")",
"{",
"pass",
":=",
"clstr",
".",
"password",
".",
"Get",
"(",
")",
"\n",
"if",
"pass",
"!=",
"nil",
"{",
"return",
"pass",
".",
"(",
"[",
"]",
... | // Password returns the password that is currently used with the cluster. | [
"Password",
"returns",
"the",
"password",
"that",
"is",
"currently",
"used",
"with",
"the",
"cluster",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/cluster.go#L1067-L1073 |
9,853 | aerospike/aerospike-client-go | internal/lua/lua_aerospike.go | registerLuaAerospikeType | func registerLuaAerospikeType(L *lua.LState) {
mt := L.NewTypeMetatable(luaLuaAerospikeTypeName)
L.SetGlobal("aerospike", mt)
// static attributes
L.SetField(mt, "log", L.NewFunction(luaAerospikeLog))
L.SetMetatable(mt, mt)
} | go | func registerLuaAerospikeType(L *lua.LState) {
mt := L.NewTypeMetatable(luaLuaAerospikeTypeName)
L.SetGlobal("aerospike", mt)
// static attributes
L.SetField(mt, "log", L.NewFunction(luaAerospikeLog))
L.SetMetatable(mt, mt)
} | [
"func",
"registerLuaAerospikeType",
"(",
"L",
"*",
"lua",
".",
"LState",
")",
"{",
"mt",
":=",
"L",
".",
"NewTypeMetatable",
"(",
"luaLuaAerospikeTypeName",
")",
"\n\n",
"L",
".",
"SetGlobal",
"(",
"\"",
"\"",
",",
"mt",
")",
"\n\n",
"// static attributes",
... | // Registers my luaAerospike type to given L. | [
"Registers",
"my",
"luaAerospike",
"type",
"to",
"given",
"L",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/internal/lua/lua_aerospike.go#L31-L40 |
9,854 | aerospike/aerospike-client-go | task_index.go | NewIndexTask | func NewIndexTask(cluster *Cluster, namespace string, indexName string) *IndexTask {
return &IndexTask{
baseTask: newTask(cluster),
namespace: namespace,
indexName: indexName,
}
} | go | func NewIndexTask(cluster *Cluster, namespace string, indexName string) *IndexTask {
return &IndexTask{
baseTask: newTask(cluster),
namespace: namespace,
indexName: indexName,
}
} | [
"func",
"NewIndexTask",
"(",
"cluster",
"*",
"Cluster",
",",
"namespace",
"string",
",",
"indexName",
"string",
")",
"*",
"IndexTask",
"{",
"return",
"&",
"IndexTask",
"{",
"baseTask",
":",
"newTask",
"(",
"cluster",
")",
",",
"namespace",
":",
"namespace",
... | // NewIndexTask initializes a task with fields needed to query server nodes. | [
"NewIndexTask",
"initializes",
"a",
"task",
"with",
"fields",
"needed",
"to",
"query",
"server",
"nodes",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/task_index.go#L32-L38 |
9,855 | aerospike/aerospike-client-go | buffered_connection.go | shiftContentToHead | func (bc *bufferedConn) shiftContentToHead(length int) {
// shift data to the head of the byte slice
if length > bc.emptyCap() {
buf := make([]byte, bc.len()+length)
copy(buf, bc.buf()[bc.head:bc.tail])
bc.conn.dataBuffer = buf
bc.tail -= bc.head
bc.head = 0
} else if bc.len() > 0 {
copy(bc.buf(), bc.buf()[bc.head:bc.tail])
bc.tail -= bc.head
bc.head = 0
} else {
bc.tail = 0
bc.head = 0
}
} | go | func (bc *bufferedConn) shiftContentToHead(length int) {
// shift data to the head of the byte slice
if length > bc.emptyCap() {
buf := make([]byte, bc.len()+length)
copy(buf, bc.buf()[bc.head:bc.tail])
bc.conn.dataBuffer = buf
bc.tail -= bc.head
bc.head = 0
} else if bc.len() > 0 {
copy(bc.buf(), bc.buf()[bc.head:bc.tail])
bc.tail -= bc.head
bc.head = 0
} else {
bc.tail = 0
bc.head = 0
}
} | [
"func",
"(",
"bc",
"*",
"bufferedConn",
")",
"shiftContentToHead",
"(",
"length",
"int",
")",
"{",
"// shift data to the head of the byte slice",
"if",
"length",
">",
"bc",
".",
"emptyCap",
"(",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"b... | // shiftContentToHead will move the unread bytes to the head of the buffer.
// It will also resize the buffer if there is not enough empty capacity to read
// the minimum number of bytes that are requested.
// If the buffer is empty, head and tail will be reset to the beginning of the buffer. | [
"shiftContentToHead",
"will",
"move",
"the",
"unread",
"bytes",
"to",
"the",
"head",
"of",
"the",
"buffer",
".",
"It",
"will",
"also",
"resize",
"the",
"buffer",
"if",
"there",
"is",
"not",
"enough",
"empty",
"capacity",
"to",
"read",
"the",
"minimum",
"nu... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/buffered_connection.go#L55-L73 |
9,856 | aerospike/aerospike-client-go | buffered_connection.go | readConn | func (bc *bufferedConn) readConn(minLength int) error {
// Corrupted data streams can result in a huge minLength.
// Do a sanity check here.
if minLength > MaxBufferSize || minLength <= 0 || minLength > bc.remaining {
return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid readBytes length: %d", minLength))
}
bc.shiftContentToHead(minLength)
toRead := bc.remaining
if ec := bc.emptyCap(); toRead > ec {
toRead = ec
}
n, err := bc.conn.Read(bc.buf()[bc.tail:], toRead)
bc.tail += n
bc.remaining -= n
if err != nil {
return fmt.Errorf("Requested to read %d bytes, but %d was read. (%v)", minLength, n, err)
}
return nil
} | go | func (bc *bufferedConn) readConn(minLength int) error {
// Corrupted data streams can result in a huge minLength.
// Do a sanity check here.
if minLength > MaxBufferSize || minLength <= 0 || minLength > bc.remaining {
return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid readBytes length: %d", minLength))
}
bc.shiftContentToHead(minLength)
toRead := bc.remaining
if ec := bc.emptyCap(); toRead > ec {
toRead = ec
}
n, err := bc.conn.Read(bc.buf()[bc.tail:], toRead)
bc.tail += n
bc.remaining -= n
if err != nil {
return fmt.Errorf("Requested to read %d bytes, but %d was read. (%v)", minLength, n, err)
}
return nil
} | [
"func",
"(",
"bc",
"*",
"bufferedConn",
")",
"readConn",
"(",
"minLength",
"int",
")",
"error",
"{",
"// Corrupted data streams can result in a huge minLength.",
"// Do a sanity check here.",
"if",
"minLength",
">",
"MaxBufferSize",
"||",
"minLength",
"<=",
"0",
"||",
... | // readConn will read the minimum minLength number of bytes from the connection.
// It will read more if it has extra empty capacity in the buffer. | [
"readConn",
"will",
"read",
"the",
"minimum",
"minLength",
"number",
"of",
"bytes",
"from",
"the",
"connection",
".",
"It",
"will",
"read",
"more",
"if",
"it",
"has",
"extra",
"empty",
"capacity",
"in",
"the",
"buffer",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/buffered_connection.go#L77-L100 |
9,857 | aerospike/aerospike-client-go | recordset.go | newObjectset | func newObjectset(objChan reflect.Value, goroutines int, taskID uint64) *objectset {
if objChan.Kind() != reflect.Chan ||
objChan.Type().Elem().Kind() != reflect.Ptr ||
objChan.Type().Elem().Elem().Kind() != reflect.Struct {
panic("Scan/Query object channels should be of type `chan *T`")
}
rs := &objectset{
objChan: objChan,
Errors: make(chan error, goroutines),
active: NewAtomicBool(true),
closed: NewAtomicBool(false),
goroutines: NewAtomicInt(goroutines),
cancelled: make(chan struct{}),
taskID: taskID,
}
rs.wgGoroutines.Add(goroutines)
return rs
} | go | func newObjectset(objChan reflect.Value, goroutines int, taskID uint64) *objectset {
if objChan.Kind() != reflect.Chan ||
objChan.Type().Elem().Kind() != reflect.Ptr ||
objChan.Type().Elem().Elem().Kind() != reflect.Struct {
panic("Scan/Query object channels should be of type `chan *T`")
}
rs := &objectset{
objChan: objChan,
Errors: make(chan error, goroutines),
active: NewAtomicBool(true),
closed: NewAtomicBool(false),
goroutines: NewAtomicInt(goroutines),
cancelled: make(chan struct{}),
taskID: taskID,
}
rs.wgGoroutines.Add(goroutines)
return rs
} | [
"func",
"newObjectset",
"(",
"objChan",
"reflect",
".",
"Value",
",",
"goroutines",
"int",
",",
"taskID",
"uint64",
")",
"*",
"objectset",
"{",
"if",
"objChan",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Chan",
"||",
"objChan",
".",
"Type",
"(",
")"... | // newObjectset generates a new RecordSet instance. | [
"newObjectset",
"generates",
"a",
"new",
"RecordSet",
"instance",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/recordset.go#L82-L102 |
9,858 | aerospike/aerospike-client-go | recordset.go | newRecordset | func newRecordset(recSize, goroutines int, taskID uint64) *Recordset {
var nilChan chan *struct{}
rs := &Recordset{
Records: make(chan *Record, recSize),
objectset: *newObjectset(reflect.ValueOf(nilChan), goroutines, taskID),
}
runtime.SetFinalizer(rs, recordsetFinalizer)
return rs
} | go | func newRecordset(recSize, goroutines int, taskID uint64) *Recordset {
var nilChan chan *struct{}
rs := &Recordset{
Records: make(chan *Record, recSize),
objectset: *newObjectset(reflect.ValueOf(nilChan), goroutines, taskID),
}
runtime.SetFinalizer(rs, recordsetFinalizer)
return rs
} | [
"func",
"newRecordset",
"(",
"recSize",
",",
"goroutines",
"int",
",",
"taskID",
"uint64",
")",
"*",
"Recordset",
"{",
"var",
"nilChan",
"chan",
"*",
"struct",
"{",
"}",
"\n\n",
"rs",
":=",
"&",
"Recordset",
"{",
"Records",
":",
"make",
"(",
"chan",
"*... | // newRecordset generates a new RecordSet instance. | [
"newRecordset",
"generates",
"a",
"new",
"RecordSet",
"instance",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/recordset.go#L105-L115 |
9,859 | aerospike/aerospike-client-go | recordset.go | Read | func (rcs *Recordset) Read() (record *Record, err error) {
var ok bool
L:
select {
case record, ok = <-rcs.Records:
if !ok {
err = ErrRecordsetClosed
}
case err = <-rcs.Errors:
if err == nil {
// if err == nil, it means the Errors chan has been closed
// we should not return nil as an error, so we should listen
// to other chans again to determine either cancellation,
// or normal EOR
goto L
}
}
return record, err
} | go | func (rcs *Recordset) Read() (record *Record, err error) {
var ok bool
L:
select {
case record, ok = <-rcs.Records:
if !ok {
err = ErrRecordsetClosed
}
case err = <-rcs.Errors:
if err == nil {
// if err == nil, it means the Errors chan has been closed
// we should not return nil as an error, so we should listen
// to other chans again to determine either cancellation,
// or normal EOR
goto L
}
}
return record, err
} | [
"func",
"(",
"rcs",
"*",
"Recordset",
")",
"Read",
"(",
")",
"(",
"record",
"*",
"Record",
",",
"err",
"error",
")",
"{",
"var",
"ok",
"bool",
"\n\n",
"L",
":",
"select",
"{",
"case",
"record",
",",
"ok",
"=",
"<-",
"rcs",
".",
"Records",
":",
... | // Read reads the next record from the Recordset. If the Recordset has been
// closed, it returns ErrRecordsetClosed. | [
"Read",
"reads",
"the",
"next",
"record",
"from",
"the",
"Recordset",
".",
"If",
"the",
"Recordset",
"has",
"been",
"closed",
"it",
"returns",
"ErrRecordsetClosed",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/recordset.go#L124-L144 |
9,860 | aerospike/aerospike-client-go | recordset.go | Close | func (rcs *Recordset) Close() error {
// do it only once
if !rcs.closed.CompareAndToggle(false) {
return ErrRecordsetClosed
}
// mark the recordset as inactive
rcs.active.Set(false)
close(rcs.cancelled)
// wait till all goroutines are done, and signalEnd is called by the scan command
rcs.wgGoroutines.Wait()
return nil
} | go | func (rcs *Recordset) Close() error {
// do it only once
if !rcs.closed.CompareAndToggle(false) {
return ErrRecordsetClosed
}
// mark the recordset as inactive
rcs.active.Set(false)
close(rcs.cancelled)
// wait till all goroutines are done, and signalEnd is called by the scan command
rcs.wgGoroutines.Wait()
return nil
} | [
"func",
"(",
"rcs",
"*",
"Recordset",
")",
"Close",
"(",
")",
"error",
"{",
"// do it only once",
"if",
"!",
"rcs",
".",
"closed",
".",
"CompareAndToggle",
"(",
"false",
")",
"{",
"return",
"ErrRecordsetClosed",
"\n",
"}",
"\n\n",
"// mark the recordset as ina... | // Close all streams from different nodes. A successful close return nil,
// subsequent calls to the method will return ErrRecordsetClosed. | [
"Close",
"all",
"streams",
"from",
"different",
"nodes",
".",
"A",
"successful",
"close",
"return",
"nil",
"subsequent",
"calls",
"to",
"the",
"method",
"will",
"return",
"ErrRecordsetClosed",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/recordset.go#L204-L219 |
9,861 | aerospike/aerospike-client-go | client.go | NewClientWithPolicy | func NewClientWithPolicy(policy *ClientPolicy, hostname string, port int) (*Client, error) {
return NewClientWithPolicyAndHost(policy, NewHost(hostname, port))
} | go | func NewClientWithPolicy(policy *ClientPolicy, hostname string, port int) (*Client, error) {
return NewClientWithPolicyAndHost(policy, NewHost(hostname, port))
} | [
"func",
"NewClientWithPolicy",
"(",
"policy",
"*",
"ClientPolicy",
",",
"hostname",
"string",
",",
"port",
"int",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"return",
"NewClientWithPolicyAndHost",
"(",
"policy",
",",
"NewHost",
"(",
"hostname",
",",
"p... | // NewClientWithPolicy generates a new Client using the specified ClientPolicy.
// If the policy is nil, the default relevant policy will be used. | [
"NewClientWithPolicy",
"generates",
"a",
"new",
"Client",
"using",
"the",
"specified",
"ClientPolicy",
".",
"If",
"the",
"policy",
"is",
"nil",
"the",
"default",
"relevant",
"policy",
"will",
"be",
"used",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L69-L71 |
9,862 | aerospike/aerospike-client-go | client.go | NewClientWithPolicyAndHost | func NewClientWithPolicyAndHost(policy *ClientPolicy, hosts ...*Host) (*Client, error) {
if policy == nil {
policy = NewClientPolicy()
}
cluster, err := NewCluster(policy, hosts)
if err != nil && policy.FailIfNotConnected {
if aerr, ok := err.(AerospikeError); ok {
Logger.Debug("Failed to connect to host(s): %v; error: %s", hosts, err)
return nil, aerr
}
return nil, fmt.Errorf("Failed to connect to host(s): %v; error: %s", hosts, err)
}
client := &Client{
cluster: cluster,
DefaultPolicy: NewPolicy(),
DefaultBatchPolicy: NewBatchPolicy(),
DefaultWritePolicy: NewWritePolicy(0, 0),
DefaultScanPolicy: NewScanPolicy(),
DefaultQueryPolicy: NewQueryPolicy(),
DefaultAdminPolicy: NewAdminPolicy(),
}
runtime.SetFinalizer(client, clientFinalizer)
return client, err
} | go | func NewClientWithPolicyAndHost(policy *ClientPolicy, hosts ...*Host) (*Client, error) {
if policy == nil {
policy = NewClientPolicy()
}
cluster, err := NewCluster(policy, hosts)
if err != nil && policy.FailIfNotConnected {
if aerr, ok := err.(AerospikeError); ok {
Logger.Debug("Failed to connect to host(s): %v; error: %s", hosts, err)
return nil, aerr
}
return nil, fmt.Errorf("Failed to connect to host(s): %v; error: %s", hosts, err)
}
client := &Client{
cluster: cluster,
DefaultPolicy: NewPolicy(),
DefaultBatchPolicy: NewBatchPolicy(),
DefaultWritePolicy: NewWritePolicy(0, 0),
DefaultScanPolicy: NewScanPolicy(),
DefaultQueryPolicy: NewQueryPolicy(),
DefaultAdminPolicy: NewAdminPolicy(),
}
runtime.SetFinalizer(client, clientFinalizer)
return client, err
} | [
"func",
"NewClientWithPolicyAndHost",
"(",
"policy",
"*",
"ClientPolicy",
",",
"hosts",
"...",
"*",
"Host",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"if",
"policy",
"==",
"nil",
"{",
"policy",
"=",
"NewClientPolicy",
"(",
")",
"\n",
"}",
"\n\n",
... | // NewClientWithPolicyAndHost generates a new Client the specified ClientPolicy and
// sets up the cluster using the provided hosts.
// If the policy is nil, the default relevant policy will be used. | [
"NewClientWithPolicyAndHost",
"generates",
"a",
"new",
"Client",
"the",
"specified",
"ClientPolicy",
"and",
"sets",
"up",
"the",
"cluster",
"using",
"the",
"provided",
"hosts",
".",
"If",
"the",
"policy",
"is",
"nil",
"the",
"default",
"relevant",
"policy",
"wil... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L76-L103 |
9,863 | aerospike/aerospike-client-go | client.go | GetNodeNames | func (clnt *Client) GetNodeNames() []string {
nodes := clnt.cluster.GetNodes()
names := make([]string, 0, len(nodes))
for _, node := range nodes {
names = append(names, node.GetName())
}
return names
} | go | func (clnt *Client) GetNodeNames() []string {
nodes := clnt.cluster.GetNodes()
names := make([]string, 0, len(nodes))
for _, node := range nodes {
names = append(names, node.GetName())
}
return names
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"GetNodeNames",
"(",
")",
"[",
"]",
"string",
"{",
"nodes",
":=",
"clnt",
".",
"cluster",
".",
"GetNodes",
"(",
")",
"\n",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"nodes"... | // GetNodeNames returns a list of active server node names in the cluster. | [
"GetNodeNames",
"returns",
"a",
"list",
"of",
"active",
"server",
"node",
"names",
"in",
"the",
"cluster",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L125-L133 |
9,864 | aerospike/aerospike-client-go | client.go | AppendBins | func (clnt *Client) AppendBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _APPEND)
return command.Execute()
} | go | func (clnt *Client) AppendBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _APPEND)
return command.Execute()
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"AppendBins",
"(",
"policy",
"*",
"WritePolicy",
",",
"key",
"*",
"Key",
",",
"bins",
"...",
"*",
"Bin",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableWritePolicy",
"(",
"policy",
")",
"\n",
"command"... | // AppendBins works the same as Append, but avoids BinMap allocation and iteration. | [
"AppendBins",
"works",
"the",
"same",
"as",
"Append",
"but",
"avoids",
"BinMap",
"allocation",
"and",
"iteration",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L176-L180 |
9,865 | aerospike/aerospike-client-go | client.go | PrependBins | func (clnt *Client) PrependBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _PREPEND)
return command.Execute()
} | go | func (clnt *Client) PrependBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _PREPEND)
return command.Execute()
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"PrependBins",
"(",
"policy",
"*",
"WritePolicy",
",",
"key",
"*",
"Key",
",",
"bins",
"...",
"*",
"Bin",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableWritePolicy",
"(",
"policy",
")",
"\n",
"command... | // PrependBins works the same as Prepend, but avoids BinMap allocation and iteration. | [
"PrependBins",
"works",
"the",
"same",
"as",
"Prepend",
"but",
"avoids",
"BinMap",
"allocation",
"and",
"iteration",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L194-L198 |
9,866 | aerospike/aerospike-client-go | client.go | AddBins | func (clnt *Client) AddBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _ADD)
return command.Execute()
} | go | func (clnt *Client) AddBins(policy *WritePolicy, key *Key, bins ...*Bin) error {
policy = clnt.getUsableWritePolicy(policy)
command := newWriteCommand(clnt.cluster, policy, key, bins, nil, _ADD)
return command.Execute()
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"AddBins",
"(",
"policy",
"*",
"WritePolicy",
",",
"key",
"*",
"Key",
",",
"bins",
"...",
"*",
"Bin",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableWritePolicy",
"(",
"policy",
")",
"\n",
"command",
... | // AddBins works the same as Add, but avoids BinMap allocation and iteration. | [
"AddBins",
"works",
"the",
"same",
"as",
"Add",
"but",
"avoids",
"BinMap",
"allocation",
"and",
"iteration",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L216-L220 |
9,867 | aerospike/aerospike-client-go | client.go | BatchExists | func (clnt *Client) BatchExists(policy *BatchPolicy, keys []*Key) ([]bool, error) {
policy = clnt.getUsableBatchPolicy(policy)
// same array can be used without synchronization;
// when a key exists, the corresponding index will be marked true
existsArray := make([]bool, len(keys))
// pass nil to make sure it will be cloned and prepared
cmd := newBatchCommandExists(nil, nil, nil, policy, keys, existsArray)
if err := clnt.batchExecute(policy, keys, cmd); err != nil {
return nil, err
}
return existsArray, nil
} | go | func (clnt *Client) BatchExists(policy *BatchPolicy, keys []*Key) ([]bool, error) {
policy = clnt.getUsableBatchPolicy(policy)
// same array can be used without synchronization;
// when a key exists, the corresponding index will be marked true
existsArray := make([]bool, len(keys))
// pass nil to make sure it will be cloned and prepared
cmd := newBatchCommandExists(nil, nil, nil, policy, keys, existsArray)
if err := clnt.batchExecute(policy, keys, cmd); err != nil {
return nil, err
}
return existsArray, nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"BatchExists",
"(",
"policy",
"*",
"BatchPolicy",
",",
"keys",
"[",
"]",
"*",
"Key",
")",
"(",
"[",
"]",
"bool",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableBatchPolicy",
"(",
"policy",
")",
... | // BatchExists determines if multiple record keys exist in one batch request.
// The returned boolean array is in positional order with the original key array order.
// The policy can be used to specify timeouts.
// If the policy is nil, the default relevant policy will be used. | [
"BatchExists",
"determines",
"if",
"multiple",
"record",
"keys",
"exist",
"in",
"one",
"batch",
"request",
".",
"The",
"returned",
"boolean",
"array",
"is",
"in",
"positional",
"order",
"with",
"the",
"original",
"key",
"array",
"order",
".",
"The",
"policy",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L268-L282 |
9,868 | aerospike/aerospike-client-go | client.go | GetHeader | func (clnt *Client) GetHeader(policy *BasePolicy, key *Key) (*Record, error) {
policy = clnt.getUsablePolicy(policy)
command := newReadHeaderCommand(clnt.cluster, policy, key)
if err := command.Execute(); err != nil {
return nil, err
}
return command.GetRecord(), nil
} | go | func (clnt *Client) GetHeader(policy *BasePolicy, key *Key) (*Record, error) {
policy = clnt.getUsablePolicy(policy)
command := newReadHeaderCommand(clnt.cluster, policy, key)
if err := command.Execute(); err != nil {
return nil, err
}
return command.GetRecord(), nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"GetHeader",
"(",
"policy",
"*",
"BasePolicy",
",",
"key",
"*",
"Key",
")",
"(",
"*",
"Record",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsablePolicy",
"(",
"policy",
")",
"\n\n",
"command",
":=... | // GetHeader reads a record generation and expiration only for specified key.
// Bins are not read.
// The policy can be used to specify timeouts.
// If the policy is nil, the default relevant policy will be used. | [
"GetHeader",
"reads",
"a",
"record",
"generation",
"and",
"expiration",
"only",
"for",
"specified",
"key",
".",
"Bins",
"are",
"not",
"read",
".",
"The",
"policy",
"can",
"be",
"used",
"to",
"specify",
"timeouts",
".",
"If",
"the",
"policy",
"is",
"nil",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L305-L313 |
9,869 | aerospike/aerospike-client-go | client.go | BatchGetHeader | func (clnt *Client) BatchGetHeader(policy *BatchPolicy, keys []*Key) ([]*Record, error) {
policy = clnt.getUsableBatchPolicy(policy)
// same array can be used without synchronization;
// when a key exists, the corresponding index will be set to record
records := make([]*Record, len(keys))
cmd := newBatchCommandGet(nil, nil, nil, policy, keys, nil, records, _INFO1_READ|_INFO1_NOBINDATA)
err := clnt.batchExecute(policy, keys, cmd)
if err != nil && !policy.AllowPartialResults {
return nil, err
}
return records, err
} | go | func (clnt *Client) BatchGetHeader(policy *BatchPolicy, keys []*Key) ([]*Record, error) {
policy = clnt.getUsableBatchPolicy(policy)
// same array can be used without synchronization;
// when a key exists, the corresponding index will be set to record
records := make([]*Record, len(keys))
cmd := newBatchCommandGet(nil, nil, nil, policy, keys, nil, records, _INFO1_READ|_INFO1_NOBINDATA)
err := clnt.batchExecute(policy, keys, cmd)
if err != nil && !policy.AllowPartialResults {
return nil, err
}
return records, err
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"BatchGetHeader",
"(",
"policy",
"*",
"BatchPolicy",
",",
"keys",
"[",
"]",
"*",
"Key",
")",
"(",
"[",
"]",
"*",
"Record",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableBatchPolicy",
"(",
"poli... | // BatchGetHeader reads multiple record header data for specified keys in one batch request.
// The returned records are in positional order with the original key array order.
// If a key is not found, the positional record will be nil.
// The policy can be used to specify timeouts.
// If the policy is nil, the default relevant policy will be used. | [
"BatchGetHeader",
"reads",
"multiple",
"record",
"header",
"data",
"for",
"specified",
"keys",
"in",
"one",
"batch",
"request",
".",
"The",
"returned",
"records",
"are",
"in",
"positional",
"order",
"with",
"the",
"original",
"key",
"array",
"order",
".",
"If"... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L359-L373 |
9,870 | aerospike/aerospike-client-go | client.go | ScanNode | func (clnt *Client) ScanNode(apolicy *ScanPolicy, node *Node, namespace string, setName string, binNames ...string) (*Recordset, error) {
policy := *clnt.getUsableScanPolicy(apolicy)
// results channel must be async for performance
taskID := uint64(xornd.Int64())
res := newRecordset(policy.RecordQueueSize, 1, taskID)
go clnt.scanNode(&policy, node, res, namespace, setName, taskID, binNames...)
return res, nil
} | go | func (clnt *Client) ScanNode(apolicy *ScanPolicy, node *Node, namespace string, setName string, binNames ...string) (*Recordset, error) {
policy := *clnt.getUsableScanPolicy(apolicy)
// results channel must be async for performance
taskID := uint64(xornd.Int64())
res := newRecordset(policy.RecordQueueSize, 1, taskID)
go clnt.scanNode(&policy, node, res, namespace, setName, taskID, binNames...)
return res, nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"ScanNode",
"(",
"apolicy",
"*",
"ScanPolicy",
",",
"node",
"*",
"Node",
",",
"namespace",
"string",
",",
"setName",
"string",
",",
"binNames",
"...",
"string",
")",
"(",
"*",
"Recordset",
",",
"error",
")",
"{"... | // ScanNode reads all records in specified namespace and set for one node only.
// If the policy is nil, the default relevant policy will be used. | [
"ScanNode",
"reads",
"all",
"records",
"in",
"specified",
"namespace",
"and",
"set",
"for",
"one",
"node",
"only",
".",
"If",
"the",
"policy",
"is",
"nil",
"the",
"default",
"relevant",
"policy",
"will",
"be",
"used",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L434-L443 |
9,871 | aerospike/aerospike-client-go | client.go | RegisterUDF | func (clnt *Client) RegisterUDF(policy *WritePolicy, udfBody []byte, serverPath string, language Language) (*RegisterTask, error) {
policy = clnt.getUsableWritePolicy(policy)
content := base64.StdEncoding.EncodeToString(udfBody)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-put:filename=")
_, err = strCmd.WriteString(serverPath)
_, err = strCmd.WriteString(";content=")
_, err = strCmd.WriteString(content)
_, err = strCmd.WriteString(";content-len=")
_, err = strCmd.WriteString(strconv.Itoa(len(content)))
_, err = strCmd.WriteString(";udf-type=")
_, err = strCmd.WriteString(string(language))
_, err = strCmd.WriteString(";")
// Send UDF to one node. That node will distribute the UDF to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
res := make(map[string]string)
vals := strings.Split(response, ";")
for _, pair := range vals {
t := strings.SplitN(pair, "=", 2)
if len(t) == 2 {
res[t[0]] = t[1]
} else if len(t) == 1 {
res[t[0]] = ""
}
}
if _, exists := res["error"]; exists {
msg, _ := base64.StdEncoding.DecodeString(res["message"])
return nil, NewAerospikeError(COMMAND_REJECTED, fmt.Sprintf("Registration failed: %s\nFile: %s\nLine: %s\nMessage: %s",
res["error"], res["file"], res["line"], msg))
}
return NewRegisterTask(clnt.cluster, serverPath), nil
} | go | func (clnt *Client) RegisterUDF(policy *WritePolicy, udfBody []byte, serverPath string, language Language) (*RegisterTask, error) {
policy = clnt.getUsableWritePolicy(policy)
content := base64.StdEncoding.EncodeToString(udfBody)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-put:filename=")
_, err = strCmd.WriteString(serverPath)
_, err = strCmd.WriteString(";content=")
_, err = strCmd.WriteString(content)
_, err = strCmd.WriteString(";content-len=")
_, err = strCmd.WriteString(strconv.Itoa(len(content)))
_, err = strCmd.WriteString(";udf-type=")
_, err = strCmd.WriteString(string(language))
_, err = strCmd.WriteString(";")
// Send UDF to one node. That node will distribute the UDF to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
res := make(map[string]string)
vals := strings.Split(response, ";")
for _, pair := range vals {
t := strings.SplitN(pair, "=", 2)
if len(t) == 2 {
res[t[0]] = t[1]
} else if len(t) == 1 {
res[t[0]] = ""
}
}
if _, exists := res["error"]; exists {
msg, _ := base64.StdEncoding.DecodeString(res["message"])
return nil, NewAerospikeError(COMMAND_REJECTED, fmt.Sprintf("Registration failed: %s\nFile: %s\nLine: %s\nMessage: %s",
res["error"], res["file"], res["line"], msg))
}
return NewRegisterTask(clnt.cluster, serverPath), nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"RegisterUDF",
"(",
"policy",
"*",
"WritePolicy",
",",
"udfBody",
"[",
"]",
"byte",
",",
"serverPath",
"string",
",",
"language",
"Language",
")",
"(",
"*",
"RegisterTask",
",",
"error",
")",
"{",
"policy",
"=",
... | // RegisterUDF registers a package containing user defined functions with server.
// This asynchronous server call will return before command is complete.
// The user can optionally wait for command completion by using the returned
// RegisterTask instance.
//
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"RegisterUDF",
"registers",
"a",
"package",
"containing",
"user",
"defined",
"functions",
"with",
"server",
".",
"This",
"asynchronous",
"server",
"call",
"will",
"return",
"before",
"command",
"is",
"complete",
".",
"The",
"user",
"can",
"optionally",
"wait",
"... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L481-L522 |
9,872 | aerospike/aerospike-client-go | client.go | RemoveUDF | func (clnt *Client) RemoveUDF(policy *WritePolicy, udfName string) (*RemoveTask, error) {
policy = clnt.getUsableWritePolicy(policy)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-remove:filename=")
_, err = strCmd.WriteString(udfName)
_, err = strCmd.WriteString(";")
// Send command to one node. That node will distribute it to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
if response == "ok" {
return NewRemoveTask(clnt.cluster, udfName), nil
}
return nil, NewAerospikeError(SERVER_ERROR, response)
} | go | func (clnt *Client) RemoveUDF(policy *WritePolicy, udfName string) (*RemoveTask, error) {
policy = clnt.getUsableWritePolicy(policy)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-remove:filename=")
_, err = strCmd.WriteString(udfName)
_, err = strCmd.WriteString(";")
// Send command to one node. That node will distribute it to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
if response == "ok" {
return NewRemoveTask(clnt.cluster, udfName), nil
}
return nil, NewAerospikeError(SERVER_ERROR, response)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"RemoveUDF",
"(",
"policy",
"*",
"WritePolicy",
",",
"udfName",
"string",
")",
"(",
"*",
"RemoveTask",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableWritePolicy",
"(",
"policy",
")",
"\n",
"var",
... | // RemoveUDF removes a package containing user defined functions in the server.
// This asynchronous server call will return before command is complete.
// The user can optionally wait for command completion by using the returned
// RemoveTask instance.
//
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"RemoveUDF",
"removes",
"a",
"package",
"containing",
"user",
"defined",
"functions",
"in",
"the",
"server",
".",
"This",
"asynchronous",
"server",
"call",
"will",
"return",
"before",
"command",
"is",
"complete",
".",
"The",
"user",
"can",
"optionally",
"wait",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L531-L551 |
9,873 | aerospike/aerospike-client-go | client.go | ListUDF | func (clnt *Client) ListUDF(policy *BasePolicy) ([]*UDF, error) {
policy = clnt.getUsablePolicy(policy)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-list")
// Send command to one node. That node will distribute it to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
vals := strings.Split(response, ";")
res := make([]*UDF, 0, len(vals))
for _, udfInfo := range vals {
if strings.Trim(udfInfo, " ") == "" {
continue
}
udfParts := strings.Split(udfInfo, ",")
udf := &UDF{}
for _, values := range udfParts {
valueParts := strings.Split(values, "=")
if len(valueParts) == 2 {
switch valueParts[0] {
case "filename":
udf.Filename = valueParts[1]
case "hash":
udf.Hash = valueParts[1]
case "type":
udf.Language = Language(valueParts[1])
}
}
}
res = append(res, udf)
}
return res, nil
} | go | func (clnt *Client) ListUDF(policy *BasePolicy) ([]*UDF, error) {
policy = clnt.getUsablePolicy(policy)
var strCmd bytes.Buffer
// errors are to remove errcheck warnings
// they will always be nil as stated in golang docs
_, err := strCmd.WriteString("udf-list")
// Send command to one node. That node will distribute it to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return nil, err
}
response := responseMap[strCmd.String()]
vals := strings.Split(response, ";")
res := make([]*UDF, 0, len(vals))
for _, udfInfo := range vals {
if strings.Trim(udfInfo, " ") == "" {
continue
}
udfParts := strings.Split(udfInfo, ",")
udf := &UDF{}
for _, values := range udfParts {
valueParts := strings.Split(values, "=")
if len(valueParts) == 2 {
switch valueParts[0] {
case "filename":
udf.Filename = valueParts[1]
case "hash":
udf.Hash = valueParts[1]
case "type":
udf.Language = Language(valueParts[1])
}
}
}
res = append(res, udf)
}
return res, nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"ListUDF",
"(",
"policy",
"*",
"BasePolicy",
")",
"(",
"[",
"]",
"*",
"UDF",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsablePolicy",
"(",
"policy",
")",
"\n\n",
"var",
"strCmd",
"bytes",
".",
... | // ListUDF lists all packages containing user defined functions in the server.
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"ListUDF",
"lists",
"all",
"packages",
"containing",
"user",
"defined",
"functions",
"in",
"the",
"server",
".",
"This",
"method",
"is",
"only",
"supported",
"by",
"Aerospike",
"3",
"servers",
".",
"If",
"the",
"policy",
"is",
"nil",
"the",
"default",
"relev... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L556-L598 |
9,874 | aerospike/aerospike-client-go | client.go | ExecuteUDFNode | func (clnt *Client) ExecuteUDFNode(policy *QueryPolicy,
node *Node,
statement *Statement,
packageName string,
functionName string,
functionArgs ...Value,
) (*ExecuteTask, error) {
policy = clnt.getUsableQueryPolicy(policy)
if node == nil {
return nil, NewAerospikeError(SERVER_NOT_AVAILABLE, "ExecuteUDFNode failed because node is nil.")
}
statement.SetAggregateFunction(packageName, functionName, functionArgs, false)
command := newServerCommand(node, policy, statement)
err := command.Execute()
return NewExecuteTask(clnt.cluster, statement), err
} | go | func (clnt *Client) ExecuteUDFNode(policy *QueryPolicy,
node *Node,
statement *Statement,
packageName string,
functionName string,
functionArgs ...Value,
) (*ExecuteTask, error) {
policy = clnt.getUsableQueryPolicy(policy)
if node == nil {
return nil, NewAerospikeError(SERVER_NOT_AVAILABLE, "ExecuteUDFNode failed because node is nil.")
}
statement.SetAggregateFunction(packageName, functionName, functionArgs, false)
command := newServerCommand(node, policy, statement)
err := command.Execute()
return NewExecuteTask(clnt.cluster, statement), err
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"ExecuteUDFNode",
"(",
"policy",
"*",
"QueryPolicy",
",",
"node",
"*",
"Node",
",",
"statement",
"*",
"Statement",
",",
"packageName",
"string",
",",
"functionName",
"string",
",",
"functionArgs",
"...",
"Value",
",",... | // ExecuteUDFNode applies user defined function on records that match the statement filter on the specified node.
// Records are not returned to the client.
// This asynchronous server call will return before command is complete.
// The user can optionally wait for command completion by using the returned
// ExecuteTask instance.
//
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"ExecuteUDFNode",
"applies",
"user",
"defined",
"function",
"on",
"records",
"that",
"match",
"the",
"statement",
"filter",
"on",
"the",
"specified",
"node",
".",
"Records",
"are",
"not",
"returned",
"to",
"the",
"client",
".",
"This",
"asynchronous",
"server",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L678-L697 |
9,875 | aerospike/aerospike-client-go | client.go | QueryNode | func (clnt *Client) QueryNode(policy *QueryPolicy, node *Node, statement *Statement) (*Recordset, error) {
policy = clnt.getUsableQueryPolicy(policy)
// results channel must be async for performance
recSet := newRecordset(policy.RecordQueueSize, 1, statement.TaskId)
// copy policies to avoid race conditions
newPolicy := *policy
command := newQueryRecordCommand(node, &newPolicy, statement, recSet)
go func() {
command.Execute()
}()
return recSet, nil
} | go | func (clnt *Client) QueryNode(policy *QueryPolicy, node *Node, statement *Statement) (*Recordset, error) {
policy = clnt.getUsableQueryPolicy(policy)
// results channel must be async for performance
recSet := newRecordset(policy.RecordQueueSize, 1, statement.TaskId)
// copy policies to avoid race conditions
newPolicy := *policy
command := newQueryRecordCommand(node, &newPolicy, statement, recSet)
go func() {
command.Execute()
}()
return recSet, nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"QueryNode",
"(",
"policy",
"*",
"QueryPolicy",
",",
"node",
"*",
"Node",
",",
"statement",
"*",
"Statement",
")",
"(",
"*",
"Recordset",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableQueryPolicy",... | // QueryNode executes a query on a specific node and returns a recordset.
// The caller can concurrently pop records off the channel through the
// record channel.
//
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"QueryNode",
"executes",
"a",
"query",
"on",
"a",
"specific",
"node",
"and",
"returns",
"a",
"recordset",
".",
"The",
"caller",
"can",
"concurrently",
"pop",
"records",
"off",
"the",
"channel",
"through",
"the",
"record",
"channel",
".",
"This",
"method",
"i... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L740-L754 |
9,876 | aerospike/aerospike-client-go | client.go | CreateIndex | func (clnt *Client) CreateIndex(
policy *WritePolicy,
namespace string,
setName string,
indexName string,
binName string,
indexType IndexType,
) (*IndexTask, error) {
policy = clnt.getUsableWritePolicy(policy)
return clnt.CreateComplexIndex(policy, namespace, setName, indexName, binName, indexType, ICT_DEFAULT)
} | go | func (clnt *Client) CreateIndex(
policy *WritePolicy,
namespace string,
setName string,
indexName string,
binName string,
indexType IndexType,
) (*IndexTask, error) {
policy = clnt.getUsableWritePolicy(policy)
return clnt.CreateComplexIndex(policy, namespace, setName, indexName, binName, indexType, ICT_DEFAULT)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"CreateIndex",
"(",
"policy",
"*",
"WritePolicy",
",",
"namespace",
"string",
",",
"setName",
"string",
",",
"indexName",
"string",
",",
"binName",
"string",
",",
"indexType",
"IndexType",
",",
")",
"(",
"*",
"Index... | // CreateIndex creates a secondary index.
// This asynchronous server call will return before the command is complete.
// The user can optionally wait for command completion by using the returned
// IndexTask instance.
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"CreateIndex",
"creates",
"a",
"secondary",
"index",
".",
"This",
"asynchronous",
"server",
"call",
"will",
"return",
"before",
"the",
"command",
"is",
"complete",
".",
"The",
"user",
"can",
"optionally",
"wait",
"for",
"command",
"completion",
"by",
"using",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L762-L772 |
9,877 | aerospike/aerospike-client-go | client.go | DropIndex | func (clnt *Client) DropIndex(
policy *WritePolicy,
namespace string,
setName string,
indexName string,
) error {
policy = clnt.getUsableWritePolicy(policy)
var strCmd bytes.Buffer
_, err := strCmd.WriteString("sindex-delete:ns=")
_, err = strCmd.WriteString(namespace)
if len(setName) > 0 {
_, err = strCmd.WriteString(";set=")
_, err = strCmd.WriteString(setName)
}
_, err = strCmd.WriteString(";indexname=")
_, err = strCmd.WriteString(indexName)
// Send index command to one node. That node will distribute the command to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return err
}
response := responseMap[strCmd.String()]
if strings.ToUpper(response) == "OK" {
// Return task that could optionally be polled for completion.
task := NewDropIndexTask(clnt.cluster, namespace, indexName)
return <-task.OnComplete()
}
if strings.HasPrefix(response, "FAIL:201") {
// Index did not previously exist. Return without error.
return nil
}
return NewAerospikeError(INDEX_GENERIC, "Drop index failed: "+response)
} | go | func (clnt *Client) DropIndex(
policy *WritePolicy,
namespace string,
setName string,
indexName string,
) error {
policy = clnt.getUsableWritePolicy(policy)
var strCmd bytes.Buffer
_, err := strCmd.WriteString("sindex-delete:ns=")
_, err = strCmd.WriteString(namespace)
if len(setName) > 0 {
_, err = strCmd.WriteString(";set=")
_, err = strCmd.WriteString(setName)
}
_, err = strCmd.WriteString(";indexname=")
_, err = strCmd.WriteString(indexName)
// Send index command to one node. That node will distribute the command to other nodes.
responseMap, err := clnt.sendInfoCommand(policy.TotalTimeout, strCmd.String())
if err != nil {
return err
}
response := responseMap[strCmd.String()]
if strings.ToUpper(response) == "OK" {
// Return task that could optionally be polled for completion.
task := NewDropIndexTask(clnt.cluster, namespace, indexName)
return <-task.OnComplete()
}
if strings.HasPrefix(response, "FAIL:201") {
// Index did not previously exist. Return without error.
return nil
}
return NewAerospikeError(INDEX_GENERIC, "Drop index failed: "+response)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"DropIndex",
"(",
"policy",
"*",
"WritePolicy",
",",
"namespace",
"string",
",",
"setName",
"string",
",",
"indexName",
"string",
",",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableWritePolicy",
"(",
"pol... | // DropIndex deletes a secondary index. It will block until index is dropped on all nodes.
// This method is only supported by Aerospike 3 servers.
// If the policy is nil, the default relevant policy will be used. | [
"DropIndex",
"deletes",
"a",
"secondary",
"index",
".",
"It",
"will",
"block",
"until",
"index",
"is",
"dropped",
"on",
"all",
"nodes",
".",
"This",
"method",
"is",
"only",
"supported",
"by",
"Aerospike",
"3",
"servers",
".",
"If",
"the",
"policy",
"is",
... | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L839-L877 |
9,878 | aerospike/aerospike-client-go | client.go | DropUser | func (clnt *Client) DropUser(policy *AdminPolicy, user string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.dropUser(clnt.cluster, policy, user)
} | go | func (clnt *Client) DropUser(policy *AdminPolicy, user string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.dropUser(clnt.cluster, policy, user)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"DropUser",
"(",
"policy",
"*",
"AdminPolicy",
",",
"user",
"string",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",
":=",
"newAdminCommand",
"(",
"nil"... | // DropUser removes a user from the cluster. | [
"DropUser",
"removes",
"a",
"user",
"from",
"the",
"cluster",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L958-L963 |
9,879 | aerospike/aerospike-client-go | client.go | ChangePassword | func (clnt *Client) ChangePassword(policy *AdminPolicy, user string, password string) error {
policy = clnt.getUsableAdminPolicy(policy)
if clnt.cluster.user == "" {
return NewAerospikeError(INVALID_USER)
}
hash, err := hashPassword(password)
if err != nil {
return err
}
command := newAdminCommand(nil)
if user == clnt.cluster.user {
// Change own password.
if err := command.changePassword(clnt.cluster, policy, user, hash); err != nil {
return err
}
} else {
// Change other user's password by user admin.
if err := command.setPassword(clnt.cluster, policy, user, hash); err != nil {
return err
}
}
clnt.cluster.changePassword(user, password, hash)
return nil
} | go | func (clnt *Client) ChangePassword(policy *AdminPolicy, user string, password string) error {
policy = clnt.getUsableAdminPolicy(policy)
if clnt.cluster.user == "" {
return NewAerospikeError(INVALID_USER)
}
hash, err := hashPassword(password)
if err != nil {
return err
}
command := newAdminCommand(nil)
if user == clnt.cluster.user {
// Change own password.
if err := command.changePassword(clnt.cluster, policy, user, hash); err != nil {
return err
}
} else {
// Change other user's password by user admin.
if err := command.setPassword(clnt.cluster, policy, user, hash); err != nil {
return err
}
}
clnt.cluster.changePassword(user, password, hash)
return nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"ChangePassword",
"(",
"policy",
"*",
"AdminPolicy",
",",
"user",
"string",
",",
"password",
"string",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"if",
"clnt",... | // ChangePassword changes a user's password. Clear-text password will be hashed using bcrypt before sending to server. | [
"ChangePassword",
"changes",
"a",
"user",
"s",
"password",
".",
"Clear",
"-",
"text",
"password",
"will",
"be",
"hashed",
"using",
"bcrypt",
"before",
"sending",
"to",
"server",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L966-L994 |
9,880 | aerospike/aerospike-client-go | client.go | GrantRoles | func (clnt *Client) GrantRoles(policy *AdminPolicy, user string, roles []string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.grantRoles(clnt.cluster, policy, user, roles)
} | go | func (clnt *Client) GrantRoles(policy *AdminPolicy, user string, roles []string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.grantRoles(clnt.cluster, policy, user, roles)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"GrantRoles",
"(",
"policy",
"*",
"AdminPolicy",
",",
"user",
"string",
",",
"roles",
"[",
"]",
"string",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command... | // GrantRoles adds roles to user's list of roles. | [
"GrantRoles",
"adds",
"roles",
"to",
"user",
"s",
"list",
"of",
"roles",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L997-L1002 |
9,881 | aerospike/aerospike-client-go | client.go | RevokeRoles | func (clnt *Client) RevokeRoles(policy *AdminPolicy, user string, roles []string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.revokeRoles(clnt.cluster, policy, user, roles)
} | go | func (clnt *Client) RevokeRoles(policy *AdminPolicy, user string, roles []string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.revokeRoles(clnt.cluster, policy, user, roles)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"RevokeRoles",
"(",
"policy",
"*",
"AdminPolicy",
",",
"user",
"string",
",",
"roles",
"[",
"]",
"string",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"comman... | // RevokeRoles removes roles from user's list of roles. | [
"RevokeRoles",
"removes",
"roles",
"from",
"user",
"s",
"list",
"of",
"roles",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1005-L1010 |
9,882 | aerospike/aerospike-client-go | client.go | QueryUser | func (clnt *Client) QueryUser(policy *AdminPolicy, user string) (*UserRoles, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryUser(clnt.cluster, policy, user)
} | go | func (clnt *Client) QueryUser(policy *AdminPolicy, user string) (*UserRoles, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryUser(clnt.cluster, policy, user)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"QueryUser",
"(",
"policy",
"*",
"AdminPolicy",
",",
"user",
"string",
")",
"(",
"*",
"UserRoles",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",... | // QueryUser retrieves roles for a given user. | [
"QueryUser",
"retrieves",
"roles",
"for",
"a",
"given",
"user",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1013-L1018 |
9,883 | aerospike/aerospike-client-go | client.go | QueryUsers | func (clnt *Client) QueryUsers(policy *AdminPolicy) ([]*UserRoles, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryUsers(clnt.cluster, policy)
} | go | func (clnt *Client) QueryUsers(policy *AdminPolicy) ([]*UserRoles, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryUsers(clnt.cluster, policy)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"QueryUsers",
"(",
"policy",
"*",
"AdminPolicy",
")",
"(",
"[",
"]",
"*",
"UserRoles",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",
":=",
"ne... | // QueryUsers retrieves all users and their roles. | [
"QueryUsers",
"retrieves",
"all",
"users",
"and",
"their",
"roles",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1021-L1026 |
9,884 | aerospike/aerospike-client-go | client.go | QueryRole | func (clnt *Client) QueryRole(policy *AdminPolicy, role string) (*Role, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryRole(clnt.cluster, policy, role)
} | go | func (clnt *Client) QueryRole(policy *AdminPolicy, role string) (*Role, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryRole(clnt.cluster, policy, role)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"QueryRole",
"(",
"policy",
"*",
"AdminPolicy",
",",
"role",
"string",
")",
"(",
"*",
"Role",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",
":... | // QueryRole retrieves privileges for a given role. | [
"QueryRole",
"retrieves",
"privileges",
"for",
"a",
"given",
"role",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1029-L1034 |
9,885 | aerospike/aerospike-client-go | client.go | QueryRoles | func (clnt *Client) QueryRoles(policy *AdminPolicy) ([]*Role, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryRoles(clnt.cluster, policy)
} | go | func (clnt *Client) QueryRoles(policy *AdminPolicy) ([]*Role, error) {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.queryRoles(clnt.cluster, policy)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"QueryRoles",
"(",
"policy",
"*",
"AdminPolicy",
")",
"(",
"[",
"]",
"*",
"Role",
",",
"error",
")",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",
":=",
"newAdmi... | // QueryRoles retrieves all roles and their privileges. | [
"QueryRoles",
"retrieves",
"all",
"roles",
"and",
"their",
"privileges",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1037-L1042 |
9,886 | aerospike/aerospike-client-go | client.go | CreateRole | func (clnt *Client) CreateRole(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.createRole(clnt.cluster, policy, roleName, privileges)
} | go | func (clnt *Client) CreateRole(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.createRole(clnt.cluster, policy, roleName, privileges)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"CreateRole",
"(",
"policy",
"*",
"AdminPolicy",
",",
"roleName",
"string",
",",
"privileges",
"[",
"]",
"Privilege",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n"... | // CreateRole creates a user-defined role. | [
"CreateRole",
"creates",
"a",
"user",
"-",
"defined",
"role",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1045-L1050 |
9,887 | aerospike/aerospike-client-go | client.go | DropRole | func (clnt *Client) DropRole(policy *AdminPolicy, roleName string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.dropRole(clnt.cluster, policy, roleName)
} | go | func (clnt *Client) DropRole(policy *AdminPolicy, roleName string) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.dropRole(clnt.cluster, policy, roleName)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"DropRole",
"(",
"policy",
"*",
"AdminPolicy",
",",
"roleName",
"string",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"\n\n",
"command",
":=",
"newAdminCommand",
"(",
"... | // DropRole removes a user-defined role. | [
"DropRole",
"removes",
"a",
"user",
"-",
"defined",
"role",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1053-L1058 |
9,888 | aerospike/aerospike-client-go | client.go | GrantPrivileges | func (clnt *Client) GrantPrivileges(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.grantPrivileges(clnt.cluster, policy, roleName, privileges)
} | go | func (clnt *Client) GrantPrivileges(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.grantPrivileges(clnt.cluster, policy, roleName, privileges)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"GrantPrivileges",
"(",
"policy",
"*",
"AdminPolicy",
",",
"roleName",
"string",
",",
"privileges",
"[",
"]",
"Privilege",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
"... | // GrantPrivileges grant privileges to a user-defined role. | [
"GrantPrivileges",
"grant",
"privileges",
"to",
"a",
"user",
"-",
"defined",
"role",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1061-L1066 |
9,889 | aerospike/aerospike-client-go | client.go | RevokePrivileges | func (clnt *Client) RevokePrivileges(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.revokePrivileges(clnt.cluster, policy, roleName, privileges)
} | go | func (clnt *Client) RevokePrivileges(policy *AdminPolicy, roleName string, privileges []Privilege) error {
policy = clnt.getUsableAdminPolicy(policy)
command := newAdminCommand(nil)
return command.revokePrivileges(clnt.cluster, policy, roleName, privileges)
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"RevokePrivileges",
"(",
"policy",
"*",
"AdminPolicy",
",",
"roleName",
"string",
",",
"privileges",
"[",
"]",
"Privilege",
")",
"error",
"{",
"policy",
"=",
"clnt",
".",
"getUsableAdminPolicy",
"(",
"policy",
")",
... | // RevokePrivileges revokes privileges from a user-defined role. | [
"RevokePrivileges",
"revokes",
"privileges",
"from",
"a",
"user",
"-",
"defined",
"role",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1069-L1074 |
9,890 | aerospike/aerospike-client-go | client.go | String | func (clnt *Client) String() string {
if clnt.cluster != nil {
return clnt.cluster.String()
}
return ""
} | go | func (clnt *Client) String() string {
if clnt.cluster != nil {
return clnt.cluster.String()
}
return ""
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"String",
"(",
")",
"string",
"{",
"if",
"clnt",
".",
"cluster",
"!=",
"nil",
"{",
"return",
"clnt",
".",
"cluster",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String implements the Stringer interface for client | [
"String",
"implements",
"the",
"Stringer",
"interface",
"for",
"client"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1082-L1087 |
9,891 | aerospike/aerospike-client-go | client.go | Stats | func (clnt *Client) Stats() (map[string]interface{}, error) {
resStats := clnt.cluster.statsCopy()
clusterStats := nodeStats{}
for _, stats := range resStats {
clusterStats.aggregate(&stats)
}
resStats["cluster-aggregated-stats"] = clusterStats
b, err := json.Marshal(resStats)
if err != nil {
return nil, err
}
res := map[string]interface{}{}
err = json.Unmarshal(b, &res)
if err != nil {
return nil, err
}
res["open-connections"] = clusterStats.ConnectionsOpen
return res, nil
} | go | func (clnt *Client) Stats() (map[string]interface{}, error) {
resStats := clnt.cluster.statsCopy()
clusterStats := nodeStats{}
for _, stats := range resStats {
clusterStats.aggregate(&stats)
}
resStats["cluster-aggregated-stats"] = clusterStats
b, err := json.Marshal(resStats)
if err != nil {
return nil, err
}
res := map[string]interface{}{}
err = json.Unmarshal(b, &res)
if err != nil {
return nil, err
}
res["open-connections"] = clusterStats.ConnectionsOpen
return res, nil
} | [
"func",
"(",
"clnt",
"*",
"Client",
")",
"Stats",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"resStats",
":=",
"clnt",
".",
"cluster",
".",
"statsCopy",
"(",
")",
"\n\n",
"clusterStats",
":=",
"nodeStats"... | // Stats returns internal statistics regarding the inner state of the client and the cluster. | [
"Stats",
"returns",
"internal",
"statistics",
"regarding",
"the",
"inner",
"state",
"of",
"the",
"client",
"and",
"the",
"cluster",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/client.go#L1090-L1114 |
9,892 | aerospike/aerospike-client-go | utils/utils.go | ReadFileEncodeBase64 | func ReadFileEncodeBase64(filename string) (string, error) {
// read whole the file
b, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(b), nil
} | go | func ReadFileEncodeBase64(filename string) (string, error) {
// read whole the file
b, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(b), nil
} | [
"func",
"ReadFileEncodeBase64",
"(",
"filename",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// read whole the file",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
... | // ReadFileEncodeBase64 readfs a file from disk and encodes it as base64 | [
"ReadFileEncodeBase64",
"readfs",
"a",
"file",
"from",
"disk",
"and",
"encodes",
"it",
"as",
"base64"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/utils.go#L9-L17 |
9,893 | aerospike/aerospike-client-go | types/epoc.go | TTL | func TTL(secsFromCitrusLeafEpoc uint32) uint32 {
switch secsFromCitrusLeafEpoc {
// don't convert magic values
case 0: // when set to don't expire, this value is returned
return math.MaxUint32
default:
// Record may not have expired on server, but delay or clock differences may
// cause it to look expired on client. Floor at 1, not 0, to avoid old
// "never expires" interpretation.
now := time.Now().Unix()
expiration := int64(CITRUSLEAF_EPOCH + secsFromCitrusLeafEpoc)
if expiration < 0 || expiration > now {
return uint32(expiration - now)
}
return 1
}
} | go | func TTL(secsFromCitrusLeafEpoc uint32) uint32 {
switch secsFromCitrusLeafEpoc {
// don't convert magic values
case 0: // when set to don't expire, this value is returned
return math.MaxUint32
default:
// Record may not have expired on server, but delay or clock differences may
// cause it to look expired on client. Floor at 1, not 0, to avoid old
// "never expires" interpretation.
now := time.Now().Unix()
expiration := int64(CITRUSLEAF_EPOCH + secsFromCitrusLeafEpoc)
if expiration < 0 || expiration > now {
return uint32(expiration - now)
}
return 1
}
} | [
"func",
"TTL",
"(",
"secsFromCitrusLeafEpoc",
"uint32",
")",
"uint32",
"{",
"switch",
"secsFromCitrusLeafEpoc",
"{",
"// don't convert magic values",
"case",
"0",
":",
"// when set to don't expire, this value is returned",
"return",
"math",
".",
"MaxUint32",
"\n",
"default"... | // TTL converts an Expiration time from citrusleaf epoc to TTL in seconds. | [
"TTL",
"converts",
"an",
"Expiration",
"time",
"from",
"citrusleaf",
"epoc",
"to",
"TTL",
"in",
"seconds",
"."
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/types/epoc.go#L14-L30 |
9,894 | aerospike/aerospike-client-go | utils/buffer/buffer.go | BytesToHexString | func BytesToHexString(buf []byte) string {
hlist := make([]byte, 3*len(buf))
for i := range buf {
hex := fmt.Sprintf("%02x ", buf[i])
idx := i * 3
copy(hlist[idx:], hex)
}
return string(hlist)
} | go | func BytesToHexString(buf []byte) string {
hlist := make([]byte, 3*len(buf))
for i := range buf {
hex := fmt.Sprintf("%02x ", buf[i])
idx := i * 3
copy(hlist[idx:], hex)
}
return string(hlist)
} | [
"func",
"BytesToHexString",
"(",
"buf",
"[",
"]",
"byte",
")",
"string",
"{",
"hlist",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
"*",
"len",
"(",
"buf",
")",
")",
"\n\n",
"for",
"i",
":=",
"range",
"buf",
"{",
"hex",
":=",
"fmt",
".",
"Spr... | // BytesToHexString converts a byte slice into a hex string | [
"BytesToHexString",
"converts",
"a",
"byte",
"slice",
"into",
"a",
"hex",
"string"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L51-L60 |
9,895 | aerospike/aerospike-client-go | utils/buffer/buffer.go | LittleBytesToInt32 | func LittleBytesToInt32(buf []byte, offset int) int32 {
l := len(buf[offset:])
if l > uint32sz {
l = uint32sz
}
r := int32(binary.LittleEndian.Uint32(buf[offset : offset+l]))
return r
} | go | func LittleBytesToInt32(buf []byte, offset int) int32 {
l := len(buf[offset:])
if l > uint32sz {
l = uint32sz
}
r := int32(binary.LittleEndian.Uint32(buf[offset : offset+l]))
return r
} | [
"func",
"LittleBytesToInt32",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int32",
"{",
"l",
":=",
"len",
"(",
"buf",
"[",
"offset",
":",
"]",
")",
"\n",
"if",
"l",
">",
"uint32sz",
"{",
"l",
"=",
"uint32sz",
"\n",
"}",
"\n",
"r",
... | // LittleBytesToInt32 converts a slice into int32; only maximum of 4 bytes will be used | [
"LittleBytesToInt32",
"converts",
"a",
"slice",
"into",
"int32",
";",
"only",
"maximum",
"of",
"4",
"bytes",
"will",
"be",
"used"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L63-L70 |
9,896 | aerospike/aerospike-client-go | utils/buffer/buffer.go | BytesToInt64 | func BytesToInt64(buf []byte, offset int) int64 {
l := len(buf[offset:])
if l > uint64sz {
l = uint64sz
}
r := int64(binary.BigEndian.Uint64(buf[offset : offset+l]))
return r
} | go | func BytesToInt64(buf []byte, offset int) int64 {
l := len(buf[offset:])
if l > uint64sz {
l = uint64sz
}
r := int64(binary.BigEndian.Uint64(buf[offset : offset+l]))
return r
} | [
"func",
"BytesToInt64",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int64",
"{",
"l",
":=",
"len",
"(",
"buf",
"[",
"offset",
":",
"]",
")",
"\n",
"if",
"l",
">",
"uint64sz",
"{",
"l",
"=",
"uint64sz",
"\n",
"}",
"\n",
"r",
":=",
... | // BytesToInt64 converts a slice into int64; only maximum of 8 bytes will be used | [
"BytesToInt64",
"converts",
"a",
"slice",
"into",
"int64",
";",
"only",
"maximum",
"of",
"8",
"bytes",
"will",
"be",
"used"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L73-L80 |
9,897 | aerospike/aerospike-client-go | utils/buffer/buffer.go | BytesToInt32 | func BytesToInt32(buf []byte, offset int) int32 {
return int32(binary.BigEndian.Uint32(buf[offset : offset+uint32sz]))
} | go | func BytesToInt32(buf []byte, offset int) int32 {
return int32(binary.BigEndian.Uint32(buf[offset : offset+uint32sz]))
} | [
"func",
"BytesToInt32",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int32",
"{",
"return",
"int32",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"offset",
":",
"offset",
"+",
"uint32sz",
"]",
")",
")",
"\n",
"}"
] | // BytesToInt32 converts a slice into int32; only maximum of 4 bytes will be used | [
"BytesToInt32",
"converts",
"a",
"slice",
"into",
"int32",
";",
"only",
"maximum",
"of",
"4",
"bytes",
"will",
"be",
"used"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L100-L102 |
9,898 | aerospike/aerospike-client-go | utils/buffer/buffer.go | BytesToUint32 | func BytesToUint32(buf []byte, offset int) uint32 {
return binary.BigEndian.Uint32(buf[offset : offset+uint32sz])
} | go | func BytesToUint32(buf []byte, offset int) uint32 {
return binary.BigEndian.Uint32(buf[offset : offset+uint32sz])
} | [
"func",
"BytesToUint32",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"uint32",
"{",
"return",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"offset",
":",
"offset",
"+",
"uint32sz",
"]",
")",
"\n",
"}"
] | // BytesToUint32 converts a slice into uint32; only maximum of 4 bytes will be used | [
"BytesToUint32",
"converts",
"a",
"slice",
"into",
"uint32",
";",
"only",
"maximum",
"of",
"4",
"bytes",
"will",
"be",
"used"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L105-L107 |
9,899 | aerospike/aerospike-client-go | utils/buffer/buffer.go | BytesToInt16 | func BytesToInt16(buf []byte, offset int) int16 {
return int16(binary.BigEndian.Uint16(buf[offset : offset+uint16sz]))
} | go | func BytesToInt16(buf []byte, offset int) int16 {
return int16(binary.BigEndian.Uint16(buf[offset : offset+uint16sz]))
} | [
"func",
"BytesToInt16",
"(",
"buf",
"[",
"]",
"byte",
",",
"offset",
"int",
")",
"int16",
"{",
"return",
"int16",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"buf",
"[",
"offset",
":",
"offset",
"+",
"uint16sz",
"]",
")",
")",
"\n",
"}"
] | // BytesToInt16 converts a slice of bytes to an int16 | [
"BytesToInt16",
"converts",
"a",
"slice",
"of",
"bytes",
"to",
"an",
"int16"
] | f257953b1650505cf4c357fcc4f032d160ebb07e | https://github.com/aerospike/aerospike-client-go/blob/f257953b1650505cf4c357fcc4f032d160ebb07e/utils/buffer/buffer.go#L110-L112 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.