viewLib

package module
v0.0.0-...-b4aae89 Latest Latest
Warning

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

Go to latest
Published: May 26, 2015 License: MIT Imports: 7 Imported by: 0

README

viewsLib

Website View Counter LIbrary

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Counter = struct {
	sync.RWMutex
	M map[string]int
}{M: make(map[string]int)}

Counter is an instance of a [pageName]pageView hash map. This is implemented with a mutex RW lock for concurrent R/W safety

View Source
var IPs = struct {
	sync.RWMutex
	M map[string]bool
}{M: make(map[string]bool)}

IPs is an instance of a [ipAdress]bool hash map. hash offers a easy implementation of a set with quick insertion. This is implemented with a mutex RW lock for concurrent R/W safety

View Source
var SaveDuration = time.Minute * 1

RefreshTime is how often the page views and IPs are saved to disk, set at a default of 1 minute

Functions

func AddPage

func AddPage(page string)

AddPage adds a new page to the Counter with 0 views

func DeletePage

func DeletePage(page string)

DeletePage deletes the page and its views from the counter

func GetNumberOfUniqueIPs

func GetNumberOfUniqueIPs(page string) (numberOfUniqueIPs int)

GetNumberOfUniqueIPs returns the number of unique IPs

func GetPageViews

func GetPageViews(page string) (count int, exists bool)

GetPageViews returns a boolean to indicate if a page is present in the counter. If it is it also returns the count, else count = 0

func ViewInc

func ViewInc(ip string, page string)

ViewInc locks the Counter and ip set mutexes, writes to both then unlocks

Types

type IPList

type IPList struct {
	IPs map[string]bool
}

IPList struct is used to marshal/unmarshal IP visitor data into JSON for disk storage

type SavePoint

type SavePoint struct {
	PageCounts  map[string]int
	UniqueViews int
}

SavePoint struct is used to marshal/unmarshal pageview data into JSON for disk storage

Jump to

Keyboard shortcuts

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