id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2,100 | cloudflare/golibs | kt/kt.go | Get | func (c *Conn) Get(key string) (string, error) {
s, err := c.GetBytes(key)
if err != nil {
return "", err
}
return string(s), nil
} | go | func (c *Conn) Get(key string) (string, error) {
s, err := c.GetBytes(key)
if err != nil {
return "", err
}
return string(s), nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"c",
".",
"GetBytes",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
... | // Get retrieves the data stored at key. ErrNotFound is
// returned if no such data exists | [
"Get",
"retrieves",
"the",
"data",
"stored",
"at",
"key",
".",
"ErrNotFound",
"is",
"returned",
"if",
"no",
"such",
"data",
"exists"
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L277-L283 |
2,101 | cloudflare/golibs | kt/kt.go | Set | func (c *Conn) Set(key string, value []byte) error {
code, body, err := c.doREST("PUT", key, value)
if err != nil {
return err
}
if code != 201 {
return &Error{string(body), code}
}
return nil
} | go | func (c *Conn) Set(key string, value []byte) error {
code, body, err := c.doREST("PUT", key, value)
if err != nil {
return err
}
if code != 201 {
return &Error{string(body), code}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"code",
",",
"body",
",",
"err",
":=",
"c",
".",
"doREST",
"(",
"\"",
"\"",
",",
"key",
",",
"value",
")",
"\n",
"if",
"err",
... | // Set stores the data at key | [
"Set",
"stores",
"the",
"data",
"at",
"key"
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L305-L315 |
2,102 | cloudflare/golibs | kt/kt.go | GetBulkBytes | func (c *Conn) GetBulkBytes(keys map[string][]byte) error {
// The format for querying multiple keys in KT is to send a
// TSV value for each key with a _ as a prefix.
// KT then returns the value as a TSV set with _ in front of the keys
keystransmit := make([]KV, 0, len(keys))
for k, _ := range keys {
// we se... | go | func (c *Conn) GetBulkBytes(keys map[string][]byte) error {
// The format for querying multiple keys in KT is to send a
// TSV value for each key with a _ as a prefix.
// KT then returns the value as a TSV set with _ in front of the keys
keystransmit := make([]KV, 0, len(keys))
for k, _ := range keys {
// we se... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetBulkBytes",
"(",
"keys",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"// The format for querying multiple keys in KT is to send a",
"// TSV value for each key with a _ as a prefix.",
"// KT then returns the value a... | // GetBulkBytes retrieves the keys in the map. The results will be filled in on function return.
// If a key was not found in the database, it will be removed from the map. | [
"GetBulkBytes",
"retrieves",
"the",
"keys",
"in",
"the",
"map",
".",
"The",
"results",
"will",
"be",
"filled",
"in",
"on",
"function",
"return",
".",
"If",
"a",
"key",
"was",
"not",
"found",
"in",
"the",
"database",
"it",
"will",
"be",
"removed",
"from",... | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L321-L353 |
2,103 | cloudflare/golibs | kt/kt.go | SetBulk | func (c *Conn) SetBulk(values map[string]string) (int64, error) {
vals := make([]KV, 0, len(values))
for k, v := range values {
vals = append(vals, KV{"_" + k, []byte(v)})
}
code, m, err := c.doRPC("/rpc/set_bulk", vals)
if err != nil {
return 0, err
}
if code != 200 {
return 0, makeError(m)
}
return str... | go | func (c *Conn) SetBulk(values map[string]string) (int64, error) {
vals := make([]KV, 0, len(values))
for k, v := range values {
vals = append(vals, KV{"_" + k, []byte(v)})
}
code, m, err := c.doRPC("/rpc/set_bulk", vals)
if err != nil {
return 0, err
}
if code != 200 {
return 0, makeError(m)
}
return str... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetBulk",
"(",
"values",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"vals",
":=",
"make",
"(",
"[",
"]",
"KV",
",",
"0",
",",
"len",
"(",
"values",
")",
")",
"\n",
"for... | // SetBulk stores the values in the map. | [
"SetBulk",
"stores",
"the",
"values",
"in",
"the",
"map",
"."
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L356-L369 |
2,104 | cloudflare/golibs | kt/kt.go | RemoveBulk | func (c *Conn) RemoveBulk(keys []string) (int64, error) {
vals := make([]KV, 0, len(keys))
for _, k := range keys {
vals = append(vals, KV{"_" + k, zeroslice})
}
code, m, err := c.doRPC("/rpc/remove_bulk", vals)
if err != nil {
return 0, err
}
if code != 200 {
return 0, makeError(m)
}
return strconv.Pars... | go | func (c *Conn) RemoveBulk(keys []string) (int64, error) {
vals := make([]KV, 0, len(keys))
for _, k := range keys {
vals = append(vals, KV{"_" + k, zeroslice})
}
code, m, err := c.doRPC("/rpc/remove_bulk", vals)
if err != nil {
return 0, err
}
if code != 200 {
return 0, makeError(m)
}
return strconv.Pars... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RemoveBulk",
"(",
"keys",
"[",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"vals",
":=",
"make",
"(",
"[",
"]",
"KV",
",",
"0",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"for",
"_",
",",
"k"... | // RemoveBulk deletes the values | [
"RemoveBulk",
"deletes",
"the",
"values"
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L372-L385 |
2,105 | cloudflare/golibs | kt/kt.go | MatchPrefix | func (c *Conn) MatchPrefix(key string, maxrecords int64) ([]string, error) {
keystransmit := []KV{
{"prefix", []byte(key)},
{"max", []byte(strconv.FormatInt(maxrecords, 10))},
}
code, m, err := c.doRPC("/rpc/match_prefix", keystransmit)
if err != nil {
return nil, err
}
if code != 200 {
return nil, makeEr... | go | func (c *Conn) MatchPrefix(key string, maxrecords int64) ([]string, error) {
keystransmit := []KV{
{"prefix", []byte(key)},
{"max", []byte(strconv.FormatInt(maxrecords, 10))},
}
code, m, err := c.doRPC("/rpc/match_prefix", keystransmit)
if err != nil {
return nil, err
}
if code != 200 {
return nil, makeEr... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"MatchPrefix",
"(",
"key",
"string",
",",
"maxrecords",
"int64",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"keystransmit",
":=",
"[",
"]",
"KV",
"{",
"{",
"\"",
"\"",
",",
"[",
"]",
"byte",
"(",
"... | // MatchPrefix performs the match_prefix operation against the server
// It returns a sorted list of strings.
// The error may be ErrSuccess in the case that no records were found.
// This is for compatibility with the old gokabinet library. | [
"MatchPrefix",
"performs",
"the",
"match_prefix",
"operation",
"against",
"the",
"server",
"It",
"returns",
"a",
"sorted",
"list",
"of",
"strings",
".",
"The",
"error",
"may",
"be",
"ErrSuccess",
"in",
"the",
"case",
"that",
"no",
"records",
"were",
"found",
... | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L391-L414 |
2,106 | cloudflare/golibs | kt/kt.go | doRPC | func (c *Conn) doRPC(path string, values []KV) (code int, vals []KV, err error) {
url := &url.URL{
Scheme: c.scheme,
Host: c.host,
Path: path,
}
body, enc := TSVEncode(values)
headers := identityheaders
if enc == Base64Enc {
headers = base64headers
}
resp, t, err := c.roundTrip("POST", url, headers, ... | go | func (c *Conn) doRPC(path string, values []KV) (code int, vals []KV, err error) {
url := &url.URL{
Scheme: c.scheme,
Host: c.host,
Path: path,
}
body, enc := TSVEncode(values)
headers := identityheaders
if enc == Base64Enc {
headers = base64headers
}
resp, t, err := c.roundTrip("POST", url, headers, ... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"doRPC",
"(",
"path",
"string",
",",
"values",
"[",
"]",
"KV",
")",
"(",
"code",
"int",
",",
"vals",
"[",
"]",
"KV",
",",
"err",
"error",
")",
"{",
"url",
":=",
"&",
"url",
".",
"URL",
"{",
"Scheme",
":",
... | // Do an RPC call against the KT endpoint. | [
"Do",
"an",
"RPC",
"call",
"against",
"the",
"KT",
"endpoint",
"."
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L434-L462 |
2,107 | cloudflare/golibs | kt/kt.go | DecodeValues | func DecodeValues(buf []byte, contenttype string) ([]KV, error) {
if len(buf) == 0 {
return nil, nil
}
// Ideally, we should parse the mime media type here,
// but this is an expensive operation because mime is just
// that awful.
//
// KT can return values in 3 different formats, Tab separated values (TSV) wi... | go | func DecodeValues(buf []byte, contenttype string) ([]KV, error) {
if len(buf) == 0 {
return nil, nil
}
// Ideally, we should parse the mime media type here,
// but this is an expensive operation because mime is just
// that awful.
//
// KT can return values in 3 different formats, Tab separated values (TSV) wi... | [
"func",
"DecodeValues",
"(",
"buf",
"[",
"]",
"byte",
",",
"contenttype",
"string",
")",
"(",
"[",
"]",
"KV",
",",
"error",
")",
"{",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"// Ideally, we should... | // DecodeValues takes a response from an KT RPC call decodes it into a list of key
// value pairs. | [
"DecodeValues",
"takes",
"a",
"response",
"from",
"an",
"KT",
"RPC",
"call",
"decodes",
"it",
"into",
"a",
"list",
"of",
"key",
"value",
"pairs",
"."
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L575-L633 |
2,108 | cloudflare/golibs | kt/kt.go | base64Decode | func base64Decode(b []byte) []byte {
n, _ := base64.StdEncoding.Decode(b, b)
return b[:n]
} | go | func base64Decode(b []byte) []byte {
n, _ := base64.StdEncoding.Decode(b, b)
return b[:n]
} | [
"func",
"base64Decode",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"n",
",",
"_",
":=",
"base64",
".",
"StdEncoding",
".",
"Decode",
"(",
"b",
",",
"b",
")",
"\n",
"return",
"b",
"[",
":",
"n",
"]",
"\n",
"}"
] | // Base64 decode each of the field | [
"Base64",
"decode",
"each",
"of",
"the",
"field"
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L647-L650 |
2,109 | cloudflare/golibs | kt/kt.go | urlDecode | func urlDecode(b []byte) []byte {
res := b
resi := 0
for i := 0; i < len(b); i++ {
if b[i] != '%' {
res[resi] = b[i]
resi++
continue
}
res[resi] = unhex(b[i+1])<<4 | unhex(b[i+2])
resi++
i += 2
}
return res[:resi]
} | go | func urlDecode(b []byte) []byte {
res := b
resi := 0
for i := 0; i < len(b); i++ {
if b[i] != '%' {
res[resi] = b[i]
resi++
continue
}
res[resi] = unhex(b[i+1])<<4 | unhex(b[i+2])
resi++
i += 2
}
return res[:resi]
} | [
"func",
"urlDecode",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"res",
":=",
"b",
"\n",
"resi",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"b",
")",
";",
"i",
"++",
"{",
"if",
"b",
"[",
"i",
"]",
"!=... | // Decode % escaped URL format | [
"Decode",
"%",
"escaped",
"URL",
"format"
] | 4efefffc6d5c2168e1c209e44dad549e0674e7a3 | https://github.com/cloudflare/golibs/blob/4efefffc6d5c2168e1c209e44dad549e0674e7a3/kt/kt.go#L653-L667 |
2,110 | mattbaird/elastigo | lib/indicesdeletemapping.go | DeleteMapping | func (c *Conn) DeleteMapping(index string, typeName string) (BaseResponse, error) {
var retval BaseResponse
if len(index) == 0 {
return retval, fmt.Errorf("You must specify at least one index to delete a mapping from")
}
if len(typeName) == 0 {
return retval, fmt.Errorf("You must specify at least one mapping ... | go | func (c *Conn) DeleteMapping(index string, typeName string) (BaseResponse, error) {
var retval BaseResponse
if len(index) == 0 {
return retval, fmt.Errorf("You must specify at least one index to delete a mapping from")
}
if len(typeName) == 0 {
return retval, fmt.Errorf("You must specify at least one mapping ... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"DeleteMapping",
"(",
"index",
"string",
",",
"typeName",
"string",
")",
"(",
"BaseResponse",
",",
"error",
")",
"{",
"var",
"retval",
"BaseResponse",
"\n\n",
"if",
"len",
"(",
"index",
")",
"==",
"0",
"{",
"return",... | // The delete API allows you to delete a mapping through an API. | [
"The",
"delete",
"API",
"allows",
"you",
"to",
"delete",
"a",
"mapping",
"through",
"an",
"API",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/indicesdeletemapping.go#L20-L45 |
2,111 | mattbaird/elastigo | lib/corebulk.go | NewBulkIndexerErrors | func (c *Conn) NewBulkIndexerErrors(maxConns, retrySeconds int) *BulkIndexer {
b := c.NewBulkIndexer(maxConns)
b.RetryForSeconds = retrySeconds
b.ErrorChannel = make(chan *ErrorBuffer, 20)
return b
} | go | func (c *Conn) NewBulkIndexerErrors(maxConns, retrySeconds int) *BulkIndexer {
b := c.NewBulkIndexer(maxConns)
b.RetryForSeconds = retrySeconds
b.ErrorChannel = make(chan *ErrorBuffer, 20)
return b
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"NewBulkIndexerErrors",
"(",
"maxConns",
",",
"retrySeconds",
"int",
")",
"*",
"BulkIndexer",
"{",
"b",
":=",
"c",
".",
"NewBulkIndexer",
"(",
"maxConns",
")",
"\n",
"b",
".",
"RetryForSeconds",
"=",
"retrySeconds",
"\n"... | // A bulk indexer with more control over error handling
// @maxConns is the max number of in flight http requests
// @retrySeconds is # of seconds to wait before retrying falied requests
//
// done := make(chan bool)
// BulkIndexerGlobalRun(100, done) | [
"A",
"bulk",
"indexer",
"with",
"more",
"control",
"over",
"error",
"handling"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/corebulk.go#L123-L128 |
2,112 | mattbaird/elastigo | lib/corebulk.go | Start | func (b *BulkIndexer) Start() {
b.shutdownChan = make(chan chan struct{})
go func() {
// XXX(j): Refactor this stuff to use an interface.
if b.Sender == nil {
b.Sender = b.Send
}
// Backwards compatibility
b.startHttpSender()
b.startDocChannel()
b.startTimer()
ch := <-b.shutdownChan
time.Sleep(2... | go | func (b *BulkIndexer) Start() {
b.shutdownChan = make(chan chan struct{})
go func() {
// XXX(j): Refactor this stuff to use an interface.
if b.Sender == nil {
b.Sender = b.Send
}
// Backwards compatibility
b.startHttpSender()
b.startDocChannel()
b.startTimer()
ch := <-b.shutdownChan
time.Sleep(2... | [
"func",
"(",
"b",
"*",
"BulkIndexer",
")",
"Start",
"(",
")",
"{",
"b",
".",
"shutdownChan",
"=",
"make",
"(",
"chan",
"chan",
"struct",
"{",
"}",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"// XXX(j): Refactor this stuff to use an interface.",
"if",
"b",
... | // Starts this bulk Indexer running, this Run opens a go routine so is
// Non blocking | [
"Starts",
"this",
"bulk",
"Indexer",
"running",
"this",
"Run",
"opens",
"a",
"go",
"routine",
"so",
"is",
"Non",
"blocking"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/corebulk.go#L132-L150 |
2,113 | mattbaird/elastigo | lib/corebulk.go | Stop | func (b *BulkIndexer) Stop() {
ch := make(chan struct{}, 1)
b.shutdownChan <- ch
select {
case <-ch:
// done
case <-time.After(time.Second * time.Duration(MAX_SHUTDOWN_SECS)):
// timeout!
}
} | go | func (b *BulkIndexer) Stop() {
ch := make(chan struct{}, 1)
b.shutdownChan <- ch
select {
case <-ch:
// done
case <-time.After(time.Second * time.Duration(MAX_SHUTDOWN_SECS)):
// timeout!
}
} | [
"func",
"(",
"b",
"*",
"BulkIndexer",
")",
"Stop",
"(",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
"\n",
"b",
".",
"shutdownChan",
"<-",
"ch",
"\n",
"select",
"{",
"case",
"<-",
"ch",
":",
"// done",
"case",
"... | // Stop stops the bulk indexer, blocking the caller until it is complete. | [
"Stop",
"stops",
"the",
"bulk",
"indexer",
"blocking",
"the",
"caller",
"until",
"it",
"is",
"complete",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/corebulk.go#L153-L162 |
2,114 | mattbaird/elastigo | lib/corebulk.go | Flush | func (b *BulkIndexer) Flush() {
b.mu.Lock()
if b.docCt > 0 {
b.send(b.buf)
}
b.mu.Unlock()
} | go | func (b *BulkIndexer) Flush() {
b.mu.Lock()
if b.docCt > 0 {
b.send(b.buf)
}
b.mu.Unlock()
} | [
"func",
"(",
"b",
"*",
"BulkIndexer",
")",
"Flush",
"(",
")",
"{",
"b",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"b",
".",
"docCt",
">",
"0",
"{",
"b",
".",
"send",
"(",
"b",
".",
"buf",
")",
"\n",
"}",
"\n",
"b",
".",
"mu",
".",
"... | // Flush all current documents to ElasticSearch | [
"Flush",
"all",
"current",
"documents",
"to",
"ElasticSearch"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/corebulk.go#L169-L175 |
2,115 | mattbaird/elastigo | lib/corebulk.go | Send | func (b *BulkIndexer) Send(buf *bytes.Buffer) error {
type responseStruct struct {
Took int64 `json:"took"`
Errors bool `json:"errors"`
Items []map[string]interface{} `json:"items"`
}
response := responseStruct{}
body, err := b.conn.DoCommand("POST", fmt.Sprintf("/_... | go | func (b *BulkIndexer) Send(buf *bytes.Buffer) error {
type responseStruct struct {
Took int64 `json:"took"`
Errors bool `json:"errors"`
Items []map[string]interface{} `json:"items"`
}
response := responseStruct{}
body, err := b.conn.DoCommand("POST", fmt.Sprintf("/_... | [
"func",
"(",
"b",
"*",
"BulkIndexer",
")",
"Send",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"error",
"{",
"type",
"responseStruct",
"struct",
"{",
"Took",
"int64",
"`json:\"took\"`",
"\n",
"Errors",
"bool",
"`json:\"errors\"`",
"\n",
"Items",
"[",
"]"... | // This does the actual send of a buffer, which has already been formatted
// into bytes of ES formatted bulk data | [
"This",
"does",
"the",
"actual",
"send",
"of",
"a",
"buffer",
"which",
"has",
"already",
"been",
"formatted",
"into",
"bytes",
"of",
"ES",
"formatted",
"bulk",
"data"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/corebulk.go#L327-L351 |
2,116 | mattbaird/elastigo | lib/catindexinfo.go | GetCatIndexInfo | func (c *Conn) GetCatIndexInfo(pattern string) (catIndices []CatIndexInfo) {
catIndices = make([]CatIndexInfo, 0)
//force it to only show the fileds we know about
args := map[string]interface{}{"bytes": "b", "h": "health,status,index,pri,rep,docs.count,docs.deleted,store.size,pri.store.size"}
indices, err := c.DoCo... | go | func (c *Conn) GetCatIndexInfo(pattern string) (catIndices []CatIndexInfo) {
catIndices = make([]CatIndexInfo, 0)
//force it to only show the fileds we know about
args := map[string]interface{}{"bytes": "b", "h": "health,status,index,pri,rep,docs.count,docs.deleted,store.size,pri.store.size"}
indices, err := c.DoCo... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetCatIndexInfo",
"(",
"pattern",
"string",
")",
"(",
"catIndices",
"[",
"]",
"CatIndexInfo",
")",
"{",
"catIndices",
"=",
"make",
"(",
"[",
"]",
"CatIndexInfo",
",",
"0",
")",
"\n",
"//force it to only show the fileds we... | // Pull all the index info from the connection | [
"Pull",
"all",
"the",
"index",
"info",
"from",
"the",
"connection"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/catindexinfo.go#L65-L80 |
2,117 | mattbaird/elastigo | lib/baserequest.go | Exists | func (c *Conn) Exists(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error) {
var response map[string]interface{}
var body []byte
var url string
var retval BaseResponse
var httpStatusCode int
query, err := Escape(args)
if err != nil {
return retval, err
}
if len(_type) >... | go | func (c *Conn) Exists(index string, _type string, id string, args map[string]interface{}) (BaseResponse, error) {
var response map[string]interface{}
var body []byte
var url string
var retval BaseResponse
var httpStatusCode int
query, err := Escape(args)
if err != nil {
return retval, err
}
if len(_type) >... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Exists",
"(",
"index",
"string",
",",
"_type",
"string",
",",
"id",
"string",
",",
"args",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"BaseResponse",
",",
"error",
")",
"{",
"var",
"response",
"... | // Exists allows the caller to check for the existence of a document using HEAD
// This appears to be broken in the current version of elasticsearch 0.19.10, currently
// returning nothing | [
"Exists",
"allows",
"the",
"caller",
"to",
"check",
"for",
"the",
"existence",
"of",
"a",
"document",
"using",
"HEAD",
"This",
"appears",
"to",
"be",
"broken",
"in",
"the",
"current",
"version",
"of",
"elasticsearch",
"0",
".",
"19",
".",
"10",
"currently"... | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/baserequest.go#L110-L145 |
2,118 | mattbaird/elastigo | lib/coreget.go | GetCustom | func (c *Conn) GetCustom(index string, _type string, id string, args map[string]interface{}, source *json.RawMessage) (BaseResponse, error) {
return c.get(index, _type, id, args, source)
} | go | func (c *Conn) GetCustom(index string, _type string, id string, args map[string]interface{}, source *json.RawMessage) (BaseResponse, error) {
return c.get(index, _type, id, args, source)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetCustom",
"(",
"index",
"string",
",",
"_type",
"string",
",",
"id",
"string",
",",
"args",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"source",
"*",
"json",
".",
"RawMessage",
")",
"(",
"BaseRespons... | // Same as Get but with custom source type. | [
"Same",
"as",
"Get",
"but",
"with",
"custom",
"source",
"type",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/coreget.go#L57-L59 |
2,119 | mattbaird/elastigo | lib/coreget.go | GetSource | func (c *Conn) GetSource(index string, _type string, id string, args map[string]interface{}, source interface{}) error {
url := fmt.Sprintf("/%s/%s/%s/_source", index, _type, id)
body, err := c.DoCommand("GET", url, args, nil)
if err == nil {
err = json.Unmarshal(body, &source)
}
return err
} | go | func (c *Conn) GetSource(index string, _type string, id string, args map[string]interface{}, source interface{}) error {
url := fmt.Sprintf("/%s/%s/%s/_source", index, _type, id)
body, err := c.DoCommand("GET", url, args, nil)
if err == nil {
err = json.Unmarshal(body, &source)
}
return err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetSource",
"(",
"index",
"string",
",",
"_type",
"string",
",",
"id",
"string",
",",
"args",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"source",
"interface",
"{",
"}",
")",
"error",
"{",
"url",
":=... | // GetSource retrieves the document by id and converts it to provided interface | [
"GetSource",
"retrieves",
"the",
"document",
"by",
"id",
"and",
"converts",
"it",
"to",
"provided",
"interface"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/coreget.go#L62-L69 |
2,120 | mattbaird/elastigo | lib/cataliasinfo.go | GetCatAliasInfo | func (c *Conn) GetCatAliasInfo(pattern string) (catAliases []CatAliasInfo) {
catAliases = make([]CatAliasInfo, 0)
//force it to only show the fields we know about
aliases, err := c.DoCommand("GET", "/_cat/aliases/"+pattern, nil, nil)
if err == nil {
aliasLines := strings.Split(string(aliases[:]), "\n")
for _, a... | go | func (c *Conn) GetCatAliasInfo(pattern string) (catAliases []CatAliasInfo) {
catAliases = make([]CatAliasInfo, 0)
//force it to only show the fields we know about
aliases, err := c.DoCommand("GET", "/_cat/aliases/"+pattern, nil, nil)
if err == nil {
aliasLines := strings.Split(string(aliases[:]), "\n")
for _, a... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetCatAliasInfo",
"(",
"pattern",
"string",
")",
"(",
"catAliases",
"[",
"]",
"CatAliasInfo",
")",
"{",
"catAliases",
"=",
"make",
"(",
"[",
"]",
"CatAliasInfo",
",",
"0",
")",
"\n",
"//force it to only show the fields we... | // Pull all the alias info from the connection | [
"Pull",
"all",
"the",
"alias",
"info",
"from",
"the",
"connection"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/cataliasinfo.go#L25-L39 |
2,121 | mattbaird/elastigo | lib/searchfilter.go | addFilters | func (f *FilterWrap) addFilters(fl []interface{}) {
if len(fl) > 1 {
fc := fl[0]
switch fc.(type) {
case BoolClause, string:
f.boolClause = fc.(string)
fl = fl[1:]
}
}
f.filters = append(f.filters, fl...)
} | go | func (f *FilterWrap) addFilters(fl []interface{}) {
if len(fl) > 1 {
fc := fl[0]
switch fc.(type) {
case BoolClause, string:
f.boolClause = fc.(string)
fl = fl[1:]
}
}
f.filters = append(f.filters, fl...)
} | [
"func",
"(",
"f",
"*",
"FilterWrap",
")",
"addFilters",
"(",
"fl",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"len",
"(",
"fl",
")",
">",
"1",
"{",
"fc",
":=",
"fl",
"[",
"0",
"]",
"\n",
"switch",
"fc",
".",
"(",
"type",
")",
"{",
"ca... | // Custom marshalling to support the query dsl | [
"Custom",
"marshalling",
"to",
"support",
"the",
"query",
"dsl"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L77-L87 |
2,122 | mattbaird/elastigo | lib/searchfilter.go | MarshalJSON | func (f *FilterWrap) MarshalJSON() ([]byte, error) {
var root interface{}
if len(f.filters) > 1 {
root = map[string]interface{}{f.boolClause: f.filters}
} else if len(f.filters) == 1 {
root = f.filters[0]
}
return json.Marshal(root)
} | go | func (f *FilterWrap) MarshalJSON() ([]byte, error) {
var root interface{}
if len(f.filters) > 1 {
root = map[string]interface{}{f.boolClause: f.filters}
} else if len(f.filters) == 1 {
root = f.filters[0]
}
return json.Marshal(root)
} | [
"func",
"(",
"f",
"*",
"FilterWrap",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"root",
"interface",
"{",
"}",
"\n",
"if",
"len",
"(",
"f",
".",
"filters",
")",
">",
"1",
"{",
"root",
"=",
"map",
"[",
... | // MarshalJSON override for FilterWrap to match the expected ES syntax with the bool at the root | [
"MarshalJSON",
"override",
"for",
"FilterWrap",
"to",
"match",
"the",
"expected",
"ES",
"syntax",
"with",
"the",
"bool",
"at",
"the",
"root"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L90-L98 |
2,123 | mattbaird/elastigo | lib/searchfilter.go | Term | func (f *FilterOp) Term(field string, value interface{}) *FilterOp {
if len(f.TermMap) == 0 {
f.TermMap = make(map[string]interface{})
}
f.TermMap[field] = value
return f
} | go | func (f *FilterOp) Term(field string, value interface{}) *FilterOp {
if len(f.TermMap) == 0 {
f.TermMap = make(map[string]interface{})
}
f.TermMap[field] = value
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Term",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"FilterOp",
"{",
"if",
"len",
"(",
"f",
".",
"TermMap",
")",
"==",
"0",
"{",
"f",
".",
"TermMap",
"=",
"make",
"(",
"map",
"[... | // Term will add a term to the filter.
// Multiple Term filters can be added, and ES will OR them.
// If the term already exists in the FilterOp, the value will be overridden. | [
"Term",
"will",
"add",
"a",
"term",
"to",
"the",
"filter",
".",
"Multiple",
"Term",
"filters",
"can",
"be",
"added",
"and",
"ES",
"will",
"OR",
"them",
".",
"If",
"the",
"term",
"already",
"exists",
"in",
"the",
"FilterOp",
"the",
"value",
"will",
"be"... | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L251-L258 |
2,124 | mattbaird/elastigo | lib/searchfilter.go | And | func (f *FilterOp) And(filters ...*FilterOp) *FilterOp {
if len(f.AndFilters) == 0 {
f.AndFilters = filters[:]
} else {
f.AndFilters = append(f.AndFilters, filters...)
}
return f
} | go | func (f *FilterOp) And(filters ...*FilterOp) *FilterOp {
if len(f.AndFilters) == 0 {
f.AndFilters = filters[:]
} else {
f.AndFilters = append(f.AndFilters, filters...)
}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"And",
"(",
"filters",
"...",
"*",
"FilterOp",
")",
"*",
"FilterOp",
"{",
"if",
"len",
"(",
"f",
".",
"AndFilters",
")",
"==",
"0",
"{",
"f",
".",
"AndFilters",
"=",
"filters",
"[",
":",
"]",
"\n",
"}",
"... | // And will add an AND op to the filter. One or more FilterOps can be passed in. | [
"And",
"will",
"add",
"an",
"AND",
"op",
"to",
"the",
"filter",
".",
"One",
"or",
"more",
"FilterOps",
"can",
"be",
"passed",
"in",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L261-L269 |
2,125 | mattbaird/elastigo | lib/searchfilter.go | Or | func (f *FilterOp) Or(filters ...*FilterOp) *FilterOp {
if len(f.OrFilters) == 0 {
f.OrFilters = filters[:]
} else {
f.OrFilters = append(f.OrFilters, filters...)
}
return f
} | go | func (f *FilterOp) Or(filters ...*FilterOp) *FilterOp {
if len(f.OrFilters) == 0 {
f.OrFilters = filters[:]
} else {
f.OrFilters = append(f.OrFilters, filters...)
}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Or",
"(",
"filters",
"...",
"*",
"FilterOp",
")",
"*",
"FilterOp",
"{",
"if",
"len",
"(",
"f",
".",
"OrFilters",
")",
"==",
"0",
"{",
"f",
".",
"OrFilters",
"=",
"filters",
"[",
":",
"]",
"\n",
"}",
"els... | // Or will add an OR op to the filter. One or more FilterOps can be passed in. | [
"Or",
"will",
"add",
"an",
"OR",
"op",
"to",
"the",
"filter",
".",
"One",
"or",
"more",
"FilterOps",
"can",
"be",
"passed",
"in",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L272-L280 |
2,126 | mattbaird/elastigo | lib/searchfilter.go | Not | func (f *FilterOp) Not(filters ...*FilterOp) *FilterOp {
if len(f.NotFilters) == 0 {
f.NotFilters = filters[:]
} else {
f.NotFilters = append(f.NotFilters, filters...)
}
return f
} | go | func (f *FilterOp) Not(filters ...*FilterOp) *FilterOp {
if len(f.NotFilters) == 0 {
f.NotFilters = filters[:]
} else {
f.NotFilters = append(f.NotFilters, filters...)
}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Not",
"(",
"filters",
"...",
"*",
"FilterOp",
")",
"*",
"FilterOp",
"{",
"if",
"len",
"(",
"f",
".",
"NotFilters",
")",
"==",
"0",
"{",
"f",
".",
"NotFilters",
"=",
"filters",
"[",
":",
"]",
"\n\n",
"}",
... | // Not will add a NOT op to the filter. One or more FilterOps can be passed in. | [
"Not",
"will",
"add",
"a",
"NOT",
"op",
"to",
"the",
"filter",
".",
"One",
"or",
"more",
"FilterOps",
"can",
"be",
"passed",
"in",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L283-L292 |
2,127 | mattbaird/elastigo | lib/searchfilter.go | NewGeoField | func NewGeoField(field string, latitude float32, longitude float32) GeoField {
return GeoField{
GeoLocation: GeoLocation{Latitude: latitude, Longitude: longitude},
Field: field}
} | go | func NewGeoField(field string, latitude float32, longitude float32) GeoField {
return GeoField{
GeoLocation: GeoLocation{Latitude: latitude, Longitude: longitude},
Field: field}
} | [
"func",
"NewGeoField",
"(",
"field",
"string",
",",
"latitude",
"float32",
",",
"longitude",
"float32",
")",
"GeoField",
"{",
"return",
"GeoField",
"{",
"GeoLocation",
":",
"GeoLocation",
"{",
"Latitude",
":",
"latitude",
",",
"Longitude",
":",
"longitude",
"}... | // NewGeoField is a helper function to create values for the GeoDistance filters | [
"NewGeoField",
"is",
"a",
"helper",
"function",
"to",
"create",
"values",
"for",
"the",
"GeoDistance",
"filters"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L324-L328 |
2,128 | mattbaird/elastigo | lib/searchfilter.go | Range | func (f *FilterOp) Range(field string, gte interface{},
gt interface{}, lte interface{}, lt interface{}, timeZone string) *FilterOp {
if f.RangeMap == nil {
f.RangeMap = make(map[string]RangeFilter)
}
f.RangeMap[field] = RangeFilter{
Gte: gte,
Gt: gt,
Lte: lte,
Lt: lt,
TimeZone: ... | go | func (f *FilterOp) Range(field string, gte interface{},
gt interface{}, lte interface{}, lt interface{}, timeZone string) *FilterOp {
if f.RangeMap == nil {
f.RangeMap = make(map[string]RangeFilter)
}
f.RangeMap[field] = RangeFilter{
Gte: gte,
Gt: gt,
Lte: lte,
Lt: lt,
TimeZone: ... | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Range",
"(",
"field",
"string",
",",
"gte",
"interface",
"{",
"}",
",",
"gt",
"interface",
"{",
"}",
",",
"lte",
"interface",
"{",
"}",
",",
"lt",
"interface",
"{",
"}",
",",
"timeZone",
"string",
")",
"*",
... | // Range adds a range filter for the given field.
// See the RangeFilter struct documentation for information about the parameters. | [
"Range",
"adds",
"a",
"range",
"filter",
"for",
"the",
"given",
"field",
".",
"See",
"the",
"RangeFilter",
"struct",
"documentation",
"for",
"information",
"about",
"the",
"parameters",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L350-L365 |
2,129 | mattbaird/elastigo | lib/searchfilter.go | Type | func (f *FilterOp) Type(fieldType string) *FilterOp {
f.TypeProp = &TypeFilter{Value: fieldType}
return f
} | go | func (f *FilterOp) Type(fieldType string) *FilterOp {
f.TypeProp = &TypeFilter{Value: fieldType}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Type",
"(",
"fieldType",
"string",
")",
"*",
"FilterOp",
"{",
"f",
".",
"TypeProp",
"=",
"&",
"TypeFilter",
"{",
"Value",
":",
"fieldType",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // Type adds a TYPE op to the filter. | [
"Type",
"adds",
"a",
"TYPE",
"op",
"to",
"the",
"filter",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L368-L371 |
2,130 | mattbaird/elastigo | lib/searchfilter.go | Ids | func (f *FilterOp) Ids(ids ...interface{}) *FilterOp {
f.IdsProp = &IdsFilter{Values: ids}
return f
} | go | func (f *FilterOp) Ids(ids ...interface{}) *FilterOp {
f.IdsProp = &IdsFilter{Values: ids}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Ids",
"(",
"ids",
"...",
"interface",
"{",
"}",
")",
"*",
"FilterOp",
"{",
"f",
".",
"IdsProp",
"=",
"&",
"IdsFilter",
"{",
"Values",
":",
"ids",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // Ids adds a IDS op to the filter. | [
"Ids",
"adds",
"a",
"IDS",
"op",
"to",
"the",
"filter",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L374-L377 |
2,131 | mattbaird/elastigo | lib/searchfilter.go | IdsByTypes | func (f *FilterOp) IdsByTypes(types []string, ids ...interface{}) *FilterOp {
f.IdsProp = &IdsFilter{Type: types, Values: ids}
return f
} | go | func (f *FilterOp) IdsByTypes(types []string, ids ...interface{}) *FilterOp {
f.IdsProp = &IdsFilter{Type: types, Values: ids}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"IdsByTypes",
"(",
"types",
"[",
"]",
"string",
",",
"ids",
"...",
"interface",
"{",
"}",
")",
"*",
"FilterOp",
"{",
"f",
".",
"IdsProp",
"=",
"&",
"IdsFilter",
"{",
"Type",
":",
"types",
",",
"Values",
":",
... | // IdsByTypes adds a IDS op to the filter, but also allows passing in an array of types for the query. | [
"IdsByTypes",
"adds",
"a",
"IDS",
"op",
"to",
"the",
"filter",
"but",
"also",
"allows",
"passing",
"in",
"an",
"array",
"of",
"types",
"for",
"the",
"query",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L380-L383 |
2,132 | mattbaird/elastigo | lib/searchfilter.go | Exists | func (f *FilterOp) Exists(field string) *FilterOp {
f.ExistsProp = &propertyPathMarker{Field: field}
return f
} | go | func (f *FilterOp) Exists(field string) *FilterOp {
f.ExistsProp = &propertyPathMarker{Field: field}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Exists",
"(",
"field",
"string",
")",
"*",
"FilterOp",
"{",
"f",
".",
"ExistsProp",
"=",
"&",
"propertyPathMarker",
"{",
"Field",
":",
"field",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // Exists adds an EXISTS op to the filter. | [
"Exists",
"adds",
"an",
"EXISTS",
"op",
"to",
"the",
"filter",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L386-L389 |
2,133 | mattbaird/elastigo | lib/searchfilter.go | Missing | func (f *FilterOp) Missing(field string) *FilterOp {
f.MissingProp = &propertyPathMarker{Field: field}
return f
} | go | func (f *FilterOp) Missing(field string) *FilterOp {
f.MissingProp = &propertyPathMarker{Field: field}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Missing",
"(",
"field",
"string",
")",
"*",
"FilterOp",
"{",
"f",
".",
"MissingProp",
"=",
"&",
"propertyPathMarker",
"{",
"Field",
":",
"field",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // Missing adds an MISSING op to the filter. | [
"Missing",
"adds",
"an",
"MISSING",
"op",
"to",
"the",
"filter",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L392-L395 |
2,134 | mattbaird/elastigo | lib/searchfilter.go | Limit | func (f *FilterOp) Limit(maxResults int) *FilterOp {
f.LimitProp = &LimitFilter{Value: maxResults}
return f
} | go | func (f *FilterOp) Limit(maxResults int) *FilterOp {
f.LimitProp = &LimitFilter{Value: maxResults}
return f
} | [
"func",
"(",
"f",
"*",
"FilterOp",
")",
"Limit",
"(",
"maxResults",
"int",
")",
"*",
"FilterOp",
"{",
"f",
".",
"LimitProp",
"=",
"&",
"LimitFilter",
"{",
"Value",
":",
"maxResults",
"}",
"\n",
"return",
"f",
"\n",
"}"
] | // Limit adds an LIMIT op to the filter. | [
"Limit",
"adds",
"an",
"LIMIT",
"op",
"to",
"the",
"filter",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchfilter.go#L398-L401 |
2,135 | mattbaird/elastigo | lib/connection.go | initializeHostPool | func (c *Conn) initializeHostPool() {
// If no hosts are set, fallback to defaults
if len(c.Hosts) == 0 {
c.Hosts = append(c.Hosts, fmt.Sprintf("%s:%s", c.Domain, c.Port))
}
// Epsilon Greedy is an algorithm that allows HostPool not only to
// track failure state, but also to learn about "better" options in
/... | go | func (c *Conn) initializeHostPool() {
// If no hosts are set, fallback to defaults
if len(c.Hosts) == 0 {
c.Hosts = append(c.Hosts, fmt.Sprintf("%s:%s", c.Domain, c.Port))
}
// Epsilon Greedy is an algorithm that allows HostPool not only to
// track failure state, but also to learn about "better" options in
/... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"initializeHostPool",
"(",
")",
"{",
"// If no hosts are set, fallback to defaults",
"if",
"len",
"(",
"c",
".",
"Hosts",
")",
"==",
"0",
"{",
"c",
".",
"Hosts",
"=",
"append",
"(",
"c",
".",
"Hosts",
",",
"fmt",
"."... | // Set up the host pool to be used | [
"Set",
"up",
"the",
"host",
"pool",
"to",
"be",
"used"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/connection.go#L109-L132 |
2,136 | mattbaird/elastigo | lib/connection.go | splitHostnamePartsFromHost | func splitHostnamePartsFromHost(fullHost string, defaultPortNum string) (string, string) {
h := strings.Split(fullHost, ":")
if len(h) == 2 {
return h[0], h[1]
}
return h[0], defaultPortNum
} | go | func splitHostnamePartsFromHost(fullHost string, defaultPortNum string) (string, string) {
h := strings.Split(fullHost, ":")
if len(h) == 2 {
return h[0], h[1]
}
return h[0], defaultPortNum
} | [
"func",
"splitHostnamePartsFromHost",
"(",
"fullHost",
"string",
",",
"defaultPortNum",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"h",
":=",
"strings",
".",
"Split",
"(",
"fullHost",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"h",
")",
... | // Split apart the hostname on colon
// Return the host and a default port if there is no separator | [
"Split",
"apart",
"the",
"hostname",
"on",
"colon",
"Return",
"the",
"host",
"and",
"a",
"default",
"port",
"if",
"there",
"is",
"no",
"separator"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/connection.go#L177-L186 |
2,137 | mattbaird/elastigo | lib/indicesaliases.go | AddAlias | func (c *Conn) AddAlias(index string, alias string) (BaseResponse, error) {
var url string
var retval BaseResponse
if len(index) > 0 {
url = "/_aliases"
} else {
return retval, fmt.Errorf("You must specify an index to create the alias on")
}
jsonAliases := JsonAliases{}
jsonAliasAdd := JsonAliasAdd{}
json... | go | func (c *Conn) AddAlias(index string, alias string) (BaseResponse, error) {
var url string
var retval BaseResponse
if len(index) > 0 {
url = "/_aliases"
} else {
return retval, fmt.Errorf("You must specify an index to create the alias on")
}
jsonAliases := JsonAliases{}
jsonAliasAdd := JsonAliasAdd{}
json... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"AddAlias",
"(",
"index",
"string",
",",
"alias",
"string",
")",
"(",
"BaseResponse",
",",
"error",
")",
"{",
"var",
"url",
"string",
"\n",
"var",
"retval",
"BaseResponse",
"\n\n",
"if",
"len",
"(",
"index",
")",
"... | // The API allows you to create an index alias through an API. | [
"The",
"API",
"allows",
"you",
"to",
"create",
"an",
"index",
"alias",
"through",
"an",
"API",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/indicesaliases.go#L33-L65 |
2,138 | mattbaird/elastigo | lib/coreindex.go | IndexWithParameters | func (c *Conn) IndexWithParameters(index string, _type string, id string, parentId string, version int, op_type string,
routing string, timestamp string, ttl int, percolate string, timeout string, refresh bool,
args map[string]interface{}, data interface{}) (BaseResponse, error) {
var url string
var retval BaseResp... | go | func (c *Conn) IndexWithParameters(index string, _type string, id string, parentId string, version int, op_type string,
routing string, timestamp string, ttl int, percolate string, timeout string, refresh bool,
args map[string]interface{}, data interface{}) (BaseResponse, error) {
var url string
var retval BaseResp... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"IndexWithParameters",
"(",
"index",
"string",
",",
"_type",
"string",
",",
"id",
"string",
",",
"parentId",
"string",
",",
"version",
"int",
",",
"op_type",
"string",
",",
"routing",
"string",
",",
"timestamp",
"string"... | // IndexWithParameters takes all the potential parameters available | [
"IndexWithParameters",
"takes",
"all",
"the",
"potential",
"parameters",
"available"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/coreindex.go#L41-L68 |
2,139 | mattbaird/elastigo | lib/searchquery.go | SetLenient | func (q *QueryDsl) SetLenient(lenient bool) *QueryDsl {
q.QueryEmbed.Qs.Lenient = lenient
return q
} | go | func (q *QueryDsl) SetLenient(lenient bool) *QueryDsl {
q.QueryEmbed.Qs.Lenient = lenient
return q
} | [
"func",
"(",
"q",
"*",
"QueryDsl",
")",
"SetLenient",
"(",
"lenient",
"bool",
")",
"*",
"QueryDsl",
"{",
"q",
".",
"QueryEmbed",
".",
"Qs",
".",
"Lenient",
"=",
"lenient",
"\n",
"return",
"q",
"\n",
"}"
] | // SetLenient sets whether the query should ignore format based failures,
// such as passing in text to a number field. | [
"SetLenient",
"sets",
"whether",
"the",
"query",
"should",
"ignore",
"format",
"based",
"failures",
"such",
"as",
"passing",
"in",
"text",
"to",
"a",
"number",
"field",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchquery.go#L149-L152 |
2,140 | mattbaird/elastigo | lib/searchquery.go | Filter | func (q *QueryDsl) Filter(f *FilterOp) *QueryDsl {
q.FilterVal = f
return q
} | go | func (q *QueryDsl) Filter(f *FilterOp) *QueryDsl {
q.FilterVal = f
return q
} | [
"func",
"(",
"q",
"*",
"QueryDsl",
")",
"Filter",
"(",
"f",
"*",
"FilterOp",
")",
"*",
"QueryDsl",
"{",
"q",
".",
"FilterVal",
"=",
"f",
"\n",
"return",
"q",
"\n",
"}"
] | // Filter this query | [
"Filter",
"this",
"query"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchquery.go#L176-L179 |
2,141 | mattbaird/elastigo | lib/searchquery.go | MultiMatch | func (q *QueryDsl) MultiMatch(s string, fields []string) *QueryDsl {
q.QueryEmbed.MultiMatch = &MultiMatch{Query: s, Fields: fields}
return q
} | go | func (q *QueryDsl) MultiMatch(s string, fields []string) *QueryDsl {
q.QueryEmbed.MultiMatch = &MultiMatch{Query: s, Fields: fields}
return q
} | [
"func",
"(",
"q",
"*",
"QueryDsl",
")",
"MultiMatch",
"(",
"s",
"string",
",",
"fields",
"[",
"]",
"string",
")",
"*",
"QueryDsl",
"{",
"q",
".",
"QueryEmbed",
".",
"MultiMatch",
"=",
"&",
"MultiMatch",
"{",
"Query",
":",
"s",
",",
"Fields",
":",
"... | // MultiMatch allows searching against multiple fields. | [
"MultiMatch",
"allows",
"searching",
"against",
"multiple",
"fields",
"."
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchquery.go#L182-L185 |
2,142 | mattbaird/elastigo | lib/searchquery.go | NewQueryString | func NewQueryString(field, query string) QueryString {
return QueryString{"", field, query, "", "", nil, false}
} | go | func NewQueryString(field, query string) QueryString {
return QueryString{"", field, query, "", "", nil, false}
} | [
"func",
"NewQueryString",
"(",
"field",
",",
"query",
"string",
")",
"QueryString",
"{",
"return",
"QueryString",
"{",
"\"",
"\"",
",",
"field",
",",
"query",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"false",
"}",
"\n",
"}"
] | // QueryString based search | [
"QueryString",
"based",
"search"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchquery.go#L202-L204 |
2,143 | mattbaird/elastigo | lib/searchsearch.go | Search | func (s *SearchDsl) Search(srch string) *SearchDsl {
s.QueryVal = Query().Search(srch)
return s
} | go | func (s *SearchDsl) Search(srch string) *SearchDsl {
s.QueryVal = Query().Search(srch)
return s
} | [
"func",
"(",
"s",
"*",
"SearchDsl",
")",
"Search",
"(",
"srch",
"string",
")",
"*",
"SearchDsl",
"{",
"s",
".",
"QueryVal",
"=",
"Query",
"(",
")",
".",
"Search",
"(",
"srch",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // Search is a simple interface to search, doesn't have the power of query
// but uses a simple query_string search | [
"Search",
"is",
"a",
"simple",
"interface",
"to",
"search",
"doesn",
"t",
"have",
"the",
"power",
"of",
"query",
"but",
"uses",
"a",
"simple",
"query_string",
"search"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/searchsearch.go#L107-L110 |
2,144 | mattbaird/elastigo | lib/catshardinfo.go | String | func (s *CatShards) String() string {
var buffer bytes.Buffer
if s != nil {
for _, cs := range *s {
buffer.WriteString(fmt.Sprintf("%v\n", cs))
}
}
return buffer.String()
} | go | func (s *CatShards) String() string {
var buffer bytes.Buffer
if s != nil {
for _, cs := range *s {
buffer.WriteString(fmt.Sprintf("%v\n", cs))
}
}
return buffer.String()
} | [
"func",
"(",
"s",
"*",
"CatShards",
")",
"String",
"(",
")",
"string",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"s",
"!=",
"nil",
"{",
"for",
"_",
",",
"cs",
":=",
"range",
"*",
"s",
"{",
"buffer",
".",
"WriteString",
"(",
"fmt... | // Stringify the shards | [
"Stringify",
"the",
"shards"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/catshardinfo.go#L14-L23 |
2,145 | mattbaird/elastigo | lib/catshardinfo.go | String | func (s *CatShardInfo) String() string {
if s == nil {
return ":::::::"
}
return fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v", s.IndexName, s.Shard, s.Primary,
s.State, s.Docs, s.Store, s.NodeIP, s.NodeName)
} | go | func (s *CatShardInfo) String() string {
if s == nil {
return ":::::::"
}
return fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v", s.IndexName, s.Shard, s.Primary,
s.State, s.Docs, s.Store, s.NodeIP, s.NodeName)
} | [
"func",
"(",
"s",
"*",
"CatShardInfo",
")",
"String",
"(",
")",
"string",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"IndexName",
",",
"s",
".",
"Sha... | // Print shard info | [
"Print",
"shard",
"info"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/catshardinfo.go#L82-L88 |
2,146 | mattbaird/elastigo | lib/catshardinfo.go | GetCatShards | func (c *Conn) GetCatShards() (shards CatShards) {
shards = make(CatShards, 0)
//force it to only respond with the columns we know about and in a forced order
args := map[string]interface{}{"bytes": "b", "h": "index,shard,prirep,state,docs,store,ip,node"}
s, err := c.DoCommand("GET", "/_cat/shards", args, nil)
if ... | go | func (c *Conn) GetCatShards() (shards CatShards) {
shards = make(CatShards, 0)
//force it to only respond with the columns we know about and in a forced order
args := map[string]interface{}{"bytes": "b", "h": "index,shard,prirep,state,docs,store,ip,node"}
s, err := c.DoCommand("GET", "/_cat/shards", args, nil)
if ... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetCatShards",
"(",
")",
"(",
"shards",
"CatShards",
")",
"{",
"shards",
"=",
"make",
"(",
"CatShards",
",",
"0",
")",
"\n",
"//force it to only respond with the columns we know about and in a forced order",
"args",
":=",
"map"... | // Get all the shards, even the bad ones | [
"Get",
"all",
"the",
"shards",
"even",
"the",
"bad",
"ones"
] | 2fe47fd29e4b70353f852ede77a196830d2924ec | https://github.com/mattbaird/elastigo/blob/2fe47fd29e4b70353f852ede77a196830d2924ec/lib/catshardinfo.go#L91-L106 |
2,147 | jpillora/backoff | backoff.go | Duration | func (b *Backoff) Duration() time.Duration {
d := b.ForAttempt(b.attempt)
b.attempt++
return d
} | go | func (b *Backoff) Duration() time.Duration {
d := b.ForAttempt(b.attempt)
b.attempt++
return d
} | [
"func",
"(",
"b",
"*",
"Backoff",
")",
"Duration",
"(",
")",
"time",
".",
"Duration",
"{",
"d",
":=",
"b",
".",
"ForAttempt",
"(",
"b",
".",
"attempt",
")",
"\n",
"b",
".",
"attempt",
"++",
"\n",
"return",
"d",
"\n",
"}"
] | // Duration returns the duration for the current attempt before incrementing
// the attempt counter. See ForAttempt. | [
"Duration",
"returns",
"the",
"duration",
"for",
"the",
"current",
"attempt",
"before",
"incrementing",
"the",
"attempt",
"counter",
".",
"See",
"ForAttempt",
"."
] | 3050d21c67d7c46b07ca1b5e1be0b26669c8d04c | https://github.com/jpillora/backoff/blob/3050d21c67d7c46b07ca1b5e1be0b26669c8d04c/backoff.go#L27-L31 |
2,148 | jpillora/backoff | backoff.go | ForAttempt | func (b *Backoff) ForAttempt(attempt float64) time.Duration {
// Zero-values are nonsensical, so we use
// them to apply defaults
min := b.Min
if min <= 0 {
min = 100 * time.Millisecond
}
max := b.Max
if max <= 0 {
max = 10 * time.Second
}
if min >= max {
// short-circuit
return max
}
factor := b.Fac... | go | func (b *Backoff) ForAttempt(attempt float64) time.Duration {
// Zero-values are nonsensical, so we use
// them to apply defaults
min := b.Min
if min <= 0 {
min = 100 * time.Millisecond
}
max := b.Max
if max <= 0 {
max = 10 * time.Second
}
if min >= max {
// short-circuit
return max
}
factor := b.Fac... | [
"func",
"(",
"b",
"*",
"Backoff",
")",
"ForAttempt",
"(",
"attempt",
"float64",
")",
"time",
".",
"Duration",
"{",
"// Zero-values are nonsensical, so we use",
"// them to apply defaults",
"min",
":=",
"b",
".",
"Min",
"\n",
"if",
"min",
"<=",
"0",
"{",
"min",... | // ForAttempt returns the duration for a specific attempt. This is useful if
// you have a large number of independent Backoffs, but don't want use
// unnecessary memory storing the Backoff parameters per Backoff. The first
// attempt should be 0.
//
// ForAttempt is concurrent-safe. | [
"ForAttempt",
"returns",
"the",
"duration",
"for",
"a",
"specific",
"attempt",
".",
"This",
"is",
"useful",
"if",
"you",
"have",
"a",
"large",
"number",
"of",
"independent",
"Backoffs",
"but",
"don",
"t",
"want",
"use",
"unnecessary",
"memory",
"storing",
"t... | 3050d21c67d7c46b07ca1b5e1be0b26669c8d04c | https://github.com/jpillora/backoff/blob/3050d21c67d7c46b07ca1b5e1be0b26669c8d04c/backoff.go#L41-L79 |
2,149 | jpillora/backoff | backoff.go | Copy | func (b *Backoff) Copy() *Backoff {
return &Backoff{
Factor: b.Factor,
Jitter: b.Jitter,
Min: b.Min,
Max: b.Max,
}
} | go | func (b *Backoff) Copy() *Backoff {
return &Backoff{
Factor: b.Factor,
Jitter: b.Jitter,
Min: b.Min,
Max: b.Max,
}
} | [
"func",
"(",
"b",
"*",
"Backoff",
")",
"Copy",
"(",
")",
"*",
"Backoff",
"{",
"return",
"&",
"Backoff",
"{",
"Factor",
":",
"b",
".",
"Factor",
",",
"Jitter",
":",
"b",
".",
"Jitter",
",",
"Min",
":",
"b",
".",
"Min",
",",
"Max",
":",
"b",
".... | // Copy returns a backoff with equals constraints as the original | [
"Copy",
"returns",
"a",
"backoff",
"with",
"equals",
"constraints",
"as",
"the",
"original"
] | 3050d21c67d7c46b07ca1b5e1be0b26669c8d04c | https://github.com/jpillora/backoff/blob/3050d21c67d7c46b07ca1b5e1be0b26669c8d04c/backoff.go#L92-L99 |
2,150 | yosssi/gmq | mqtt/packet/connack.go | NewCONNACKFromBytes | func NewCONNACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validateCONNACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Create a CONNACK Packet.
p := &CONNACK{
sessionPresent: variableHeader[0]<<7 == 0x80,
connec... | go | func NewCONNACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validateCONNACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Create a CONNACK Packet.
p := &CONNACK{
sessionPresent: variableHeader[0]<<7 == 0x80,
connec... | [
"func",
"NewCONNACKFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validateCONNACKBytes",
"(",
"fixedHeader",
",",
"variableHeader",... | // NewCONNACKFromBytes creates the CONNACK Packet
// from the byte data and returns it. | [
"NewCONNACKFromBytes",
"creates",
"the",
"CONNACK",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/connack.go#L42-L62 |
2,151 | yosssi/gmq | mqtt/packet/connack.go | validateCONNACKBytes | func validateCONNACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenCONNACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | go | func validateCONNACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenCONNACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | [
"func",
"validateCONNACKBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
... | // validateCONNACKBytes validates the fixed header and the variable header. | [
"validateCONNACKBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/connack.go#L65-L116 |
2,152 | yosssi/gmq | cmd/gmq-cli/command_sub.go | newCommandSub | func newCommandSub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
topicFilter := flg.String("t", "", "Topic Filter")
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
// Parse the flag.
if err := flg.Parse(args); err != nil {
return nil, errCm... | go | func newCommandSub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
topicFilter := flg.String("t", "", "Topic Filter")
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
// Parse the flag.
if err := flg.Parse(args); err != nil {
return nil, errCm... | [
"func",
"newCommandSub",
"(",
"args",
"[",
"]",
"string",
",",
"cli",
"*",
"client",
".",
"Client",
")",
"(",
"command",
",",
"error",
")",
"{",
"// Create a flag set.",
"var",
"flg",
"flag",
".",
"FlagSet",
"\n\n",
"// Define the flags.",
"topicFilter",
":=... | // newCommandSub creates and returns a sub command. | [
"newCommandSub",
"creates",
"and",
"returns",
"a",
"sub",
"command",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/cmd/gmq-cli/command_sub.go#L26-L55 |
2,153 | yosssi/gmq | mqtt/packet/decode.go | decodeUint16 | func decodeUint16(b []byte) (uint16, error) {
// Check the length of the slice of bytes.
if len(b) != 2 {
return 0, ErrInvalidByteLen
}
return uint16(b[0])<<8 | uint16(b[1]), nil
} | go | func decodeUint16(b []byte) (uint16, error) {
// Check the length of the slice of bytes.
if len(b) != 2 {
return 0, ErrInvalidByteLen
}
return uint16(b[0])<<8 | uint16(b[1]), nil
} | [
"func",
"decodeUint16",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"uint16",
",",
"error",
")",
"{",
"// Check the length of the slice of bytes.",
"if",
"len",
"(",
"b",
")",
"!=",
"2",
"{",
"return",
"0",
",",
"ErrInvalidByteLen",
"\n",
"}",
"\n\n",
"return",
... | // decodeUint16 converts the slice of bytes in big-endian order
// into an unsigned 16-bit integer. | [
"decodeUint16",
"converts",
"the",
"slice",
"of",
"bytes",
"in",
"big",
"-",
"endian",
"order",
"into",
"an",
"unsigned",
"16",
"-",
"bit",
"integer",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/decode.go#L10-L17 |
2,154 | yosssi/gmq | cmd/gmq-cli/command_pub.go | newCommandPub | func newCommandPub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
retain := flg.Bool("r", false, "Retain")
topicName := flg.String("t", "", "Topic Name")
message := flg.String("m", "", "Applicatio... | go | func newCommandPub(args []string, cli *client.Client) (command, error) {
// Create a flag set.
var flg flag.FlagSet
// Define the flags.
qos := flg.Uint("q", uint(mqtt.QoS0), "QoS")
retain := flg.Bool("r", false, "Retain")
topicName := flg.String("t", "", "Topic Name")
message := flg.String("m", "", "Applicatio... | [
"func",
"newCommandPub",
"(",
"args",
"[",
"]",
"string",
",",
"cli",
"*",
"client",
".",
"Client",
")",
"(",
"command",
",",
"error",
")",
"{",
"// Create a flag set.",
"var",
"flg",
"flag",
".",
"FlagSet",
"\n\n",
"// Define the flags.",
"qos",
":=",
"fl... | // newCommandPub creates and returns a pub command. | [
"newCommandPub",
"creates",
"and",
"returns",
"a",
"pub",
"command",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/cmd/gmq-cli/command_pub.go#L25-L53 |
2,155 | yosssi/gmq | mqtt/packet/suback.go | NewSUBACKFromBytes | func NewSUBACKFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validateSUBACKBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Extract the variable header.
variableHeader := remaining[0:lenSUBACKVariableHeader]
// Extract the payload.
... | go | func NewSUBACKFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validateSUBACKBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Extract the variable header.
variableHeader := remaining[0:lenSUBACKVariableHeader]
// Extract the payload.
... | [
"func",
"NewSUBACKFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validateSUBACKBytes",
"(",
"fixedHeader",
",",
"remaining",
")",
";... | // NewSUBACKFromBytes creates a SUBACK Packet
// from the byte data and returns it. | [
"NewSUBACKFromBytes",
"creates",
"a",
"SUBACK",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/suback.go#L32-L66 |
2,156 | yosssi/gmq | mqtt/packet/suback.go | validateSUBACKBytes | func validateSUBACKBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) < minLenSUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
// ... | go | func validateSUBACKBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) < minLenSUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
// ... | [
"func",
"validateSUBACKBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // validateSUBACKBytes validates the fixed header and the remaining. | [
"validateSUBACKBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"remaining",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/suback.go#L69-L112 |
2,157 | yosssi/gmq | mqtt/packet/pubrec.go | NewPUBREC | func NewPUBREC(opts *PUBRECOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBRECOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBREC Packet.
p := &PUBREC{
PacketID: opts.PacketID,
}
// Set the variable header... | go | func NewPUBREC(opts *PUBRECOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBRECOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBREC Packet.
p := &PUBREC{
PacketID: opts.PacketID,
}
// Set the variable header... | [
"func",
"NewPUBREC",
"(",
"opts",
"*",
"PUBRECOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"PUBRECOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"if"... | // NewPUBREC creates and returns a PUBACK Packet. | [
"NewPUBREC",
"creates",
"and",
"returns",
"a",
"PUBACK",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrec.go#L32-L56 |
2,158 | yosssi/gmq | mqtt/packet/pubrec.go | NewPUBRECFromBytes | func NewPUBRECFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBRECBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | go | func NewPUBRECFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBRECBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | [
"func",
"NewPUBRECFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePUBRECBytes",
"(",
"fixedHeader",
",",
"variableHeader",
... | // NewPUBRECFromBytes creates a PUBREC Packet
// from the byte data and returns it. | [
"NewPUBRECFromBytes",
"creates",
"a",
"PUBREC",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrec.go#L60-L84 |
2,159 | yosssi/gmq | mqtt/packet/pubrec.go | validatePUBRECBytes | func validatePUBRECBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBRECFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | go | func validatePUBRECBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBRECFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | [
"func",
"validatePUBRECBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"... | // validatePUBRECBytes validates the fixed header and the variable header. | [
"validatePUBRECBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrec.go#L87-L128 |
2,160 | yosssi/gmq | mqtt/packet/connect.go | connectFlags | func (p *CONNECT) connectFlags() byte {
// Create a byte which represents the Connect Flags.
var b byte
// Set 1 to the Bit 7 if the Packet has the User Name.
if len(p.userName) > 0 {
b |= 0x80
}
// Set 1 to the Bit 6 if the Packet has the Password.
if len(p.password) > 0 {
b |= 0x40
}
// Set 1 to the B... | go | func (p *CONNECT) connectFlags() byte {
// Create a byte which represents the Connect Flags.
var b byte
// Set 1 to the Bit 7 if the Packet has the User Name.
if len(p.userName) > 0 {
b |= 0x80
}
// Set 1 to the Bit 6 if the Packet has the Password.
if len(p.password) > 0 {
b |= 0x40
}
// Set 1 to the B... | [
"func",
"(",
"p",
"*",
"CONNECT",
")",
"connectFlags",
"(",
")",
"byte",
"{",
"// Create a byte which represents the Connect Flags.",
"var",
"b",
"byte",
"\n\n",
"// Set 1 to the Bit 7 if the Packet has the User Name.",
"if",
"len",
"(",
"p",
".",
"userName",
")",
">"... | // connectFlags creates and returns a byte which represents the Connect Flags. | [
"connectFlags",
"creates",
"and",
"returns",
"a",
"byte",
"which",
"represents",
"the",
"Connect",
"Flags",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/connect.go#L79-L113 |
2,161 | yosssi/gmq | mqtt/packet/connect.go | will | func (p *CONNECT) will() bool {
return len(p.willTopic) > 0 && len(p.willMessage) > 0
} | go | func (p *CONNECT) will() bool {
return len(p.willTopic) > 0 && len(p.willMessage) > 0
} | [
"func",
"(",
"p",
"*",
"CONNECT",
")",
"will",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"p",
".",
"willTopic",
")",
">",
"0",
"&&",
"len",
"(",
"p",
".",
"willMessage",
")",
">",
"0",
"\n",
"}"
] | // will return true if both the Will Topic and the Will Message are not zero-byte. | [
"will",
"return",
"true",
"if",
"both",
"the",
"Will",
"Topic",
"and",
"the",
"Will",
"Message",
"are",
"not",
"zero",
"-",
"byte",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/connect.go#L116-L118 |
2,162 | yosssi/gmq | mqtt/packet/connect.go | NewCONNECT | func NewCONNECT(opts *CONNECTOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &CONNECTOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a CONNECT Packet.
p := &CONNECT{
clientID: opts.ClientID,
userName: opts.U... | go | func NewCONNECT(opts *CONNECTOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &CONNECTOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a CONNECT Packet.
p := &CONNECT{
clientID: opts.ClientID,
userName: opts.U... | [
"func",
"NewCONNECT",
"(",
"opts",
"*",
"CONNECTOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"CONNECTOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"... | // NewCONNECT creates and returns a CONNECT Packet. | [
"NewCONNECT",
"creates",
"and",
"returns",
"a",
"CONNECT",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/connect.go#L121-L156 |
2,163 | yosssi/gmq | mqtt/packet/subscribe.go | NewSUBSCRIBE | func NewSUBSCRIBE(opts *SUBSCRIBEOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &SUBSCRIBEOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a SUBSCRIBE Packet.
p := &SUBSCRIBE{
PacketID: opts.PacketID,
SubReqs: opts... | go | func NewSUBSCRIBE(opts *SUBSCRIBEOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &SUBSCRIBEOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a SUBSCRIBE Packet.
p := &SUBSCRIBE{
PacketID: opts.PacketID,
SubReqs: opts... | [
"func",
"NewSUBSCRIBE",
"(",
"opts",
"*",
"SUBSCRIBEOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"SUBSCRIBEOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.... | // NewSUBSCRIBE creates and returns a SUBSCRIBE Packet. | [
"NewSUBSCRIBE",
"creates",
"and",
"returns",
"a",
"SUBSCRIBE",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/subscribe.go#L40-L68 |
2,164 | yosssi/gmq | mqtt/packet/packet.go | NewFromBytes | func NewFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Extract the MQTT Control Packet type from the fixed header.
ptype, err := fixedHeader.ptype()
if err != nil {
return nil, err
}
// Create and return a Packet.
switch ptype {
case TypeCONNACK:
return NewCONNACKFromBytes(fixedHe... | go | func NewFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Extract the MQTT Control Packet type from the fixed header.
ptype, err := fixedHeader.ptype()
if err != nil {
return nil, err
}
// Create and return a Packet.
switch ptype {
case TypeCONNACK:
return NewCONNACKFromBytes(fixedHe... | [
"func",
"NewFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Extract the MQTT Control Packet type from the fixed header.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
... | // NewFromBytes creates a Packet from the byte data and returns it. | [
"NewFromBytes",
"creates",
"a",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/packet.go#L19-L49 |
2,165 | yosssi/gmq | mqtt/client/connection.go | newConnection | func newConnection(network, address string, tlsConfig *tls.Config) (*connection, error) {
// Define the local variables.
var conn net.Conn
var err error
// Connect to the address on the named network.
if tlsConfig != nil {
conn, err = tls.Dial(network, address, tlsConfig)
} else {
conn, err = net.Dial(networ... | go | func newConnection(network, address string, tlsConfig *tls.Config) (*connection, error) {
// Define the local variables.
var conn net.Conn
var err error
// Connect to the address on the named network.
if tlsConfig != nil {
conn, err = tls.Dial(network, address, tlsConfig)
} else {
conn, err = net.Dial(networ... | [
"func",
"newConnection",
"(",
"network",
",",
"address",
"string",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"connection",
",",
"error",
")",
"{",
"// Define the local variables.",
"var",
"conn",
"net",
".",
"Conn",
"\n",
"var",
"err",
"e... | // newConnection connects to the address on the named network,
// creates a Network Connection and returns it. | [
"newConnection",
"connects",
"to",
"the",
"address",
"on",
"the",
"named",
"network",
"creates",
"a",
"Network",
"Connection",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/connection.go#L55-L84 |
2,166 | yosssi/gmq | mqtt/packet/strings.go | appendLenStr | func appendLenStr(b []byte, s []byte) []byte {
b = append(b, encodeUint16(uint16(len(s)))...)
b = append(b, s...)
return b
} | go | func appendLenStr(b []byte, s []byte) []byte {
b = append(b, encodeUint16(uint16(len(s)))...)
b = append(b, s...)
return b
} | [
"func",
"appendLenStr",
"(",
"b",
"[",
"]",
"byte",
",",
"s",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"encodeUint16",
"(",
"uint16",
"(",
"len",
"(",
"s",
")",
")",
")",
"...",
")",
"\n",
"b",
"=",
"... | // appendLenStr appends the length of the strings
// and the strings to the byte slice. | [
"appendLenStr",
"appends",
"the",
"length",
"of",
"the",
"strings",
"and",
"the",
"strings",
"to",
"the",
"byte",
"slice",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/strings.go#L8-L12 |
2,167 | yosssi/gmq | mqtt/packet/publish.go | NewPUBLISH | func NewPUBLISH(opts *PUBLISHOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBLISHOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBLISH Packet.
p := &PUBLISH{
DUP: opts.DUP,
QoS: opts.QoS,
retai... | go | func NewPUBLISH(opts *PUBLISHOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBLISHOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBLISH Packet.
p := &PUBLISH{
DUP: opts.DUP,
QoS: opts.QoS,
retai... | [
"func",
"NewPUBLISH",
"(",
"opts",
"*",
"PUBLISHOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"PUBLISHOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"... | // NewPUBLISH creates and returns a PUBLISH Packet. | [
"NewPUBLISH",
"creates",
"and",
"returns",
"a",
"PUBLISH",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/publish.go#L80-L112 |
2,168 | yosssi/gmq | mqtt/packet/publish.go | NewPUBLISHFromBytes | func NewPUBLISHFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBLISHBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Get the first byte from the fixedHeader.
b := fixedHeader[0]
// Create a PUBLISH Packet.
p := &PUBLISH{
... | go | func NewPUBLISHFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBLISHBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Get the first byte from the fixedHeader.
b := fixedHeader[0]
// Create a PUBLISH Packet.
p := &PUBLISH{
... | [
"func",
"NewPUBLISHFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePUBLISHBytes",
"(",
"fixedHeader",
",",
"remaining",
")",
... | // NewPUBLISHFromBytes creates the PUBLISH Packet
// from the byte data and returns it. | [
"NewPUBLISHFromBytes",
"creates",
"the",
"PUBLISH",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/publish.go#L116-L171 |
2,169 | yosssi/gmq | mqtt/packet/publish.go | validatePUBLISHBytes | func validatePUBLISHBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) < minLenPUBLISHFixedHeader {
return ErrInvalidFixedHeaderLen
}
/... | go | func validatePUBLISHBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) < minLenPUBLISHFixedHeader {
return ErrInvalidFixedHeaderLen
}
/... | [
"func",
"validatePUBLISHBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // validatePUBLISHBytes validates the fixed header and the variable header. | [
"validatePUBLISHBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/publish.go#L174-L235 |
2,170 | yosssi/gmq | cmd/gmq-cli/main.go | printError | func printError(err error) {
// Do nothing is the error is errCmdArgsParse.
if err == errCmdArgsParse {
return
}
fmt.Fprintln(os.Stderr, err)
// Print the help of the GMQ Client commands if the error is errInvalidCmdName.
if err == errInvalidCmdName {
fmt.Println()
printHelp()
}
} | go | func printError(err error) {
// Do nothing is the error is errCmdArgsParse.
if err == errCmdArgsParse {
return
}
fmt.Fprintln(os.Stderr, err)
// Print the help of the GMQ Client commands if the error is errInvalidCmdName.
if err == errInvalidCmdName {
fmt.Println()
printHelp()
}
} | [
"func",
"printError",
"(",
"err",
"error",
")",
"{",
"// Do nothing is the error is errCmdArgsParse.",
"if",
"err",
"==",
"errCmdArgsParse",
"{",
"return",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"err",
")",
"\n\n",
"// Print ... | // printError prints the error to the standard error. | [
"printError",
"prints",
"the",
"error",
"to",
"the",
"standard",
"error",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/cmd/gmq-cli/main.go#L101-L114 |
2,171 | yosssi/gmq | cmd/gmq-cli/main.go | cmdNameArgs | func cmdNameArgs(s string) (string, []string) {
// Split the string into the tokens.
tokens := strings.Split(strings.TrimSpace(s), " ")
// Get the command name from the tokens.
cmdName := tokens[0]
// Get the command arguments from the tokens.
cmdArgs := make([]string, 0, len(tokens[1:]))
for _, t := range tok... | go | func cmdNameArgs(s string) (string, []string) {
// Split the string into the tokens.
tokens := strings.Split(strings.TrimSpace(s), " ")
// Get the command name from the tokens.
cmdName := tokens[0]
// Get the command arguments from the tokens.
cmdArgs := make([]string, 0, len(tokens[1:]))
for _, t := range tok... | [
"func",
"cmdNameArgs",
"(",
"s",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
")",
"{",
"// Split the string into the tokens.",
"tokens",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
",",
"\"",
"\"",
")",
"\n\... | // cmdNameArgs extracts the command name and the command arguments from
// the parameter string. | [
"cmdNameArgs",
"extracts",
"the",
"command",
"name",
"and",
"the",
"command",
"arguments",
"from",
"the",
"parameter",
"string",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/cmd/gmq-cli/main.go#L118-L138 |
2,172 | yosssi/gmq | mqtt/packet/pubcomp.go | NewPUBCOMP | func NewPUBCOMP(opts *PUBCOMPOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBCOMPOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBCOMP Packet.
p := &PUBCOMP{
PacketID: opts.PacketID,
}
// Set the variable h... | go | func NewPUBCOMP(opts *PUBCOMPOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBCOMPOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBCOMP Packet.
p := &PUBCOMP{
PacketID: opts.PacketID,
}
// Set the variable h... | [
"func",
"NewPUBCOMP",
"(",
"opts",
"*",
"PUBCOMPOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"PUBCOMPOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"... | // NewPUBCOMP creates and returns a PUBCOMP Packet. | [
"NewPUBCOMP",
"creates",
"and",
"returns",
"a",
"PUBCOMP",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubcomp.go#L32-L56 |
2,173 | yosssi/gmq | mqtt/packet/pubcomp.go | NewPUBCOMPFromBytes | func NewPUBCOMPFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBCOMPBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the ret... | go | func NewPUBCOMPFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBCOMPBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the ret... | [
"func",
"NewPUBCOMPFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePUBCOMPBytes",
"(",
"fixedHeader",
",",
"variableHeader",... | // NewPUBCOMPFromBytes creates a PUBCOMP Packet
// from the byte data and returns it. | [
"NewPUBCOMPFromBytes",
"creates",
"a",
"PUBCOMP",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubcomp.go#L60-L84 |
2,174 | yosssi/gmq | mqtt/packet/pubcomp.go | validatePUBCOMPBytes | func validatePUBCOMPBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBCOMPFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | go | func validatePUBCOMPBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBCOMPFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | [
"func",
"validatePUBCOMPBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
... | // validatePUBCOMPBytes validates the fixed header and the variable header. | [
"validatePUBCOMPBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubcomp.go#L87-L128 |
2,175 | yosssi/gmq | cmd/gmq-cli/command.go | newCommand | func newCommand(cmdName string, cmdArgs []string, cli *client.Client) (command, error) {
switch cmdName {
case cmdNameConn:
return newCommandConn(cmdArgs, cli)
case cmdNameDisconn:
return newCommandDisconn(cli), nil
case cmdNameHelp:
return newCommandHelp(), nil
case cmdNamePub:
return newCommandPub(cmdArg... | go | func newCommand(cmdName string, cmdArgs []string, cli *client.Client) (command, error) {
switch cmdName {
case cmdNameConn:
return newCommandConn(cmdArgs, cli)
case cmdNameDisconn:
return newCommandDisconn(cli), nil
case cmdNameHelp:
return newCommandHelp(), nil
case cmdNamePub:
return newCommandPub(cmdArg... | [
"func",
"newCommand",
"(",
"cmdName",
"string",
",",
"cmdArgs",
"[",
"]",
"string",
",",
"cli",
"*",
"client",
".",
"Client",
")",
"(",
"command",
",",
"error",
")",
"{",
"switch",
"cmdName",
"{",
"case",
"cmdNameConn",
":",
"return",
"newCommandConn",
"... | // newCommand creates and returns a command. | [
"newCommand",
"creates",
"and",
"returns",
"a",
"command",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/cmd/gmq-cli/command.go#L21-L40 |
2,176 | yosssi/gmq | mqtt/packet/encode.go | encodeLength | func encodeLength(n uint32) uint32 {
var value, digit uint32
for n > 0 {
if value != 0 {
value <<= 8
}
digit = n % 128
n /= 128
if n > 0 {
digit |= 0x80
}
value |= digit
}
return value
} | go | func encodeLength(n uint32) uint32 {
var value, digit uint32
for n > 0 {
if value != 0 {
value <<= 8
}
digit = n % 128
n /= 128
if n > 0 {
digit |= 0x80
}
value |= digit
}
return value
} | [
"func",
"encodeLength",
"(",
"n",
"uint32",
")",
"uint32",
"{",
"var",
"value",
",",
"digit",
"uint32",
"\n\n",
"for",
"n",
">",
"0",
"{",
"if",
"value",
"!=",
"0",
"{",
"value",
"<<=",
"8",
"\n",
"}",
"\n\n",
"digit",
"=",
"n",
"%",
"128",
"\n\n... | // encodeLength encodes the unsigned integer
// by using a variable length encoding scheme. | [
"encodeLength",
"encodes",
"the",
"unsigned",
"integer",
"by",
"using",
"a",
"variable",
"length",
"encoding",
"scheme",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/encode.go#L11-L31 |
2,177 | yosssi/gmq | mqtt/packet/pingresp.go | NewPINGRESPFromBytes | func NewPINGRESPFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validatePINGRESPBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Create a PINGRESP Packet.
p := &PINGRESP{}
// Set the fixed header to the Packet.
p.fixedHeader = fixedH... | go | func NewPINGRESPFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
// Validate the byte data.
if err := validatePINGRESPBytes(fixedHeader, remaining); err != nil {
return nil, err
}
// Create a PINGRESP Packet.
p := &PINGRESP{}
// Set the fixed header to the Packet.
p.fixedHeader = fixedH... | [
"func",
"NewPINGRESPFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePINGRESPBytes",
"(",
"fixedHeader",
",",
"remaining",
")",
... | // NewPINGRESPFromBytes creates a PINGRESP Packet from
// the byte data and returns it. | [
"NewPINGRESPFromBytes",
"creates",
"a",
"PINGRESP",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pingresp.go#L13-L27 |
2,178 | yosssi/gmq | mqtt/packet/pingresp.go | validatePINGRESPBytes | func validatePINGRESPBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPINGRESPFixedHeader {
return ErrInvalidFixedHeaderLen
}
/... | go | func validatePINGRESPBytes(fixedHeader FixedHeader, remaining []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPINGRESPFixedHeader {
return ErrInvalidFixedHeaderLen
}
/... | [
"func",
"validatePINGRESPBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"remaining",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil... | // validatePINGRESPBytes validates the fixed header and the remaining. | [
"validatePINGRESPBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"remaining",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pingresp.go#L30-L63 |
2,179 | yosssi/gmq | mqtt/qos.go | ValidQoS | func ValidQoS(qos byte) bool {
return qos == QoS0 || qos == QoS1 || qos == QoS2
} | go | func ValidQoS(qos byte) bool {
return qos == QoS0 || qos == QoS1 || qos == QoS2
} | [
"func",
"ValidQoS",
"(",
"qos",
"byte",
")",
"bool",
"{",
"return",
"qos",
"==",
"QoS0",
"||",
"qos",
"==",
"QoS1",
"||",
"qos",
"==",
"QoS2",
"\n",
"}"
] | // ValidQoS returns true if the input QoS equals to
// QoS0, QoS1 or QoS2. | [
"ValidQoS",
"returns",
"true",
"if",
"the",
"input",
"QoS",
"equals",
"to",
"QoS0",
"QoS1",
"or",
"QoS2",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/qos.go#L15-L17 |
2,180 | yosssi/gmq | mqtt/packet/sub_req.go | validate | func (s *SubReq) validate() error {
// Check the length of the Topic Filter.
l := len(s.TopicFilter)
if l == 0 {
return ErrNoTopicFilter
}
if l > maxStringsLen {
return ErrTopicFilterExceedsMaxStringsLen
}
// Check the QoS.
if !mqtt.ValidQoS(s.QoS) {
return ErrInvalidQoS
}
return nil
} | go | func (s *SubReq) validate() error {
// Check the length of the Topic Filter.
l := len(s.TopicFilter)
if l == 0 {
return ErrNoTopicFilter
}
if l > maxStringsLen {
return ErrTopicFilterExceedsMaxStringsLen
}
// Check the QoS.
if !mqtt.ValidQoS(s.QoS) {
return ErrInvalidQoS
}
return nil
} | [
"func",
"(",
"s",
"*",
"SubReq",
")",
"validate",
"(",
")",
"error",
"{",
"// Check the length of the Topic Filter.",
"l",
":=",
"len",
"(",
"s",
".",
"TopicFilter",
")",
"\n\n",
"if",
"l",
"==",
"0",
"{",
"return",
"ErrNoTopicFilter",
"\n",
"}",
"\n\n",
... | // validate validates the subscription request. | [
"validate",
"validates",
"the",
"subscription",
"request",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/sub_req.go#L24-L42 |
2,181 | yosssi/gmq | mqtt/packet/pubrel.go | NewPUBREL | func NewPUBREL(opts *PUBRELOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBRELOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBREL Packet.
p := &PUBREL{
PacketID: opts.PacketID,
}
// Set the variable header... | go | func NewPUBREL(opts *PUBRELOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBRELOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBREL Packet.
p := &PUBREL{
PacketID: opts.PacketID,
}
// Set the variable header... | [
"func",
"NewPUBREL",
"(",
"opts",
"*",
"PUBRELOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"PUBRELOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"if"... | // NewPUBREL creates and returns a PUBREL Packet. | [
"NewPUBREL",
"creates",
"and",
"returns",
"a",
"PUBREL",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrel.go#L32-L56 |
2,182 | yosssi/gmq | mqtt/packet/pubrel.go | NewPUBRELFromBytes | func NewPUBRELFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBRELBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | go | func NewPUBRELFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBRELBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | [
"func",
"NewPUBRELFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePUBRELBytes",
"(",
"fixedHeader",
",",
"variableHeader",
... | // NewPUBRELFromBytes creates a PUBREL Packet
// from the byte data and returns it. | [
"NewPUBRELFromBytes",
"creates",
"a",
"PUBREL",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrel.go#L60-L84 |
2,183 | yosssi/gmq | mqtt/packet/pubrel.go | validatePUBRELBytes | func validatePUBRELBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBRELFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | go | func validatePUBRELBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBRELFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | [
"func",
"validatePUBRELBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"... | // validatePUBRELBytes validates the fixed header and the variable header. | [
"validatePUBRELBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/pubrel.go#L87-L128 |
2,184 | yosssi/gmq | mqtt/packet/unsubscribe.go | NewUNSUBSCRIBE | func NewUNSUBSCRIBE(opts *UNSUBSCRIBEOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &UNSUBSCRIBEOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a SUBSCRIBE Packet.
p := &UNSUBSCRIBE{
PacketID: opts.PacketID,
To... | go | func NewUNSUBSCRIBE(opts *UNSUBSCRIBEOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &UNSUBSCRIBEOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a SUBSCRIBE Packet.
p := &UNSUBSCRIBE{
PacketID: opts.PacketID,
To... | [
"func",
"NewUNSUBSCRIBE",
"(",
"opts",
"*",
"UNSUBSCRIBEOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"UNSUBSCRIBEOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the op... | // NewUNSUBSCRIBE creates and returns an UNSUBSCRIBE Packet. | [
"NewUNSUBSCRIBE",
"creates",
"and",
"returns",
"an",
"UNSUBSCRIBE",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/unsubscribe.go#L37-L65 |
2,185 | yosssi/gmq | mqtt/packet/puback.go | NewPUBACK | func NewPUBACK(opts *PUBACKOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBACKOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBACK Packet.
p := &PUBACK{
PacketID: opts.PacketID,
}
// Set the variable header... | go | func NewPUBACK(opts *PUBACKOptions) (Packet, error) {
// Initialize the options.
if opts == nil {
opts = &PUBACKOptions{}
}
// Validate the options.
if err := opts.validate(); err != nil {
return nil, err
}
// Create a PUBACK Packet.
p := &PUBACK{
PacketID: opts.PacketID,
}
// Set the variable header... | [
"func",
"NewPUBACK",
"(",
"opts",
"*",
"PUBACKOptions",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"PUBACKOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"// Validate the options.",
"if"... | // NewPUBACK creates and returns a PUBACK Packet. | [
"NewPUBACK",
"creates",
"and",
"returns",
"a",
"PUBACK",
"Packet",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/puback.go#L32-L56 |
2,186 | yosssi/gmq | mqtt/packet/puback.go | NewPUBACKFromBytes | func NewPUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | go | func NewPUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validatePUBACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the retur... | [
"func",
"NewPUBACKFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validatePUBACKBytes",
"(",
"fixedHeader",
",",
"variableHeader",
... | // NewPUBACKFromBytes creates a PUBACK Packet
// from the byte data and returns it. | [
"NewPUBACKFromBytes",
"creates",
"a",
"PUBACK",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/puback.go#L60-L84 |
2,187 | yosssi/gmq | mqtt/packet/puback.go | validatePUBACKBytes | func validatePUBACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | go | func validatePUBACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenPUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
}
... | [
"func",
"validatePUBACKBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
"... | // validatePUBACKBytes validates the fixed header and the variable header. | [
"validatePUBACKBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/puback.go#L87-L128 |
2,188 | yosssi/gmq | mqtt/client/session.go | newSession | func newSession(cleanSession bool, clientID []byte) *session {
return &session{
cleanSession: cleanSession,
clientID: clientID,
sendingPackets: make(map[uint16]packet.Packet),
receivingPackets: make(map[uint16]packet.Packet),
}
} | go | func newSession(cleanSession bool, clientID []byte) *session {
return &session{
cleanSession: cleanSession,
clientID: clientID,
sendingPackets: make(map[uint16]packet.Packet),
receivingPackets: make(map[uint16]packet.Packet),
}
} | [
"func",
"newSession",
"(",
"cleanSession",
"bool",
",",
"clientID",
"[",
"]",
"byte",
")",
"*",
"session",
"{",
"return",
"&",
"session",
"{",
"cleanSession",
":",
"cleanSession",
",",
"clientID",
":",
"clientID",
",",
"sendingPackets",
":",
"make",
"(",
"... | // newSession creates and returns a Session. | [
"newSession",
"creates",
"and",
"returns",
"a",
"Session",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/session.go#L21-L28 |
2,189 | yosssi/gmq | mqtt/packet/fixed_header.go | ptype | func (fixedHeader FixedHeader) ptype() (byte, error) {
// Check the length of the fixed header.
if len(fixedHeader) < 1 {
return 0x00, ErrInvalidFixedHeaderLen
}
// Extract the MQTT Control Packet type from
// the fixed header and return it.
return fixedHeader[0] >> 4, nil
} | go | func (fixedHeader FixedHeader) ptype() (byte, error) {
// Check the length of the fixed header.
if len(fixedHeader) < 1 {
return 0x00, ErrInvalidFixedHeaderLen
}
// Extract the MQTT Control Packet type from
// the fixed header and return it.
return fixedHeader[0] >> 4, nil
} | [
"func",
"(",
"fixedHeader",
"FixedHeader",
")",
"ptype",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"// Check the length of the fixed header.",
"if",
"len",
"(",
"fixedHeader",
")",
"<",
"1",
"{",
"return",
"0x00",
",",
"ErrInvalidFixedHeaderLen",
"\n",
"}... | // ptype extracts the MQTT Control Packet type from
// the fixed header and returns it. | [
"ptype",
"extracts",
"the",
"MQTT",
"Control",
"Packet",
"type",
"from",
"the",
"fixed",
"header",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/fixed_header.go#L13-L22 |
2,190 | yosssi/gmq | mqtt/packet/unsuback.go | NewUNSUBACKFromBytes | func NewUNSUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validateUNSUBACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the r... | go | func NewUNSUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
// Validate the byte data.
if err := validateUNSUBACKBytes(fixedHeader, variableHeader); err != nil {
return nil, err
}
// Decode the Packet Identifier.
// No error occur because of the precedent validation and
// the r... | [
"func",
"NewUNSUBACKFromBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"(",
"Packet",
",",
"error",
")",
"{",
"// Validate the byte data.",
"if",
"err",
":=",
"validateUNSUBACKBytes",
"(",
"fixedHeader",
",",
"variableHeader... | // NewUNSUBACKFromBytes creates an UNSUBACK Packet
// from the byte data and returns it. | [
"NewUNSUBACKFromBytes",
"creates",
"an",
"UNSUBACK",
"Packet",
"from",
"the",
"byte",
"data",
"and",
"returns",
"it",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/unsuback.go#L18-L42 |
2,191 | yosssi/gmq | mqtt/packet/unsuback.go | validateUNSUBACKBytes | func validateUNSUBACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenUNSUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
... | go | func validateUNSUBACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
// Extract the MQTT Control Packet type.
ptype, err := fixedHeader.ptype()
if err != nil {
return err
}
// Check the length of the fixed header.
if len(fixedHeader) != lenUNSUBACKFixedHeader {
return ErrInvalidFixedHeaderLen
... | [
"func",
"validateUNSUBACKBytes",
"(",
"fixedHeader",
"FixedHeader",
",",
"variableHeader",
"[",
"]",
"byte",
")",
"error",
"{",
"// Extract the MQTT Control Packet type.",
"ptype",
",",
"err",
":=",
"fixedHeader",
".",
"ptype",
"(",
")",
"\n",
"if",
"err",
"!=",
... | // validateUNSUBACKBytes validates the fixed header and the variable header. | [
"validateUNSUBACKBytes",
"validates",
"the",
"fixed",
"header",
"and",
"the",
"variable",
"header",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/packet/unsuback.go#L45-L86 |
2,192 | yosssi/gmq | mqtt/client/client.go | Connect | func (cli *Client) Connect(opts *ConnectOptions) error {
// Lock for the connection.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Return an error if the Client has already connected to the Server.
if cli.conn != nil {
return ErrAlreadyConnected
}
// Initialize the options.
if opts == nil {
... | go | func (cli *Client) Connect(opts *ConnectOptions) error {
// Lock for the connection.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Return an error if the Client has already connected to the Server.
if cli.conn != nil {
return ErrAlreadyConnected
}
// Initialize the options.
if opts == nil {
... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"Connect",
"(",
"opts",
"*",
"ConnectOptions",
")",
"error",
"{",
"// Lock for the connection.",
"cli",
".",
"muConn",
".",
"Lock",
"(",
")",
"\n\n",
"// Unlock.",
"defer",
"cli",
".",
"muConn",
".",
"Unlock",
"(",
... | // Connect establishes a Network Connection to the Server and
// sends a CONNECT Packet to the Server. | [
"Connect",
"establishes",
"a",
"Network",
"Connection",
"to",
"the",
"Server",
"and",
"sends",
"a",
"CONNECT",
"Packet",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L59-L168 |
2,193 | yosssi/gmq | mqtt/client/client.go | Disconnect | func (cli *Client) Disconnect() error {
// Lock for the disconnection.
cli.muConn.Lock()
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
// Unlock.
cli.muConn.Unlock()
return ErrNotYetConnected
}
// Send a DISCONNECT Packet to the Server.
// Ignore the error re... | go | func (cli *Client) Disconnect() error {
// Lock for the disconnection.
cli.muConn.Lock()
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
// Unlock.
cli.muConn.Unlock()
return ErrNotYetConnected
}
// Send a DISCONNECT Packet to the Server.
// Ignore the error re... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"Disconnect",
"(",
")",
"error",
"{",
"// Lock for the disconnection.",
"cli",
".",
"muConn",
".",
"Lock",
"(",
")",
"\n\n",
"// Return an error if the Client has not yet connected to the Server.",
"if",
"cli",
".",
"conn",
"=... | // Disconnect sends a DISCONNECT Packet to the Server and
// closes the Network Connection. | [
"Disconnect",
"sends",
"a",
"DISCONNECT",
"Packet",
"to",
"the",
"Server",
"and",
"closes",
"the",
"Network",
"Connection",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L172-L229 |
2,194 | yosssi/gmq | mqtt/client/client.go | Publish | func (cli *Client) Publish(opts *PublishOptions) error {
// Lock for reading.
cli.muConn.RLock()
// Unlock.
defer cli.muConn.RUnlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Initialize the options.
if opts == nil {
opts = &PublishOptions{}
}
// Create a P... | go | func (cli *Client) Publish(opts *PublishOptions) error {
// Lock for reading.
cli.muConn.RLock()
// Unlock.
defer cli.muConn.RUnlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Initialize the options.
if opts == nil {
opts = &PublishOptions{}
}
// Create a P... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"Publish",
"(",
"opts",
"*",
"PublishOptions",
")",
"error",
"{",
"// Lock for reading.",
"cli",
".",
"muConn",
".",
"RLock",
"(",
")",
"\n\n",
"// Unlock.",
"defer",
"cli",
".",
"muConn",
".",
"RUnlock",
"(",
")",... | // Publish sends a PUBLISH Packet to the Server. | [
"Publish",
"sends",
"a",
"PUBLISH",
"Packet",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L232-L259 |
2,195 | yosssi/gmq | mqtt/client/client.go | Subscribe | func (cli *Client) Subscribe(opts *SubscribeOptions) error {
// Lock for reading and updating.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Check the existence of the options.
if opts == nil || len(opts.SubReqs)... | go | func (cli *Client) Subscribe(opts *SubscribeOptions) error {
// Lock for reading and updating.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Check the existence of the options.
if opts == nil || len(opts.SubReqs)... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"Subscribe",
"(",
"opts",
"*",
"SubscribeOptions",
")",
"error",
"{",
"// Lock for reading and updating.",
"cli",
".",
"muConn",
".",
"Lock",
"(",
")",
"\n\n",
"// Unlock.",
"defer",
"cli",
".",
"muConn",
".",
"Unlock"... | // Subscribe sends a SUBSCRIBE Packet to the Server. | [
"Subscribe",
"sends",
"a",
"SUBSCRIBE",
"Packet",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L262-L327 |
2,196 | yosssi/gmq | mqtt/client/client.go | Unsubscribe | func (cli *Client) Unsubscribe(opts *UnsubscribeOptions) error {
// Lock for reading and updating.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Check the existence of the options.
if opts == nil || len(opts.Topi... | go | func (cli *Client) Unsubscribe(opts *UnsubscribeOptions) error {
// Lock for reading and updating.
cli.muConn.Lock()
// Unlock.
defer cli.muConn.Unlock()
// Check the Network Connection.
if cli.conn == nil {
return ErrNotYetConnected
}
// Check the existence of the options.
if opts == nil || len(opts.Topi... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"Unsubscribe",
"(",
"opts",
"*",
"UnsubscribeOptions",
")",
"error",
"{",
"// Lock for reading and updating.",
"cli",
".",
"muConn",
".",
"Lock",
"(",
")",
"\n\n",
"// Unlock.",
"defer",
"cli",
".",
"muConn",
".",
"Unl... | // Unsubscribe sends an UNSUBSCRIBE Packet to the Server. | [
"Unsubscribe",
"sends",
"an",
"UNSUBSCRIBE",
"Packet",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L330-L379 |
2,197 | yosssi/gmq | mqtt/client/client.go | send | func (cli *Client) send(p packet.Packet) error {
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
return ErrNotYetConnected
}
// Write the Packet to the buffered writer.
if _, err := p.WriteTo(cli.conn.w); err != nil {
return err
}
// Flush the buffered writer.
re... | go | func (cli *Client) send(p packet.Packet) error {
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
return ErrNotYetConnected
}
// Write the Packet to the buffered writer.
if _, err := p.WriteTo(cli.conn.w); err != nil {
return err
}
// Flush the buffered writer.
re... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"send",
"(",
"p",
"packet",
".",
"Packet",
")",
"error",
"{",
"// Return an error if the Client has not yet connected to the Server.",
"if",
"cli",
".",
"conn",
"==",
"nil",
"{",
"return",
"ErrNotYetConnected",
"\n",
"}",
... | // send sends an MQTT Control Packet to the Server. | [
"send",
"sends",
"an",
"MQTT",
"Control",
"Packet",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L391-L404 |
2,198 | yosssi/gmq | mqtt/client/client.go | sendCONNECT | func (cli *Client) sendCONNECT(opts *packet.CONNECTOptions) error {
// Initialize the options.
if opts == nil {
opts = &packet.CONNECTOptions{}
}
// Create a CONNECT Packet.
p, err := packet.NewCONNECT(opts)
if err != nil {
return err
}
// Send a CONNECT Packet to the Server.
return cli.send(p)
} | go | func (cli *Client) sendCONNECT(opts *packet.CONNECTOptions) error {
// Initialize the options.
if opts == nil {
opts = &packet.CONNECTOptions{}
}
// Create a CONNECT Packet.
p, err := packet.NewCONNECT(opts)
if err != nil {
return err
}
// Send a CONNECT Packet to the Server.
return cli.send(p)
} | [
"func",
"(",
"cli",
"*",
"Client",
")",
"sendCONNECT",
"(",
"opts",
"*",
"packet",
".",
"CONNECTOptions",
")",
"error",
"{",
"// Initialize the options.",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"packet",
".",
"CONNECTOptions",
"{",
"}",
"\n",
... | // sendCONNECT creates a CONNECT Packet and sends it to the Server. | [
"sendCONNECT",
"creates",
"a",
"CONNECT",
"Packet",
"and",
"sends",
"it",
"to",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L407-L421 |
2,199 | yosssi/gmq | mqtt/client/client.go | receive | func (cli *Client) receive() (packet.Packet, error) {
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
return nil, ErrNotYetConnected
}
// Get the first byte of the Packet.
b, err := cli.conn.r.ReadByte()
if err != nil {
return nil, err
}
// Create the Fixed heade... | go | func (cli *Client) receive() (packet.Packet, error) {
// Return an error if the Client has not yet connected to the Server.
if cli.conn == nil {
return nil, ErrNotYetConnected
}
// Get the first byte of the Packet.
b, err := cli.conn.r.ReadByte()
if err != nil {
return nil, err
}
// Create the Fixed heade... | [
"func",
"(",
"cli",
"*",
"Client",
")",
"receive",
"(",
")",
"(",
"packet",
".",
"Packet",
",",
"error",
")",
"{",
"// Return an error if the Client has not yet connected to the Server.",
"if",
"cli",
".",
"conn",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNo... | // receive receives an MQTT Control Packet from the Server. | [
"receive",
"receives",
"an",
"MQTT",
"Control",
"Packet",
"from",
"the",
"Server",
"."
] | b221999646da8ea48ff0796c2b0191aa510d062e | https://github.com/yosssi/gmq/blob/b221999646da8ea48ff0796c2b0191aa510d062e/mqtt/client/client.go#L424-L472 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.