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

Function Example_providers

otes/example_providers_test.go:13–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func Example_providers() {
14 if os.Getenv("ELASTICSEARCH_ADDR") == "" {
15 fmt.Println("set ELASTICSEARCH_ADDR to run example")
16 return
17 }
18 c := core.New(
19 core.WithInline("log.level", "none"),
20 core.WithInline("es.default.url", strings.Split(os.Getenv("ELASTICSEARCH_ADDR"), ",")),
21 )
22 c.ProvideEssentials()
23 c.Provide(otes.Providers(otes.WithClientConstructor(func(args otes.ClientArgs) (*elastic.Client, error) {
24 return elastic.NewClient(elastic.SetURL(args.Conf.URL...), elastic.SetGzip(true))
25 })))
26 c.Invoke(func(esClient *elastic.Client) {
27 running := esClient.IsRunning()
28 fmt.Println(running)
29 })
30 // Output:
31 // true
32}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
WithInlineFunction · 0.92
ProvidersFunction · 0.92
WithClientConstructorFunction · 0.92
ProvideEssentialsMethod · 0.80
ProvideMethod · 0.80
InvokeMethod · 0.80

Tested by

no test coverage detected