()
| 24 | ) |
| 25 | |
| 26 | func ExampleResponse_IsError() { |
| 27 | es, _ := elasticsearch.New() |
| 28 | |
| 29 | res, err := es.Info() |
| 30 | |
| 31 | // Handle connection errors |
| 32 | // |
| 33 | if err != nil { |
| 34 | log.Fatalf("ERROR: %v", err) |
| 35 | } |
| 36 | defer func() { _ = res.Body.Close() }() |
| 37 | |
| 38 | // Handle error response (3xx, 4xx, 5xx) |
| 39 | // |
| 40 | if res.IsError() { |
| 41 | log.Printf("ERROR: %s", res.Status()) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | // Handle successful response (2xx) |
| 46 | // |
| 47 | log.Println(res) |
| 48 | } |
| 49 | |
| 50 | func ExampleResponse_Status() { |
| 51 | es, _ := elasticsearch.New() |