()
| 64 | } |
| 65 | |
| 66 | func 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 | |
| 107 | func startServer(started chan<- bool) { |
| 108 | proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: "localhost:9200"}) |
nothing calls this directly
no test coverage detected