pkg

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2024 Michael Davis

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// Bad geographic extent or tile coordinates. Generally a 400
	TypeOfErrorBounds = iota
	// Incoming auth, not outgoing. Generally a 401
	TypeOfErrorAuth
	// A provider misbehaved, maybe because its upstream is down. Generally a 500
	TypeOfErrorProvider
	// Problems with the request besides bounds
	TypeOfErrorBadRequest
	// Usually a real problem the operator needs to know about. Generally a 500
	TypeOfErrorOther
	// Exceeded the configured server timeout. Generally a 503
	TypeOfErrorTimeout
	// Rejected by a rate limit. Generally a 429
	TypeOfErrorRateLimit
)
View Source
const (
	SRIDWGS84          = 4326
	SRIDPsuedoMercator = 3857
	MaxZoom            = 21
)

Variables

This section is empty.

Functions

func AllowedLayersFromContext added in v0.6.0

func AllowedLayersFromContext(ctx context.Context) (*[]string, bool)

Layers allowed via auth

func BackgroundContext

func BackgroundContext() context.Context

func CachedFromContext added in v0.12.0

func CachedFromContext(ctx context.Context) (*bool, bool)

Whether the served tile came from the layer's cache

func CopyAuthRestrictions added in v0.12.0

func CopyAuthRestrictions(from, to context.Context)

func LayerPatternMatchesFromContext added in v0.6.0

func LayerPatternMatchesFromContext(ctx context.Context) (*map[string]string, bool)

Maps each layer name parameter's configured key to its value from the URL, after any paramMap replacement

func LimitAreaPartialFromContext added in v0.9.1

func LimitAreaPartialFromContext(ctx context.Context) (*bool, bool)

True means the allowed area is checked with Intersects, false with Contains

func LimitLayersFromContext added in v0.6.0

func LimitLayersFromContext(ctx context.Context) (*bool, bool)

Distinguishes being restricted to no layers from being unrestricted

func NewRequestContext

func NewRequestContext(req *http.Request) context.Context

func RefDepthFromContext added in v0.10.0

func RefDepthFromContext(ctx context.Context) (*int, bool)

Internal forwards via the ref provider, to guard against cycles

func ReqFromContext added in v0.6.0

func ReqFromContext(ctx context.Context) (*http.Request, bool)

func SetIdentity added in v0.12.0

func SetIdentity(ctx context.Context, userID, tenantID string)

Identity an offline run (seed, test) acts as, standing in for what auth sets on a real request

func StartTimeFromContext added in v0.6.0

func StartTimeFromContext(ctx context.Context) (time.Time, bool)

When the request was received

func TenantIDFromContext added in v0.12.0

func TenantIDFromContext(ctx context.Context) (*string, bool)

Set when auth can identify the tenant

func UserIDFromContext added in v0.6.0

func UserIDFromContext(ctx context.Context) (*string, bool)

Set when auth can identify the user

Types

type Bounds

type Bounds struct {
	South float64
	North float64
	West  float64
	East  float64
	SRID  uint
}

func AllowedAreaFromContext added in v0.6.0

func AllowedAreaFromContext(ctx context.Context) (*Bounds, bool)

Restricts the map to an area unless null island

func BoundsFromConfig added in v0.13.0

func BoundsFromConfig(b config.BoundsConfig) Bounds

func NewBoundsFromGeohash

func NewBoundsFromGeohash(hashStr string) (Bounds, error)

func WorldBounds added in v0.11.0

func WorldBounds() Bounds

The whole world clipped to the Web Mercator grid's latitude range. The default extent for anything unbounded

func (Bounds) BufferRelative added in v0.8.0

func (b Bounds) BufferRelative(pct float64) Bounds

func (Bounds) Centroid added in v0.8.0

func (b Bounds) Centroid() (float64, float64)

func (Bounds) ConfineToPsuedoMercatorRange added in v0.8.0

func (b Bounds) ConfineToPsuedoMercatorRange() Bounds

func (Bounds) Contains

func (b Bounds) Contains(b2 Bounds) bool

b2 is fully contained by b

func (Bounds) ContainsPoint added in v0.9.1

func (b Bounds) ContainsPoint(x float64, y float64) bool

func (Bounds) ConvertToPsuedoMercatorRange added in v0.9.1

func (b Bounds) ConvertToPsuedoMercatorRange() Bounds

func (Bounds) Height added in v0.8.0

func (b Bounds) Height() float64

func (Bounds) IntersectionWith added in v0.11.0

func (b Bounds) IntersectionWith(b2 Bounds) Bounds

Only meaningful when the two intersect. Otherwise South > North or West > East

func (Bounds) Intersects

func (b Bounds) Intersects(b2 Bounds) bool

Any part of the two bounds touch

func (Bounds) IsNullIsland

func (b Bounds) IsNullIsland() bool

All coordinates are zero

func (Bounds) ToConfig added in v0.13.0

func (b Bounds) ToConfig() config.BoundsConfig

func (Bounds) ToEWKT added in v0.8.0

func (b Bounds) ToEWKT() string

func (Bounds) ToWKT added in v0.8.0

func (b Bounds) ToWKT() string

func (Bounds) Width added in v0.8.0

func (b Bounds) Width() float64

type Image

type Image struct {
	// Always an encoded file format, never raw RGB pixel values
	Content []byte
	// Forces the response Content-Type. Empty lets Go auto-detect. Should be a valid mime if set
	ContentType string
	// Prevents caching this result
	ForceSkipCache bool
	// Epoch seconds. Zero if unknown, e.g. decoded from a v1 payload
	CreatedAt int64
}

The main result type for tiles, usually raster or vector imagery but any content type is allowed

func DecodeImage added in v0.7.0

func DecodeImage(b []byte) (*Image, error)

Reverses Image.Encode

func GetTile added in v0.10.0

func GetTile(ctx context.Context, clientConfig config.ClientConfig, url string, authHeaders map[string]string) (*Image, error)

Doesn't apply TLS profiles. Providers given a transport in their deps should use GetTileWithTransport

func GetTileWithTransport added in v0.15.0

func GetTileWithTransport(ctx context.Context, clientConfig config.ClientConfig, roundTripper http.RoundTripper, url string, authHeaders map[string]string) (*Image, error)

Applies the standard Client config: headers, timeout, allowlists, content-type rewriting and length limits. A nil transport means http.DefaultTransport. Custom Go providers should use it too

func (*Image) Encode added in v0.7.0

func (i *Image) Encode() ([]byte, error)

Combines content and content type into one byte array for caches

func (*Image) SetCreatedNow added in v0.11.0

func (i *Image) SetCreatedNow()

type InvalidArgumentError

type InvalidArgumentError struct {
	Name  string
	Value any
}

General bad input from the User

func (InvalidArgumentError) Error

func (e InvalidArgumentError) Error() string

func (InvalidArgumentError) External

func (e InvalidArgumentError) External(messages config.ErrorMessages) string

func (InvalidArgumentError) Type

type InvalidContentLengthError

type InvalidContentLengthError struct {
	Length int
}

The provider returned a content length the configuration doesn't allow

func (InvalidContentLengthError) Error

func (InvalidContentLengthError) External

func (InvalidContentLengthError) Type

type InvalidContentTypeError

type InvalidContentTypeError struct {
	ContentType string
}

The provider returned a content type the configuration doesn't allow

func (InvalidContentTypeError) Error

func (e InvalidContentTypeError) Error() string

func (InvalidContentTypeError) External

func (e InvalidContentTypeError) External(messages config.ErrorMessages) string

func (InvalidContentTypeError) Type

type InvalidSridError added in v0.6.0

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

func (InvalidSridError) Error added in v0.6.0

func (e InvalidSridError) Error() string

func (InvalidSridError) External added in v0.6.0

func (e InvalidSridError) External(messages config.ErrorMessages) string

func (InvalidSridError) Type added in v0.6.0

func (e InvalidSridError) Type() TypeOfError

type ProviderAuthError

type ProviderAuthError struct {
	Message string
}

Triggers a re-auth. If re-auth returns it again it's a normal provider error, not an auth one

func (ProviderAuthError) Error

func (e ProviderAuthError) Error() string

func (ProviderAuthError) External

func (ProviderAuthError) Type

func (e ProviderAuthError) Type() TypeOfError

type RangeError

type RangeError struct {
	ParamName string
	MinValue  float64
	MaxValue  float64
}

A numeric User input, primarily a tile coordinate, is outside its valid range

func (RangeError) Error

func (e RangeError) Error() string

func (RangeError) External

func (e RangeError) External(messages config.ErrorMessages) string

func (RangeError) Type

func (e RangeError) Type() TypeOfError

type RemoteConnectionError added in v0.13.0

type RemoteConnectionError struct {
	Cause   string
	Timeout bool
}

Indicates the request to a remote server failed without a response, such as a DNS failure, refused connection, or timeout. Never includes the URL or hostname since either can hold an operator's credentials.

func (RemoteConnectionError) Error added in v0.13.0

func (e RemoteConnectionError) Error() string

func (RemoteConnectionError) External added in v0.13.0

func (e RemoteConnectionError) External(messages config.ErrorMessages) string

func (RemoteConnectionError) Type added in v0.13.0

type RemoteServerError

type RemoteServerError struct {
	StatusCode int
}

The provider returned a status code the configuration doesn't allow

func (RemoteServerError) Error

func (e RemoteServerError) Error() string

func (RemoteServerError) External

func (e RemoteServerError) External(messages config.ErrorMessages) string

func (RemoteServerError) Type

func (e RemoteServerError) Type() TypeOfError

type TileRequest

type TileRequest struct {
	LayerName string
	Z         int
	X         int
	Y         int
}

func (TileRequest) GetBounds

func (t TileRequest) GetBounds() (*Bounds, error)

func (TileRequest) GetBoundsProjection added in v0.6.0

func (t TileRequest) GetBoundsProjection(srid uint) (*Bounds, error)

func (TileRequest) IntersectsBounds

func (t TileRequest) IntersectsBounds(b Bounds) (bool, error)

func (TileRequest) IntersectsBoundsProjection added in v0.6.0

func (t TileRequest) IntersectsBoundsProjection(b Bounds, srid uint) (bool, error)

func (TileRequest) String

func (t TileRequest) String() string

Slash separated

func (TileRequest) StringWithSeparator added in v0.7.0

func (t TileRequest) StringWithSeparator(sep string) string

type TimeoutError added in v0.11.0

type TimeoutError struct{}

The request ran longer than the configured server timeout

func (TimeoutError) Error added in v0.11.0

func (e TimeoutError) Error() string

func (TimeoutError) External added in v0.11.0

func (e TimeoutError) External(messages config.ErrorMessages) string

func (TimeoutError) Type added in v0.11.0

func (e TimeoutError) Type() TypeOfError

type TypeOfError

type TypeOfError int

Decides the HTTP status code and log level for an error

type TypedError

type TypedError interface {
	error
	Type() TypeOfError
	External(errorMessages config.ErrorMessages) string
}

Separates the localized external message from the internal Error() text used for logs

type UnauthorizedError

type UnauthorizedError struct {
	Message string
}

Avoids returning specifics through the API so as not to help attackers

func (UnauthorizedError) Error

func (e UnauthorizedError) Error() string

func (UnauthorizedError) External

func (e UnauthorizedError) External(messages config.ErrorMessages) string

func (UnauthorizedError) Type

func (e UnauthorizedError) Type() TypeOfError

Directories

Path Synopsis
entities
analytics
Package analytics records individual usage events per layer, coordinate and user, unlike telemetry's aggregate counters
Package analytics records individual usage events per layer, coordinate and user, unlike telemetry's aggregate counters
ratelimit
Package ratelimit defines the stores that hold rate limit counters.
Package ratelimit defines the stores that hold rate limit counters.

Jump to

Keyboard shortcuts

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