Last active
March 30, 2019 01:21
-
-
Save technovangelist/b48e95d995bc420eeab0 to your computer and use it in GitHub Desktop.
Trivial Expvar Sample Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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