From e42cf7356467d7174efca0503be712898db28161 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 10 Oct 2018 01:18:52 +0800 Subject: [PATCH] fix es --- module/es/es.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/es/es.go b/module/es/es.go index 25cc4e9..fe22738 100644 --- a/module/es/es.go +++ b/module/es/es.go @@ -3,6 +3,7 @@ package es import ( "context" "fmt" + "time" "git.trj.tw/golang/mtfosbot/module/config" "github.com/olivere/elastic" @@ -24,11 +25,15 @@ func NewClient() (err error) { // PutLog - func PutLog(t string, body map[string]interface{}) (err error) { + if client == nil { + return + } if len(t) == 0 || body == nil { return } conf := config.GetConf() ctx := context.Background() + body["timestamp"] = time.Now().UnixNano() _, err = client.Index().Index(conf.Elasticsearch.Index).Type(t).BodyJson(body).Do(ctx) return }