elastic.go 714 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package elastic
  4. import (
  5. elastic "gopkg.in/olivere/elastic.v5"
  6. )
  7. // elastic客户端
  8. var client *elastic.Client
  9. // Setup 建立elasitc连接
  10. func Setup(addrs []string, sniff bool) {
  11. var err error
  12. client, err = elastic.NewClient(elastic.SetURL(addrs...), elastic.SetSniff(sniff),
  13. elastic.SetTraceLog(new(TraceLog)),
  14. elastic.SetInfoLog(new(InfoLog)),
  15. elastic.SetErrorLog(new(ErrorLog)))
  16. if err != nil {
  17. panic(err)
  18. }
  19. }
  20. // Client 获取elastic客户端
  21. func Client() *elastic.Client {
  22. return client
  23. }
  24. // Stop 停止elastic客户端运行
  25. func Stop() {
  26. if client != nil {
  27. client.Stop()
  28. }
  29. }