Skip to content

Instantly share code, notes, and snippets.

@technovangelist
Last active March 30, 2019 01:21
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save technovangelist/b48e95d995bc420eeab0 to your computer and use it in GitHub Desktop.
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