pkg

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: Apache-2.0 Imports: 21 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 (
	// Indicates an error with the geographic extent or tile coordinates requested. Generally a 400
	TypeOfErrorBounds = iota
	// Indicates an authentication related issue - note this is incoming auth, not outgoing auth. Generally a 401
	TypeOfErrorAuth
	// Indicates a provider did something unexpected. Maybe the API we're calling is down. Generally a 500
	TypeOfErrorProvider
	// Indicates something wrong with the incoming request besides what's covered in bounds
	TypeOfErrorBadRequest
	// Indicates something that doesn't fall into the above categories. This is usually a real problem that the operator needs to be aware of. Generally a 500
	TypeOfErrorOther
)
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)

func BackgroundContext

func BackgroundContext() context.Context

func LayerPatternMatchesFromContext added in v0.6.0

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

func LimitLayersFromContext added in v0.6.0

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

func MakeChildSpan added in v0.6.0

func MakeChildSpan(ctx context.Context, newRequest *TileRequest, providerName string, childSpanName string, functionName string) (context.Context, trace.Span)

Handles making a new context and span for entity wrappers to break down request flow. Make sure to End the span that is returned

func NewRequestContext

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

func ParseZoomString

func ParseZoomString(str string) ([]int, error)

Turns a string indicating a range of zoom levels into an explicit array of the zoom levels. Format `<zoom>|<zoom>-<zoom>[,<range>]` e.g. `4` or `1-5` or `1-3,6`

func RandomString

func RandomString() string

Generates a random string with alphanumeric characters. Specifics are prone to change. Not guaranteed to have cryptographic security

func ReplaceConfigValues

func ReplaceConfigValues(rawConfig map[string]interface{}, keyTag string, replacer func(string) (string, error)) (map[string]interface{}, error)

Find any string values that start with `keyTag.keyName` and replace it with replacer(keyName). Replaces the full value. Used for avoiding secrets in config so your configuration can be placed in source control

func ReplaceEnv

func ReplaceEnv(rawConfig map[string]interface{}) map[string]interface{}

Find any string values that start with `env.` and interpret the rest as an environment variable. Replaces the full value with the contents of the respective environment variable. Useful for avoiding secrets in config so your configuration can be placed in source control

func ReqFromContext added in v0.6.0

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

func StartTimeFromContext added in v0.6.0

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

func Ternary

func Ternary[T any](cond bool, a T, b T) T

cond ? a : b

func UserIDFromContext added in v0.6.0

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

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)

func NewBoundsFromGeohash

func NewBoundsFromGeohash(hashStr string) (Bounds, error)

Generates a bounding box representation of a given geohash

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

The bounds passed in is fully contained by this bounds

func (Bounds) FindTiles

func (b Bounds) FindTiles(layerName string, zoom uint, force bool) (*[]TileRequest, error)

Turns a bounding box into a list of the tiles contained in the bounds for an arbitrary zoom level. Limited to 10k tiles unless force is true, then it's limited to 2^32 tiles.

func (Bounds) Height added in v0.8.0

func (b Bounds) Height() float64

func (Bounds) Intersects

func (b Bounds) Intersects(b2 Bounds) bool

Any part of this bounds and the bounds passed in touch

func (Bounds) IsNullIsland

func (b Bounds) IsNullIsland() bool

This bounds just has the default values (all coords are 0)

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 {
	// A byte array containing the response data. Always an encoded file format - it shouldn't be raw RGB pixel values.
	Content []byte
	// The Content-Type to force the HTTP response type when returning this image. If an empty string we default to letting Go auto-detect content-type. Should be a valid mime if set
	ContentType string
	// If true it prevents recording this result in the cache
	ForceSkipCache bool
}

The main result type for tiles. Can include a result of any content type - primarily either raster or vector imagery type.

func DecodeImage added in v0.7.0

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

Generates an image struct from a combined byte array as generated by image.EncodeImage. For use in caches

func (Image) Encode added in v0.7.0

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

Encodes both content and content type from Image into a single byte array for use in caches

type InvalidArgumentError

type InvalidArgumentError struct {
	Name  string
	Value any
}

Indicates generally a 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
}

Indicates the provider returned an unacceptable content length based on the configuration

func (InvalidContentLengthError) Error

func (InvalidContentLengthError) External

func (InvalidContentLengthError) Type

type InvalidContentTypeError

type InvalidContentTypeError struct {
	ContentType string
}

Indicates the provider returned an unacceptable content type based on the configuration

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
}

The error used when a provider has an auth error. This special error is used by the application to indicate that a re-auth needs to occur. If the same error is passed back on that re-auth then it's treated as a normal error and returned back through API - therefore this is a provider error type, 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
}

Indicates an input from the user is outside the valid range allowed for a numeric parameter - primarily tile coordinates

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 RemoteServerError

type RemoteServerError struct {
	StatusCode int
}

Indicates the provider returned an unacceptable status code based on the configuration

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

Generates a string representation of the tile request with slash separators between values

func (TileRequest) StringWithSeparator added in v0.7.0

func (t TileRequest) StringWithSeparator(sep string) string

Generates a string representation of the tile request with an arbitrary separator between values

type TooManyTilesError

type TooManyTilesError struct {
	NumTiles uint64
}

Indicates too many tiles will be returned for a given request than the system can safely handle

func (TooManyTilesError) Error

func (e TooManyTilesError) Error() string

func (TooManyTilesError) External

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

func (TooManyTilesError) Type

func (e TooManyTilesError) Type() TypeOfError

type TypeOfError

type TypeOfError int

Indicates high level categories of errors, used to decide the HTTP status code to return and the level of logging to use for such an error

type TypedError

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

The main interface for errors returned through the application. Indicates the type or category of the error and separates the error message that should be reported externally (with localization using the configurable error messages) from the internal error for logs (which uses the traditional Error() interface)

type UnauthorizedError

type UnauthorizedError struct {
	Message string
}

General error for incoming auth issues. 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

Jump to

Keyboard shortcuts

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