MCPcopy Create free account
hub / github.com/DoNewsCode/core / newClient

Function newClient

otes/dependency.go:113–158  ·  view source on GitHub ↗
(args ClientArgs)

Source from the content-addressed store, hash-verified

111}
112
113func newClient(args ClientArgs) (*elastic.Client, error) {
114 var options []elastic.ClientOptionFunc
115
116 var injected struct {
117 di.In
118
119 opentracing.Tracer `optional:"true"`
120 log.Logger
121 }
122
123 args.Populator.Populate(&injected)
124
125 if injected.Tracer != nil {
126 options = append(options,
127 elastic.SetHttpClient(
128 &http.Client{
129 Transport: NewTransport(WithTracer(injected.Tracer)),
130 },
131 ),
132 )
133 }
134
135 if args.Conf.Healthcheck != nil {
136 options = append(options, elastic.SetHealthcheck(*args.Conf.Healthcheck))
137 }
138
139 if args.Conf.Sniff != nil {
140 options = append(options, elastic.SetSniff(*args.Conf.Sniff))
141 }
142 logger := log.With(injected.Logger, "tag", "es")
143 options = append(options,
144 elastic.SetURL(args.Conf.URL...),
145 elastic.SetBasicAuth(args.Conf.Username, args.Conf.Password),
146 elastic.SetInfoLog(ElasticLogAdapter{level.Info(logger)}),
147 elastic.SetErrorLog(ElasticLogAdapter{level.Error(logger)}),
148 elastic.SetTraceLog(ElasticLogAdapter{level.Debug(logger)}),
149 )
150 client, err := elastic.NewClient(options...)
151 if err != nil {
152 client, err = elastic.NewSimpleClient(options...)
153 if err != nil {
154 return nil, err
155 }
156 }
157 return client, nil
158}
159
160func provideDefaultClient(maker Maker) (*elastic.Client, error) {
161 return maker.Make("default")

Callers 1

TestNewEsFactoryFunction · 0.85

Calls 7

NewTransportFunction · 0.70
WithTracerFunction · 0.70
PopulateMethod · 0.65
InfoMethod · 0.65
DebugMethod · 0.65
WithMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestNewEsFactoryFunction · 0.68