apiserver

package
v3.0.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2015 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package apiserver provides the freegeoip web server API, used by the freegeoip daemon tool.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMaker = KeyMakerFunc(func(r *http.Request) string {
	addr, _, _ := net.SplitHostPort(r.RemoteAddr)
	return addr
})

DefaultKeyMaker is a KeyMaker that returns the client IP address from http.Request.RemoteAddr.

View Source
var Version = "3.0.9"

Version tag.

Functions

func NewHandler

func NewHandler(conf *HandlerConfig) http.Handler

NewHandler creates a freegeoip http handler.

func Run

func Run() error

Run is the entrypoint for the freegeoip daemon tool.

Types

type ConnStateFunc

type ConnStateFunc func(c net.Conn, s http.ConnState)

ConnStateFunc is a function that can handle connection state.

func ConnStateMetrics

func ConnStateMetrics(proto string) ConnStateFunc

ConnStateMetrics collect metrics per connection state, per protocol. e.g. new http, closed http.

type HandlerConfig

type HandlerConfig struct {
	Prefix           string
	Origin           string
	PublicDir        string
	DB               *freegeoip.DB
	RateLimiter      RateLimiter
	UseXForwardedFor bool
}

HandlerConfig holds configuration for freegeoip http handlers.

type KeyMaker

type KeyMaker interface {
	KeyFor(r *http.Request) string
}

A KeyMaker makes keys from the http.Request object to the RateLimiter.

type KeyMakerFunc

type KeyMakerFunc func(r *http.Request) string

KeyMakerFunc is an adapter function for KeyMaker.

func (KeyMakerFunc) KeyFor

func (f KeyMakerFunc) KeyFor(r *http.Request) string

KeyFor implements the KeyMaker interface.

type RateLimiter

type RateLimiter struct {
	Redis    *redis.Client
	Max      int
	Interval time.Duration
	KeyMaker KeyMaker
	Handler  http.Handler
	// contains filtered or unexported fields
}

A RateLimiter is an http.Handler that wraps another handler, and calls it up to a certain limit, max per interval.

func (*RateLimiter) ServeHTTP

func (rl *RateLimiter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

Jump to

Keyboard shortcuts

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