MCPcopy
hub / github.com/elastic/go-elasticsearch / main

Function main

_examples/extension/main.go:66–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64}
65
66func main() {
67 log.SetFlags(0)
68
69 started := make(chan bool)
70
71 // --> Start the proxy server
72 //
73 go startServer(started)
74
75 esclient, err := elasticsearch.New(
76 elasticsearch.WithAddresses("http://localhost:"+port),
77 elasticsearch.WithLogger(&elastictransport.ColorLogger{Output: os.Stdout, EnableRequestBody: true, EnableResponseBody: true}),
78 )
79 if err != nil {
80 log.Fatalf("Error creating the client: %s", err)
81 }
82 defer func() {
83 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
84 defer cancel()
85 if err := esclient.Close(ctx); err != nil {
86 log.Fatalf("Error closing the client: %s\n", err)
87 }
88 }()
89
90 es := ExtendedClient{Client: esclient, Custom: &ExtendedAPI{esclient}}
91 <-started
92
93 // --> Call a regular Elasticsearch API
94 //
95 es.Cat.Health()
96
97 // --> Call a custom API
98 //
99 res, err := es.Custom.Example()
100 if err != nil {
101 log.Fatalf("Error calling custom API: %s", err)
102 }
103 defer res.Body.Close()
104 log.Println(res.Status())
105}
106
107func startServer(started chan<- bool) {
108 proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: "localhost:9200"})

Callers

nothing calls this directly

Calls 6

startServerFunction · 0.85
ExampleMethod · 0.80
CloseMethod · 0.65
WithTimeoutMethod · 0.45
HealthMethod · 0.45
StatusMethod · 0.45

Tested by

no test coverage detected