Documentation ¶
Overview ¶
Package apiserver provides the freegeoip web server API, used by the freegeoip daemon tool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
var Version = "3.0.8"
Version tag.
Functions ¶
func NewHandler ¶
func NewHandler(conf *HandlerConfig) http.Handler
NewHandler creates a freegeoip http handler.
Types ¶
type ConnStateFunc ¶
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 KeyMakerFunc ¶
KeyMakerFunc is an adapter function for KeyMaker.
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.