fix es
This commit is contained in:
parent
7251c43a57
commit
e42cf73564
@ -3,6 +3,7 @@ package es
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.trj.tw/golang/mtfosbot/module/config"
|
"git.trj.tw/golang/mtfosbot/module/config"
|
||||||
"github.com/olivere/elastic"
|
"github.com/olivere/elastic"
|
||||||
@ -24,11 +25,15 @@ func NewClient() (err error) {
|
|||||||
|
|
||||||
// PutLog -
|
// PutLog -
|
||||||
func PutLog(t string, body map[string]interface{}) (err error) {
|
func PutLog(t string, body map[string]interface{}) (err error) {
|
||||||
|
if client == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(t) == 0 || body == nil {
|
if len(t) == 0 || body == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conf := config.GetConf()
|
conf := config.GetConf()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
body["timestamp"] = time.Now().UnixNano()
|
||||||
_, err = client.Index().Index(conf.Elasticsearch.Index).Type(t).BodyJson(body).Do(ctx)
|
_, err = client.Index().Index(conf.Elasticsearch.Index).Type(t).BodyJson(body).Do(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user