Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Trivial Expvar Sample Code
package main
import (
"expvar"
"github.com/paulbellamy/ratecounter"
"io"
"net/http"
"strconv"
"time"
)
var (
counter *ratecounter.RateCounter
hitsperminute = expvar.NewInt("hits_per_minute")
)
func increment(w http.ResponseWriter, r *http.Request) {
counter.Incr(1)
hitsperminute.Set(counter.Rate())
io.WriteString(w, strconv.FormatInt(counter.Rate(), 10))
}
func main() {
counter = ratecounter.NewRateCounter(1 * time.Minute)
http.HandleFunc("/increment", increment)
http.ListenAndServe(":8000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment