webcounter

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

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

Go to latest
Published: Jun 9, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

README

Webcounter challenge

Build Status

This project is based on https://github.com/SDGophers/2015-04-challenge and currently handles:

  • initial challenge phase
  • extra-credit of supporting multiple image types based on the request suffix (.txt/.jpg/.gif/.png)
  • 1,000 visitor level of per-referer counts

The main logic is exposed as a library github.com/billhathaway/webcounter

There is an executable available under the 'server' directory, which will run on port 8080 by default.

Startup is a little slow (3-5 secs) since per the challenge guidelines, it fetches the source image for the glyphs from the challenge's GH repo.

Running

go get github.com/billhathaway/webcounter/wcserver

wcserver // listening on port 8080 by default

hit server at http://localhost:8080/someid.png and refresh your browser a bunch and watch the count go up

Screen Shot of app

Microbenchmarks

Made using wrk against server running on localhost, iMac Mid-2011 (3.1Ghz Core i5), GOMAXPROCS=4

Request Type Rate/sec
.txt 74555
.jpg 480
.png 267
.gif 55

Testing

go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Controller provides a web-counter service

func New

func New() (*Controller, error)

New creates a new Controller

func (*Controller) Delete

func (c *Controller) Delete(id string)

Delete resets the count

func (*Controller) Get

func (c *Controller) Get(id string, referer string) int

Get retrieves the count by referrer and increments it by one

func (*Controller) ServeHTTP

func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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