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.
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.
Index ¶
- Constants
- func AllowedLayersFromContext(ctx context.Context) (*[]string, bool)
- func BackgroundContext() context.Context
- func LayerPatternMatchesFromContext(ctx context.Context) (*map[string]string, bool)
- func LimitLayersFromContext(ctx context.Context) (*bool, bool)
- func MakeChildSpan(ctx context.Context, newRequest *TileRequest, providerName string, ...) (context.Context, trace.Span)
- func NewRequestContext(req *http.Request) context.Context
- func ParseZoomString(str string) ([]int, error)
- func RandomString() string
- func ReplaceConfigValues(rawConfig map[string]interface{}, keyTag string, ...) (map[string]interface{}, error)
- func ReplaceEnv(rawConfig map[string]interface{}) map[string]interface{}
- func ReqFromContext(ctx context.Context) (*http.Request, bool)
- func StartTimeFromContext(ctx context.Context) (time.Time, bool)
- func Ternary[T any](cond bool, a T, b T) T
- func UserIDFromContext(ctx context.Context) (*string, bool)
- type Bounds
- func (b Bounds) BufferRelative(pct float64) Bounds
- func (b Bounds) Centroid() (float64, float64)
- func (b Bounds) ConfineToPsuedoMercatorRange() Bounds
- func (b Bounds) Contains(b2 Bounds) bool
- func (b Bounds) FindTiles(layerName string, zoom uint, force bool) (*[]TileRequest, error)
- func (b Bounds) Height() float64
- func (b Bounds) Intersects(b2 Bounds) bool
- func (b Bounds) IsNullIsland() bool
- func (b Bounds) ToEWKT() string
- func (b Bounds) ToWKT() string
- func (b Bounds) Width() float64
- type Image
- type InvalidArgumentError
- type InvalidContentLengthError
- type InvalidContentTypeError
- type InvalidSridError
- type ProviderAuthError
- type RangeError
- type RemoteServerError
- type TileRequest
- func (t TileRequest) GetBounds() (*Bounds, error)
- func (t TileRequest) GetBoundsProjection(srid uint) (*Bounds, error)
- func (t TileRequest) IntersectsBounds(b Bounds) (bool, error)
- func (t TileRequest) IntersectsBoundsProjection(b Bounds, srid uint) (bool, error)
- func (t TileRequest) String() string
- func (t TileRequest) StringWithSeparator(sep string) string
- type TooManyTilesError
- type TypeOfError
- type TypedError
- type UnauthorizedError
Constants ¶
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 )
const ( SRIDWGS84 = 4326 SRIDPsuedoMercator = 3857 MaxZoom = 21 )
Variables ¶
This section is empty.
Functions ¶
func AllowedLayersFromContext ¶ added in v0.6.0
func BackgroundContext ¶
func LayerPatternMatchesFromContext ¶ added in v0.6.0
func LimitLayersFromContext ¶ added in v0.6.0
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 ParseZoomString ¶
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 ¶
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 StartTimeFromContext ¶ added in v0.6.0
Types ¶
type Bounds ¶
func AllowedAreaFromContext ¶ added in v0.6.0
func NewBoundsFromGeohash ¶
Generates a bounding box representation of a given geohash
func (Bounds) BufferRelative ¶ added in v0.8.0
func (Bounds) ConfineToPsuedoMercatorRange ¶ added in v0.8.0
func (Bounds) FindTiles ¶
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) Intersects ¶
Any part of this bounds and the bounds passed in touch
func (Bounds) IsNullIsland ¶
This bounds just has the default values (all coords are 0)
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
Generates an image struct from a combined byte array as generated by image.EncodeImage. For use in caches
type InvalidArgumentError ¶
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 ¶
func (e InvalidArgumentError) Type() TypeOfError
type InvalidContentLengthError ¶
type InvalidContentLengthError struct {
Length int
}
Indicates the provider returned an unacceptable content length based on the configuration
func (InvalidContentLengthError) Error ¶
func (e InvalidContentLengthError) Error() string
func (InvalidContentLengthError) External ¶
func (e InvalidContentLengthError) External(messages config.ErrorMessages) string
func (InvalidContentLengthError) Type ¶
func (e InvalidContentLengthError) Type() TypeOfError
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 ¶
func (e InvalidContentTypeError) Type() TypeOfError
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 (e ProviderAuthError) External(_ config.ErrorMessages) string
func (ProviderAuthError) Type ¶
func (e ProviderAuthError) Type() TypeOfError
type RangeError ¶
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 ¶
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 {
}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