4 changed files with 64 additions and 28 deletions
-
2.gitignore
-
6config.go
-
28elastic.go
-
54index.go
@ -1 +1 @@ |
|||||
./es |
|
||||
|
es |
@ -0,0 +1,28 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
elastic "github.com/olivere/elastic/v7" |
||||
|
"os" |
||||
|
) |
||||
|
|
||||
|
func ClientFromConfig(cfg ElasticConfiguration) *elastic.Client { |
||||
|
opts := []elastic.ClientOptionFunc{ |
||||
|
elastic.SetURL(cfg.URL), |
||||
|
elastic.SetSniff(false), |
||||
|
elastic.SetGzip(true), |
||||
|
} |
||||
|
if cfg.User != "" && cfg.Pass != "" { |
||||
|
opts = append(opts, elastic.SetBasicAuth( |
||||
|
cfg.User, cfg.Pass, |
||||
|
)) |
||||
|
} |
||||
|
|
||||
|
es, err := elastic.NewClient(opts...) |
||||
|
if err != nil { |
||||
|
fmt.Fprintf(os.Stderr, "Elastic connection error: %s\n", err.Error()) |
||||
|
os.Exit(1) |
||||
|
} |
||||
|
|
||||
|
return es |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue