Documentation
¶
Index ¶
- Constants
- Variables
- func CheckPing(db *sql.DB) error
- func CheckReadOnly(db *sql.DB) error
- func EnableCORS(s *Server) error
- func RowsToMaps(rows *sql.Rows, geomColumn string) ([]map[string]interface{}, error)
- func SimplifyShapes(s *Server) error
- type Cache
- type CacheConfig
- type Config
- type ConfigOption
- type Dict
- type DumbScanner
- type ElasticsearchConfig
- type ElasticsearchSource
- type Handler
- type InMemoryCache
- type InvalidRequestError
- type Layer
- type LayerConfig
- type NilCache
- type NilSource
- type PostGISConfig
- type PostGISSource
- type RedisCache
- type RedisConfig
- type Server
- type Source
- type SourceConfig
- type TileRequest
Constants ¶
const ( TableAlias = "__tilenol__table" // TODO: Externalize this? QueryTimeout = 30 * time.Second )
const ( // MinZoom is the absolute minimum zoom for a layer // tile requests with z-values lower than this will be rejected // layer configurations with Minzoom values lower than this will be rejected MinZoom = 0 // MaxZoom is the absolute maximum zoom for a layer // tile requests with z-values higher than this will be rejected // layer configurations with Maxzoom values lower than this will be rejected MaxZoom = 22 // MinSimplify is the minimum simplification radius MinSimplify = 1.0 // MaxSimplify is the maximum simplification radius MaxSimplify = 10.0 // AllLayers is the special request parameter for returning all source layers AllLayers = "_all" )
const ( // TODO: Externalize these? // SearchTimeout is the time.Duration to keep the search context alive SearchTimeout = 30 * time.Second )
Variables ¶
var ( MultipleSourcesErr = errors.New("Layers can only support a single backend source") NoSourcesErr = errors.New("Layers must have a single backend source configured") LayerMinZoomOutOfBoundsErr = errors.New("Layer Min zoom is below absolute min zoom") LayerMaxZoomOutOfBoundsErr = errors.New("Layer Max Zoom is above absolute max zoom") )
var ( InvalidTableConfig = errors.New("Either \"tableExpression\" or \"table\" + \"schema\" can be set, not both.") MissingTableConfig = errors.New("Either \"tableExpression\" or \"table\" + \"schema\" must be set.") )
var ( // ErrNoValue occurs when trying to access a value that doesn't exist in the cache ErrNoValue = errors.New("No value exists in cache") )
var (
InvalidGeometryErr = errors.New("Column value was not a valid geometry")
)
var ( // Logger is the global logging instance Logger = logrus.New() )
Functions ¶
func CheckReadOnly ¶ added in v1.0.4
CheckReadOnly warns if the current database connection is capable of read-write transactions
func EnableCORS ¶
EnableCORS configures the server for CORS (cross-origin resource sharing)
func RowsToMaps ¶ added in v1.0.4
RowsToMaps converts Go's sql.Rows data structure into a list of maps where the key is a string column name, and the value is the raw SQL value
func SimplifyShapes ¶
SimplifyShapes enables geometry simplification based on the requested zoom level
Types ¶
type Cache ¶
type Cache interface {
// Exists determines whether or not there is a cache value for the given key
Exists(key string) bool
// Get retrieves the cached data given a key
Get(key string) ([]byte, error)
// Put stores a new value in the cache at a given key
Put(key string, val []byte) error
}
Cache is a generic interface for a tile server cache
func CreateCache ¶
func CreateCache(config *CacheConfig) (Cache, error)
CreateCache creates a new generic Cache from a CacheConfig
func NewInMemoryCache ¶
func NewInMemoryCache() Cache
NewInMemoryCache allocates a new InMemoryCache
func NewRedisCache ¶
func NewRedisCache(config *RedisConfig) (Cache, error)
NewRedisCache creates a new RedisCache given a RedisConfig
type CacheConfig ¶
type CacheConfig struct {
// Redis is an optional YAML key for configuring a RedisCache
Redis *RedisConfig `yaml:"redis"`
}
CacheConfig is a generic YAML cache configuration object
type Config ¶
type Config struct {
// Cache configures the tile server cache
Cache *CacheConfig `yaml:"cache"`
// Layers configures the tile server layers
Layers []LayerConfig `yaml:"layers"`
}
Config is a YAML server configuration object
type ConfigOption ¶
ConfigOption is a function that changes a configuration setting of the server.Server
func ConfigFile ¶
func ConfigFile(configFile *os.File) ConfigOption
ConfigFile loads a YAML configuration file from disk to set up the server
func InternalPort ¶
func InternalPort(internalPort uint16) ConfigOption
InternalPort changes the port number used for administrative endpoints (e.g. healthcheck)
func Port ¶
func Port(port uint16) ConfigOption
Port changes the port number used for serving tile data
type Dict ¶
type Dict map[string]interface{}
Dict is a type alias for map[string]interface{} that cleans up literals and also adds a helper method to implement the elastic.Query interface
type DumbScanner ¶ added in v1.0.4
type DumbScanner struct {
Value interface{}
}
func (*DumbScanner) Scan ¶ added in v1.0.4
func (d *DumbScanner) Scan(src interface{}) error
type ElasticsearchConfig ¶
type ElasticsearchConfig struct {
// Hosts are the Elasticsearch cluster URLs
Hosts []string `yaml:"hosts"`
// Username is the HTTP basic auth username
Username string `yaml:"username"`
// Password is the HTTP basic auth username
Password string `yaml:"password"`
// Index is the name of the Elasticsearch index used for retrieving feature data
Index string `yaml:"index"`
// GeometryField is the name of the document field that holds the feature geometry
GeometryField string `yaml:"geometryField"`
// SourceFields is a mapping from the feature property name to the source document
// field name
SourceFields map[string]string `yaml:"sourceFields"`
}
ElasticsearchConfig is the YAML configuration structure for configuring a new ElasticsearchSource
type ElasticsearchSource ¶
type ElasticsearchSource struct {
// ES is the internal Elasticsearch cluster client
ES *elasticsearch.TypedClient
// Index is the name of the Elasticsearch index used for retrieving feature data
Index string
// GeometryField is the name of the document field that holds the feature geometry
GeometryField string
// SourceFields is a mapping from the feature property name to the source document
// field name
SourceFields map[string]string
}
ElasticsearchSource is a Source implementation that retrieves feature data from an Elasticsearch cluster
func (*ElasticsearchSource) GetFeatures ¶
func (e *ElasticsearchSource) GetFeatures(ctx context.Context, req *TileRequest) (*geojson.FeatureCollection, error)
GetFeatures implements the Source interface, to get feature data from an Elasticsearch cluster
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache implements the Cache interface backed by an in-memory map
func (*InMemoryCache) Exists ¶
func (i *InMemoryCache) Exists(key string) bool
Exists checks the internal map for the existence of the key
type InvalidRequestError ¶ added in v1.0.2
type InvalidRequestError struct {
// contains filtered or unexported fields
}
Error type for HTTP Status code 400
func (InvalidRequestError) Error ¶ added in v1.0.2
func (f InvalidRequestError) Error() string
type Layer ¶
type Layer struct {
Name string
Description string
Minzoom int
Maxzoom int
Cacheable bool
// contains filtered or unexported fields
}
Layer is a configured, hydrated tile server layer
func CreateLayer ¶
func CreateLayer(layerConfig LayerConfig) (*Layer, error)
CreateLayer creates a new Layer given a LayerConfig
func (Layer) GetFeatures ¶ added in v1.0.5
func (l Layer) GetFeatures(ctx context.Context, r *TileRequest) (*geojson.FeatureCollection, error)
GetFeatures implements a passthrough interface to the layer's underlying source
type LayerConfig ¶
type LayerConfig struct {
// Name is the effective name of the layer
Name string `yaml:"name"`
// Description is an optional short descriptor of the layer
Description string `yaml:"description"`
// Minzoom specifies the minimum z value for the layer
Minzoom int `yaml:"minzoom"`
// Maxzoom specifies the maximum z value for the layer
Maxzoom int `yaml:"maxzoom"`
// NoCache indicates that this layer should not cache its source data
NoCache bool `yaml:"nocache"`
// Source configures the underlying Source for the layer
Source SourceConfig `yaml:"source"`
}
LayerConfig represents a general YAML layer configuration object
type NilCache ¶
type NilCache struct{}
NilCache implements the Cache interface as a no-op
type NilSource ¶ added in v1.0.5
type NilSource struct{}
NilSource implements the Source interface with no data
func (*NilSource) GetFeatures ¶ added in v1.0.5
func (n *NilSource) GetFeatures(ctx context.Context, req *TileRequest) (*geojson.FeatureCollection, error)
GetFeatures returns no data for all requests
type PostGISConfig ¶ added in v1.0.4
type PostGISConfig struct {
// DSN is the "data source name" that specifies how to connect to the database server
DSN string `yaml:"dsn"`
// Schema is the table space to use for queries
Schema string `yaml:"schema"`
// Table is the name of the table to use for queries
Table string `yaml:"table"`
// TableExpression is a valid SQL query that is used as an alternative to Schema and Table
TableExpression string `yaml:"tableExpression"`
// GeometryField is the name of the column that holds the feature geometry
GeometryField string `yaml:"geometryField"`
// SourceFields is a mapping from the feature property name to the source row
// column names
SourceFields map[string]string `yaml:"sourceFields"`
}
PostGISConfig is the YAML configuration structure for configuring a new PostGISSource
func (*PostGISConfig) Dataset ¶ added in v1.0.4
func (c *PostGISConfig) Dataset() (*goqu.SelectDataset, error)
Dataset constructs a subquery to be used as the source table for all request-time queries
type PostGISSource ¶ added in v1.0.4
type PostGISSource struct {
DB *goqu.Database
Dataset *goqu.SelectDataset
GeometryField string
SourceFields map[string]string
}
PostGISSource is a Source implementation that retrieves feature data from a PostGIS server
func (*PostGISSource) GetFeatures ¶ added in v1.0.4
func (p *PostGISSource) GetFeatures(ctx context.Context, req *TileRequest) (*geojson.FeatureCollection, error)
GetFeatures implements the Source interface, to get feature data from an PostGIS server
type RedisCache ¶
type RedisCache struct {
// Client is the backend Redis cluster client
Client *redis.Client
// TTL is how long each cache entry should remain before refresh
TTL time.Duration
}
RedisCache is a Redis-backed Cache implementation
func (*RedisCache) Exists ¶
func (r *RedisCache) Exists(key string) bool
Exists tries to get the cached value for a key, returning whether or not the key exists
type RedisConfig ¶
type RedisConfig struct {
// Host is the Redis cluster host name
Host string `yaml:"host"`
// Port is the Redis cluster port number
Port int `yaml:"port"`
// TTL is how long each cache entry should remain before refresh
TTL time.Duration `yaml:"ttl"`
}
RedisConfig is the YAML configuration for a RedisCache
type Server ¶
type Server struct {
// Port is the port number to bind the tile server
Port uint16
// InternalPort is the port number to bind the internal metrics endpoints
InternalPort uint16
// EnableCORS configures whether or not the tile server responds with CORS headers
EnableCORS bool
// Simplify configures whether or not the tile server simplifies outgoing feature
// geometries based on zoom level
Simplify bool
// Layers is the list of configured layers supported by the tile server
Layers []Layer
// Cache is an optional cache object that the server uses to cache responses
Cache Cache
}
Server is a tilenol server instance
func NewServer ¶
func NewServer(configOpts ...ConfigOption) (*Server, error)
NewServer creates a new server instance pre-configured with the given ConfigOption's
type Source ¶
type Source interface {
// GetFeatures retrieves the GeoJSON FeatureCollection for the given request
GetFeatures(context.Context, *TileRequest) (*geojson.FeatureCollection, error)
}
Source is a generic interface for all feature data sources
func NewElasticsearchSource ¶
func NewElasticsearchSource(config *ElasticsearchConfig) (Source, error)
NewElasticsearchSource creates a new Source that retrieves feature data from an Elasticsearch cluster
func NewPostGISSource ¶ added in v1.0.4
func NewPostGISSource(config *PostGISConfig) (Source, error)
NewPostGISSource creates a new Source that retrieves feature data from a PostGIS server
type SourceConfig ¶
type SourceConfig struct {
// Elasticsearch is an optional YAML key for configuring an ElasticsearchConfig
Elasticsearch *ElasticsearchConfig `yaml:"elasticsearch"`
// PostGIS is an optional YAML key for configuring a PostGISConfig
PostGIS *PostGISConfig `yaml:"postgis"`
}
SourceConfig represents a generic YAML source configuration object
type TileRequest ¶
TileRequest is an object containing the tile request context
func MakeTileRequest ¶ added in v1.0.2
Sanitize TileRequest arguments and return an error if sanity checking fails.
func (*TileRequest) MapTile ¶
func (t *TileRequest) MapTile() maptile.Tile
MapTile creates a maptile.Tile object from the TileRequest
func (*TileRequest) String ¶ added in v1.0.5
func (r *TileRequest) String() string
