Documentation ¶
Overview ¶
Package server implements an HTTPS web server. The configuration is idiosyncratic, and not intended to be suitable for everyone.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Location ¶
Location returns both the registered and location country codes for the current request, if they are different.
func Registered ¶
Registered returns the registered country codes for the current request.
Types ¶
type GeoBlocker ¶
type GeoBlocker struct { Allow bool // permit only specified countries, instead of blocking them ErrorLog *log.Logger Reporter func(r *http.Request, location string, ip net.IP) string ReportSingle bool // report just location or registered country, not both Store string // storage location for database // contains filtered or unexported fields }
GeoBlocker holds the parameters and state for geo-blocking. Typically only one is needed.
func (*GeoBlocker) GeoBlock ¶
func (gb *GeoBlocker) GeoBlock(next http.Handler) http.Handler
GeoBlock initialises and returns a handler to block IPs for some locations.
func (*GeoBlocker) Locate ¶
func (gb *GeoBlocker) Locate(ipStr string) (country, registered string, ip net.IP)
Locate looks up a remote address in the geolocation database, and returns the countries of origin and registration.
func (*GeoBlocker) RejectsCounted ¶
func (gb *GeoBlocker) RejectsCounted() (rejects int)
RejectsCounted returns a statistic of the total number of requests rejected, and resets the count.
func (*GeoBlocker) Start ¶
func (gb *GeoBlocker) Start(countries []string)
Start initialises the geo-blocker.
type Server ¶
type Server struct { // logging ErrorLog *log.Logger InfoLog *log.Logger // HTTPS CertEmail string // notifications from Let's Encrypt CertPath string // folder for certificates Domains []string // domains to be served (empty for HTTP) // port addresses AddrHTTP string AddrHTTPS string Timeout time.Duration }
Server specifies the parameters for a web server.