server

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 11 Imported by: 0

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 Country added in v0.14.1

func Country(r *http.Request) (loc string)

Country returns the location country code for the current request.

func Location added in v0.14.2

func Location(r *http.Request) (loc string)

Location returns both the registered and location country codes for the current request, if they are different.

func Registered added in v0.14.2

func Registered(r *http.Request) (loc string)

Registered returns the registered country codes for the current request.

func RemoteIP added in v1.2.0

func RemoteIP(r *http.Request) (ip string)

RemoteIP returns the originating IP address for the current request.

Types

type App

type App interface {

	// Routes registers handlers for web request paths.
	Routes() http.Handler
}

App is the interface provided by the web application.

type GeoBlocker added in v0.14.1

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 added in v0.14.1

func (gb *GeoBlocker) GeoBlock(next http.Handler) http.Handler

GeoBlock initialises and returns a handler to block IPs for some locations.

func (*GeoBlocker) Locate added in v1.2.0

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 added in v1.4.0

func (gb *GeoBlocker) RejectsCounted() (rejects int)

RejectsCounted returns a statistic of the total number of requests rejected, and resets the count.

func (*GeoBlocker) Start added in v0.14.1

func (gb *GeoBlocker) Start(countries []string)

Start initialises the geo-blocker.

func (*GeoBlocker) Stop added in v0.14.1

func (gb *GeoBlocker) Stop()

Stop ends geo-blocking.

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
}

Server specifies the parameters for a web server.

func (*Server) Serve

func (srv *Server) Serve(app App)

Serve runs the web server. It never returns.

Jump to

Keyboard shortcuts

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