Topicid field initial

This commit is contained in:
Denis Zheleztsov 2018-01-04 22:59:09 +03:00
parent d826a868b9
commit b041fcd80b

View File

@ -5,9 +5,11 @@ import (
"encoding/json"
"errors"
"io/ioutil"
"log"
"net/http"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/google/uuid"
)
// ESDoc Elasticsearch document structure
@ -22,6 +24,7 @@ type ESDoc struct {
Tags string `json:"tags"`
Repto string `json:"repto"`
Address string `json:"address"`
TopicID string `json:"topicid"`
}
// ESConf ES connection settings
@ -31,6 +34,46 @@ type ESConf struct {
Type string
}
type topicid struct{}
// findTopicID for msgid
func (t topicid) findTopicID(msgid string) (string, error) {
var topicid string
return topicid, nil
}
// check if
func (t topicid) checkID(msg *ESDoc) (bool, func()) {
if msg.TopicID != "" {
return false, func() {}
}
if msg.Repto == "" {
var genTopicID = func() {
u := uuid.New()
log.Debug("New UUID " + u.String() + " for message " + msg.MsgID)
msg.TopicID = u.String()
}
return true, genTopicID
}
var findAndSetTopicID = func() {
topicid, err := t.findTopicID(msg.MsgID)
if err != nil {
log.Error(err.Error())
}
log.Debug("Topic ID " + topicid + " found for message " + msg.MsgID)
}
return true, findAndSetTopicID
}
// getorcreate topicID. Generate new unique topicID if message is start message
// Find top message and get it topicid if ESDoc.Repto is not empty
func (t topicid) getOrCreate(msg *ESDoc) error {
// TODO: write the code
return nil
}
// PutToIndex ...
func (es ESConf) PutToIndex(msg ESDoc) error {
putURI := strings.Join([]string{es.Host, es.Index, es.Type, msg.MsgID}, "/")