package module
Version: v1.0.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 4 Imported by: 0



Build Status Build Status GoDoc Go Report Card GitHub issues License

Visigo is http middleware for page unique visits counting. It uses HyperLogLog as a counter, so it's pretty fast.

Warning: Visigo stores HyperLogLog++ in map, so this implementation should be used only on smaller sites.


HyperLogLog++ paper
Google article about HyperLogLog++

From Wikipedia

HyperLogLog is an algorithm for the count-distinct problem, approximating the number of distinct elements in a multiset. Calculating the exact cardinality of a multiset requires an amount of memory proportional to the cardinality, which is impractical for very large data sets. Probabilistic cardinality estimators, such as the HyperLogLog algorithm, use significantly less memory than this, at the cost of obtaining only an approximation of the cardinality. The HyperLogLog algorithm is able to estimate cardinalities of > 109 with a typical accuracy of 2%, using 1.5 kB of memory. HyperLogLog is an extension of the earlier LogLog algorithm, itself deriving from the 1984 Flajolet–Martin algorithm.


Via go get tool

$ go get


package main

import (


func main() {
	http.Handle("/", visigo.Counter(http.HandlerFunc(final)))
	http.Handle("/total", visigo.Counter(http.HandlerFunc(total)))
	http.ListenAndServe(":3000", nil)

func final(w http.ResponseWriter, r *http.Request) {
	count, _ := visigo.Visits(r)
	response := fmt.Sprintf("This page was viewed by %d unique visitors", count)

func total(w http.ResponseWriter, r *http.Request) {
	count, _ := visigo.TotalVisits()
	response := fmt.Sprintf("This website had %d unique visitors in total", count)


$ go test ./...


If you use Visigo on your site or in your project, please let me know!

If you have any issues, just feel free and open it in this repository, thanks!


The MIT License (MIT). Please see License File for more information.




This section is empty.


View Source
var ErrCount = errors.New("count not found or error in HyperLogLog")

ErrCount - error returned when you try to get count but didn't register middleware


func Counter

func Counter(next http.Handler) http.Handler

Counter - registers middleware for visits counting

func TotalVisits

func TotalVisits() (uint64, error)

TotalVisits gets total visits to all sites

func Visits

func Visits(r *http.Request) (uint64, error)

Visits - get visits for given URL


This section is empty.

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL