server

package
v0.0.0-...-05a1c04 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: MIT Imports: 25 Imported by: 0

README

Server

The server package is responsible for handling webserver requests for map tiles and various JSON endpoints describing the configured server. Example config:

[webserver]
port = ":9090"              # set something different than default ":8080"
ssl_cert = "fullchain.pem"  # ssl cert for serving by https
ssl_key = "privkey.pem"     # ssl key for serving by https


[webserver.headers]
Access-Control-Allow-Origin = "*"
Config properties
  • port (string): [Optional] Port and bind string. For example ":9090" or "127.0.0.1:9090". Defaults to ":8080"
  • hostname (string): [Optional] The hostname to use in the various JSON endpoints. This is useful if tegola is behind a proxy and can't read the API consumer's request host directly.
  • uri_prefix (string): [Optional] A prefix to add to all API routes. This is useful when tegola is behind a proxy (i.e. example.com/tegola). The prexfix will be added to all URLs included in the capabilities endpoint responses.
  • ssl_cert (string): [Optional, unless ssl_key provided] Path to a certificate file for serving through HTTPS
  • ssl_key (string): [Optional, unless ssl_cert provided] Path to a private key file for serving through HTTPS

Local development of the embedded viewer

Tegola's built in viewer code is stored in the static/ directory. In order to embed the static files into the tegola binary the package go-bindata is used. Once go-bindata is installed the following command can be used to generate a .go file for inclusion in the tegola binary:

go-bindata -pkg=bindata -o=bindata/bindata.go -ignore=.DS_Store static/...

go-bindata also supports a debug mode which is descried as "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk." This mode is ideal for development and can be configured using the following command:

go-bindata -debug -pkg=bindata -o=bindata/bindata.go -ignore=.DS_Store static/...

Disabling the viewer

The viewer can be excluded during building by using the build flag noViewer. For example, building tegola from the cmd/tegola directory:

go build -tags "noViewer"

Documentation

Overview

Package server implements the http frontend

Index

Constants

View Source
const (
	// MaxTileSize is 500k. Currently just throws a warning when tile
	// is larger than MaxTileSize
	MaxTileSize = 500000
)

Variables

View Source
var (
	// Version is the version of the software, this should be set by the main program, before starting up.
	// It is used by various Middleware to determine the version.
	Version string = "Version Not Set"

	// HostName is the name of the host to use for construction of URLS.
	// configurable via the tegola config.toml file (set in main.go)
	HostName string

	// Port is the port the server is listening on, used for construction of URLS.
	// configurable via the tegola config.toml file (set in main.go)
	Port string

	// SSLCert is a filepath to an SSL cert, this will be used to enable https
	SSLCert string

	// SSLKey is a filepath to an SSL key, this will be used to enable https
	SSLKey string

	// Headers is the map of user defined response headers.
	// configurable via the tegola config.toml file (set in main.go)
	Headers = map[string]string{}

	// URIPrefix sets a prefix on all server endpoints. This is often used
	// when the server sits behind a reverse proxy with a prefix (i.e. /tegola)
	URIPrefix = "/"

	// DefaultCORSHeaders define the default CORS response headers added to all requests
	DefaultCORSHeaders = map[string]string{
		"Access-Control-Allow-Origin":  "*",
		"Access-Control-Allow-Methods": "GET, OPTIONS",
	}
)
View Source
var URLRoot = func(r *http.Request) *url.URL {
	root := url.URL{
		Scheme: scheme(r),
		Host:   hostName(r),
	}

	return &root
}

URLRoot builds a string containing the scheme, host and port based on a combination of user defined values, headers and request parameters. The function is public so it can be overridden for other implementations.

Functions

func GZipHandler

func GZipHandler(next http.Handler) http.Handler

GZipHandler is responsible for determining if the incoming request should be served gzipped data. All response data is assumed to be compressed prior to being passed to this handler.

If the incoming request has the "Accept-Encoding" header set with the values of "gzip" or "*" the response header "Content-Encoding: gzip" is set and the compressed data is returned.

If no "Accept-Encoding" header is present or "Accept-Encoding" has a value of "gzip;q=0" or "*;q=0" the response is decompressed prior to being sent to the client.

func HeadersHandler

func HeadersHandler(next http.Handler) http.Handler

HeadersHandler is middleware for adding user defined response headers

func NewRouter

func NewRouter(a *atlas.Atlas) *httptreemux.TreeMux

NewRouter set's up the our routes.

func Start

func Start(a *atlas.Atlas, port string) *http.Server

Start starts the tile server binding to the provided port

func TileCacheHandler

func TileCacheHandler(a *atlas.Atlas, next http.Handler) http.Handler

TileCacheHandler implements a request cache for tiles on requests when the URLs have a /:z/:x/:y scheme suffix (i.e. /osm/1/3/4.pbf)

Types

type Capabilities

type Capabilities struct {
	Version string            `json:"version"`
	Maps    []CapabilitiesMap `json:"maps"`
}

type CapabilitiesLayer

type CapabilitiesLayer struct {
	Name    string   `json:"name"`
	Tiles   []string `json:"tiles"`
	MinZoom uint     `json:"minzoom"`
	MaxZoom uint     `json:"maxzoom"`
}

type CapabilitiesMap

type CapabilitiesMap struct {
	Name         string              `json:"name"`
	Attribution  string              `json:"attribution"`
	Bounds       *geom.Extent        `json:"bounds"`
	Center       [3]float64          `json:"center"`
	Tiles        []string            `json:"tiles"`
	Capabilities string              `json:"capabilities"`
	Layers       []CapabilitiesLayer `json:"layers"`
}

type FilePathPrefixStripper

type FilePathPrefixStripper struct {
	// contains filtered or unexported fields
}

func (*FilePathPrefixStripper) Open

func (fsps *FilePathPrefixStripper) Open(name string) (http.File, error)

type HandleCapabilities

type HandleCapabilities struct{}

func (HandleCapabilities) ServeHTTP

func (req HandleCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandleMapCapabilities

type HandleMapCapabilities struct {
	// contains filtered or unexported fields
}

func (HandleMapCapabilities) ServeHTTP

func (req HandleMapCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP returns details about a map according to the tileJSON spec (https://github.com/mapbox/tilejson-spec/tree/master/2.1.0)

URI scheme: /capabilities/:map_name.json map_name - map name in the config file

type HandleMapLayerZXY

type HandleMapLayerZXY struct {

	// the Atlas to use, nil (default) is the default atlas
	Atlas *atlas.Atlas
	// contains filtered or unexported fields
}

func (HandleMapLayerZXY) ServeHTTP

func (req HandleMapLayerZXY) ServeHTTP(w http.ResponseWriter, r *http.Request)

URI scheme: /maps/:map_name/:layer_name/:z/:x/:y map_name - map name in the config file layer_name - name of the single map layer to render z, x, y - tile coordinates as described in the Slippy Map Tilenames specification

z - zoom level
x - row
y - column

type HandleMapStyle

type HandleMapStyle struct {
	// contains filtered or unexported fields
}

func (HandleMapStyle) ServeHTTP

func (req HandleMapStyle) ServeHTTP(w http.ResponseWriter, r *http.Request)

returns details about a map according to the tileJSON spec (https://github.com/mapbox/tilejson-spec/tree/master/2.1.0)

URI scheme: /capabilities/:map_name.json

map_name - map name in the config file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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