add count, pop ingester

This commit is contained in:
alexisvisco 2019-03-25 16:38:18 +01:00
parent dd927a4ab4
commit df036ec680
2 changed files with 42 additions and 6 deletions

View file

@ -19,6 +19,7 @@ func main() {
}
channel := sonic.IngesterChannel{Connection: connection}
e = channel.Push("test", "default", "captain", "lol is truth")
fmt.Println(e)
c, e := channel.Count("test", "default", "captain")
fmt.Println(c, e)
}

View file

@ -1,6 +1,10 @@
package sonic
import "fmt"
import (
"fmt"
"strconv"
"strings"
)
type Ingestable interface {
Push(collection, bucket, object, text string) (err error)
@ -42,11 +46,42 @@ func (i IngesterChannel) Push(collection, bucket, object, text string) (err erro
}
func (i IngesterChannel) Pop(collection, bucket, object, text string) (err error) {
panic("implement me")
err = i.write(fmt.Sprintf("%s %s %s %s \"%s\"", pop, collection, bucket, object, text))
if err != nil {
return err
}
// sonic should sent OK
_, err = i.read()
if err != nil {
return err
}
return nil
}
func (i IngesterChannel) Count(collection, bucket, object string) (count int, err error) {
panic("implement me")
func (i IngesterChannel) Count(collection, bucket, object string) (cnt int, err error) {
err = i.write(fmt.Sprintf("%s %s %s", count, collection, buildCountQuery(bucket, object)))
if err != nil {
return 0, err
}
// RESULT NUMBER
r, err := i.read()
if err != nil {
return 0, err
}
return strconv.Atoi(r[7:])
}
func buildCountQuery(bucket, object string) string {
builder := strings.Builder{}
if bucket != "" {
builder.WriteString(bucket)
if object != "" {
builder.WriteString(" " + object)
}
}
return builder.String()
}
func (i IngesterChannel) FlushCollection(collection string) (err error) {