()
| 31 | const DemoPrometheusURL = "https://demo.prometheus.io:443" |
| 32 | |
| 33 | func ExampleAPI_query() { |
| 34 | client, err := api.NewClient(api.Config{ |
| 35 | Address: DemoPrometheusURL, |
| 36 | }) |
| 37 | if err != nil { |
| 38 | fmt.Printf("Error creating client: %v\n", err) |
| 39 | os.Exit(1) |
| 40 | } |
| 41 | |
| 42 | v1api := v1.NewAPI(client) |
| 43 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 44 | defer cancel() |
| 45 | result, warnings, err := v1api.Query(ctx, "up", time.Now(), v1.WithTimeout(5*time.Second)) |
| 46 | if err != nil { |
| 47 | fmt.Printf("Error querying Prometheus: %v\n", err) |
| 48 | os.Exit(1) |
| 49 | } |
| 50 | if len(warnings) > 0 { |
| 51 | fmt.Printf("Warnings: %v\n", warnings) |
| 52 | } |
| 53 | fmt.Printf("Result:\n%v\n", result) |
| 54 | } |
| 55 | |
| 56 | func ExampleAPI_queryRange() { |
| 57 | client, err := api.NewClient(api.Config{ |
nothing calls this directly
no test coverage detected