Fix invalid Timer (gauge) example

The example method is assumed to be used as main() function. As a main()
function doesn't have any return values, the example doesn't compile and
is invalid.
This commit is contained in:
Tobias Schmidt 2017-02-28 11:13:17 -04:00
parent 69bb387064
commit ae77d82d88
1 changed files with 12 additions and 2 deletions

View File

@ -13,7 +13,11 @@
package prometheus_test
import "github.com/prometheus/client_golang/prometheus"
import (
"os"
"github.com/prometheus/client_golang/prometheus"
)
var (
// If a function is called rarely (i.e. not more often than scrapes
@ -27,7 +31,7 @@ var (
})
)
func ExampleTimer_gauge() error {
func run() error {
// The Set method of the Gauge is used to observe the duration.
timer := prometheus.NewTimer(prometheus.ObserverFunc(funcDuration.Set))
defer timer.ObserveDuration()
@ -36,3 +40,9 @@ func ExampleTimer_gauge() error {
// makes sure the function is still timed properly.
return nil
}
func ExampleTimer_gauge() {
if err := run(); err != nil {
os.Exit(1)
}
}