Skip to content

Commit

Permalink
inject without casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Piccoli committed Dec 4, 2019
1 parent f631657 commit 3dcc07f
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions pkg/services/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"crypto/x509"
"github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
"github.com/sarulabs/dingo"
"github.com/softonic/homing-pigeon/pkg/messages"
"github.com/softonic/homing-pigeon/pkg/readers"
Expand Down Expand Up @@ -134,9 +133,9 @@ var Container = []dingo.Def{
)
failOnError(err, "Failed to declare outer exchange")
err = ch.ExchangeBind(
config.OuterExchangeName,
config.OuterExchangeBindingKey,
config.ExchangeName,
config.OuterExchangeBindingKey,
config.OuterExchangeName,
false,
nil,
)
Expand Down Expand Up @@ -275,7 +274,7 @@ var Container = []dingo.Def{

{
Name: "ElasticsearchAdapter",
Build: func(bulk esapi.Bulk) (writeAdapters.WriteAdapter, error) {
Build: func() (writeAdapters.WriteAdapter, error) {
flushMaxSize, err := strconv.Atoi(os.Getenv("ELASTICSEARCH_FLUSH_MAX_SIZE"))
if err != nil {
flushMaxSize = 1
Expand All @@ -285,25 +284,16 @@ var Container = []dingo.Def{
if err != nil {
flushMaxIntervalMs = 1000
}
return &writeAdapters.Elasticsearch{
FlushMaxSize: flushMaxSize,
FlushInterval: time.Duration(flushMaxIntervalMs) * time.Millisecond,
Bulk: bulk,
}, nil
},
Params: dingo.Params{
"0": dingo.Service("ElasticsearchBulkClient"),
},
},
{
Name: "ElasticsearchBulkClient",
Build: func() (esapi.Bulk, error) {

es, err := elasticsearch.NewClient(elasticsearch.Config{})
if err != nil {
return nil, err
}

return es.Bulk, nil
return &writeAdapters.Elasticsearch{
FlushMaxSize: flushMaxSize,
FlushInterval: time.Duration(flushMaxIntervalMs) * time.Millisecond,
Bulk: es.Bulk,
}, nil
},
},
{
Expand Down

0 comments on commit 3dcc07f

Please sign in to comment.