@@ -199,6 +199,45 @@ func ExampleAPI_queryRangeWithAuthBearerToken() {
199199 fmt .Printf ("Result:\n %v\n " , result )
200200}
201201
202+ func ExampleAPI_queryRangeWithAuthBearerTokenHeadersRoundTripper () {
203+ client , err := api .NewClient (api.Config {
204+ Address : "http://demo.robustperception.io:9090" ,
205+ // We can use amazing github.com/prometheus/common/config helper!
206+ RoundTripper : config .NewHeadersRoundTripper (
207+ & config.Headers {
208+ Headers : map [string ]config.Header {
209+ "Authorization" : {
210+ Values : []string {"Bearer secret" },
211+ },
212+ },
213+ },
214+ api .DefaultRoundTripper ,
215+ ),
216+ })
217+ if err != nil {
218+ fmt .Printf ("Error creating client: %v\n " , err )
219+ os .Exit (1 )
220+ }
221+
222+ v1api := v1 .NewAPI (client )
223+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
224+ defer cancel ()
225+ r := v1.Range {
226+ Start : time .Now ().Add (- time .Hour ),
227+ End : time .Now (),
228+ Step : time .Minute ,
229+ }
230+ result , warnings , err := v1api .QueryRange (ctx , "rate(prometheus_tsdb_head_samples_appended_total[5m])" , r )
231+ if err != nil {
232+ fmt .Printf ("Error querying Prometheus: %v\n " , err )
233+ os .Exit (1 )
234+ }
235+ if len (warnings ) > 0 {
236+ fmt .Printf ("Warnings: %v\n " , warnings )
237+ }
238+ fmt .Printf ("Result:\n %v\n " , result )
239+ }
240+
202241func ExampleAPI_series () {
203242 client , err := api .NewClient (api.Config {
204243 Address : "http://demo.robustperception.io:9090" ,
0 commit comments