elastic.go-bk 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package clinit
  2. import (
  3. elastic "gopkg.in/olivere/elastic.v5"
  4. )
  5. type ElasticErrorLog struct {
  6. }
  7. func (errLog *ElasticErrorLog) Printf(format string, v ...interface{}) {
  8. Error("", format, v...)
  9. }
  10. type ElasticInfoLog struct {
  11. }
  12. func (infoLog *ElasticInfoLog) Printf(format string, v ...interface{}) {
  13. Info("", format, v...)
  14. }
  15. type ElasticDebugLog struct {
  16. }
  17. func (debugLog *ElasticDebugLog) Printf(format string, v ...interface{}) {
  18. Debug("", format, v...)
  19. }
  20. var elasticClient *elastic.Client
  21. func InitElastic(addr string, sniff bool) {
  22. var err error
  23. elasticClient, err = elastic.NewClient(elastic.SetTraceLog(new(ElasticDebugLog)), elastic.SetInfoLog(new(ElasticInfoLog)),
  24. elastic.SetErrorLog(new(ElasticErrorLog)), elastic.SetSniff(sniff), elastic.SetURL(addr))
  25. if err != nil {
  26. panic(err)
  27. }
  28. }
  29. func GetElasticClient() *elastic.Client {
  30. return elasticClient
  31. }