api

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootPageName   = "index"
	TagCollections = "collections"
	TagItems       = "items"
	TagConformance = "conformance"
	TagAPI         = "api"

	TagFunctions = "functions"

	ParamCrs        = "crs"
	ParamLimit      = "limit"
	ParamOffset     = "offset"
	ParamBbox       = "bbox"
	ParamBboxCrs    = "bbox-crs"
	ParamFilter     = "filter"
	ParamFilterCrs  = "filter-crs"
	ParamGroupBy    = "groupby"
	ParamOrderBy    = "orderby"
	ParamPrecision  = "precision"
	ParamProperties = "properties"
	ParamSortBy     = "sortby"
	ParamTransform  = "transform"

	OrderByDirSep = ":"
	OrderByDirD   = "d"
	OrderByDirA   = "a"

	RelSelf        = "self"
	RelAlt         = "alternate"
	RelServiceDesc = "service-desc"
	RelServiceDoc  = "service-doc"
	RelConformance = "conformance"
	RelData        = "data"
	RelFunctions   = "functions"
	RelItems       = "items"

	TitleFeatuuresGeoJSON = "Features as GeoJSON"
	TitleDataJSON         = "Data as JSON"
	TitleMetadata         = "Metadata"
	TitleDocument         = "This document"
	TitleAsJSON           = " as JSON"
	TitleAsHTML           = " as HTML"

	GeoJSONFeatureCollection = "FeatureCollection"
)
View Source
const (
	ErrMsgEncoding              = "Error encoding response"
	ErrMsgLoadCollections       = "Unable to access Collections"
	ErrMsgCollectionNotFound    = "Collection not found: %v"
	ErrMsgCollectionAccess      = "Unable to access Collection: %v"
	ErrMsgFeatureNotFound       = "Feature not found: %v"
	ErrMsgLoadFunctions         = "Unable to access Functions"
	ErrMsgFunctionNotFound      = "Function not found: %v"
	ErrMsgFunctionAccess        = "Unable to access Function: %v"
	ErrMsgInvalidParameterValue = "Invalid value for parameter %v: %v"
	ErrMsgInvalidQuery          = "Invalid query parameters"
	ErrMsgDataReadError         = "Unable to read data from: %v"
	ErrMsgDataWriteError        = "Unable to write data to: %v"
	ErrMsgNoDataRead            = "No data read from: %v"
	ErrMsgRequestTimeout        = "Maximum time exceeded.  Request cancelled."
)
View Source
const (
	ErrCodeCollectionNotFound = "CollectionNotFound"
	ErrCodeFeatureNotFound    = "FeatureNotFound"
)
View Source
const (
	// ContentTypeJSON
	ContentTypeJSON = "application/json"

	// ContentTypeGeoJSON
	ContentTypeGeoJSON = "application/geo+json"

	// ContentTypeHTML
	ContentTypeHTML = "text/html"

	// ContentTypeText
	ContentTypeText = "text/plain"

	// ContentTypeSVG
	ContentTypeSVG = "image/svg+xml"

	// ContentTypeHTML
	ContentTypeOpenAPI = "application/vnd.oai.openapi+json;version=3.0"

	// FormatJSON code and extension for JSON
	FormatJSON = "json"

	// FormatHTML code and extension for HTML
	FormatHTML = "html"

	// FormatText code and extension for Text
	FormatText = "text"

	// FormatText code and extension for Text
	FormatSVG = "svg"
)

Variables

View Source
var BboxSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"bbox"},
	Properties: map[string]*openapi3.SchemaRef{
		"crs": {

			Value: openapi3.NewStringSchema(),
		},
		"bbox": {
			Value: &openapi3.Schema{
				Type:     "array",
				MinItems: 4,
				MaxItems: openapi3.Uint64Ptr(4),
				Items:    openapi3.NewSchemaRef("", openapi3.NewFloat64Schema().WithMin(-180).WithMax(180)),
			},
		},
	},
}
View Source
var CollectionInfoSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"id", "links"},
	Properties: map[string]*openapi3.SchemaRef{
		"id":          {Value: &openapi3.Schema{Type: "string"}},
		"title":       {Value: &openapi3.Schema{Type: "string"}},
		"description": {Value: &openapi3.Schema{Type: "string"}},
		"extent":      {Value: &ExtentSchema},
		"crs": {Value: &openapi3.Schema{
			Type: "array",
			Items: &openapi3.SchemaRef{
				Value: &openapi3.Schema{Type: "string"},
			},
		},
		},
		"geometrytype": {Value: &openapi3.Schema{Type: "string"}},
		"properties": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &PropertySchema},
		},
		},
		"links": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &LinkSchema},
		},
		},
	},
}
View Source
var CollectionsInfoSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"links", "collections"},
	Properties: map[string]*openapi3.SchemaRef{
		"links": {
			Value: &openapi3.Schema{
				Type: "array",
				Items: &openapi3.SchemaRef{
					Value: &LinkSchema,
				},
			},
		},
		"collections": {
			Value: &openapi3.Schema{
				Type: "array",
				Items: &openapi3.SchemaRef{
					Value: &CollectionInfoSchema,
				},
			},
		},
	},
}
View Source
var ConformanceSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"conformsTo"},
	Properties: map[string]*openapi3.SchemaRef{
		"conformsTo": {
			Value: &openapi3.Schema{
				Type: "array",
				Items: &openapi3.SchemaRef{
					Value: &openapi3.Schema{Type: "string"},
				},
			},
		},
	},
}
View Source
var ExtentSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"extent"},
	Properties: map[string]*openapi3.SchemaRef{
		"spatial": {Value: &BboxSchema},
	},
}
View Source
var FunctionInfoSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"id", "links"},
	Properties: map[string]*openapi3.SchemaRef{
		"id":          {Value: &openapi3.Schema{Type: "string"}},
		"description": {Value: &openapi3.Schema{Type: "string"}},
		"parameters": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &ParameterSchema},
		},
		},
		"properties": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &PropertySchema},
		},
		},
		"links": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &LinkSchema},
		},
		},
	},
}
View Source
var FunctionSummarySchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"id", "links"},
	Properties: map[string]*openapi3.SchemaRef{
		"id":          {Value: &openapi3.Schema{Type: "string"}},
		"description": {Value: &openapi3.Schema{Type: "string"}},
		"links": {Value: &openapi3.Schema{
			Type:  "array",
			Items: &openapi3.SchemaRef{Value: &LinkSchema},
		},
		},
	},
}
View Source
var FunctionsInfoSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"links", "functions"},
	Properties: map[string]*openapi3.SchemaRef{
		"links": {
			Value: &openapi3.Schema{
				Type:  "array",
				Items: &openapi3.SchemaRef{Value: &LinkSchema},
			},
		},
		"functions": {
			Value: &openapi3.Schema{
				Type:  "array",
				Items: &openapi3.SchemaRef{Value: &FunctionSummarySchema},
			},
		},
	},
}
View Source
var LinkSchema openapi3.Schema = openapi3.Schema{
	Description: "Describes links to other resources",
	Type:        "object",
	Required:    []string{"href"},
	Properties: map[string]*openapi3.SchemaRef{
		"href":     {Value: &openapi3.Schema{Type: "string", Description: "URL for the link"}},
		"rel":      {Value: &openapi3.Schema{Type: "string"}},
		"type":     {Value: &openapi3.Schema{Type: "string"}},
		"hreflang": {Value: &openapi3.Schema{Type: "string"}},
		"title":    {Value: &openapi3.Schema{Type: "string"}},
	},
}
View Source
var ParamReservedNamesMap = makeSet(ParamReservedNames)
View Source
var ParameterSchema openapi3.Schema = openapi3.Schema{
	Description: "A parameter of a function",
	Type:        "object",
	Required:    []string{"name", "type"},
	Properties: map[string]*openapi3.SchemaRef{
		"name":    {Value: &openapi3.Schema{Type: "string"}},
		"type":    {Value: &openapi3.Schema{Type: "string"}},
		"default": {Value: &openapi3.Schema{Type: "string"}},
	},
}
View Source
var PropertySchema openapi3.Schema = openapi3.Schema{
	Description: "A data property of a collection or function result",
	Type:        "object",
	Required:    []string{"name", "type"},
	Properties: map[string]*openapi3.SchemaRef{
		"name":        {Value: &openapi3.Schema{Type: "string"}},
		"type":        {Value: &openapi3.Schema{Type: "string"}},
		"description": {Value: &openapi3.Schema{Type: "string"}},
	},
}
View Source
var RootInfoSchema openapi3.Schema = openapi3.Schema{
	Type:     "object",
	Required: []string{"links"},
	Properties: map[string]*openapi3.SchemaRef{
		"title": {Value: &openapi3.Schema{
			Type:        "string",
			Description: "Title of this feature service",
		}},
		"description": {Value: &openapi3.Schema{
			Type:        "string",
			Description: "Description of this feature service",
		}},
		"links": {
			Value: &openapi3.Schema{
				Type:  "array",
				Items: &openapi3.SchemaRef{Value: &LinkSchema},
			},
		},
	},
}

Functions

func GetOpenAPIContent

func GetOpenAPIContent(urlBase string) *openapi3.Swagger

GetOpenAPIContent returns a Swagger OpenAPI structure

func IsParameterReservedName

func IsParameterReservedName(name string) bool

func PathCollection

func PathCollection(name string) string

func PathCollectionItems

func PathCollectionItems(name string) string

func PathFunction

func PathFunction(name string) string

func PathFunctionItems

func PathFunctionItems(name string) string

func PathItem

func PathItem(name string, fid string) string

func PathStripFormat

func PathStripFormat(path string) string

PathStripFormat removes a format extension from a path

func RequestedFormat

func RequestedFormat(r *http.Request) string

RequestedFormat gets the format for a request from extension or headers

func URLQuery

func URLQuery(url *url.URL) string

URLQuery gets the query part of a URL

Types

type Bbox

type Bbox struct {
	Crs    string    `json:"crs"`
	Extent []float64 `json:"bbox"`
}

Bbox for extent

type CollectionInfo

type CollectionInfo struct {
	Name         string   `json:"id"`
	Title        string   `json:"title,omitempty"`
	Description  string   `json:"description,omitempty"`
	Extent       *Extent  `json:"extent,omitempty"`
	Crs          []string `json:"crs,omitempty"`
	GeometryType *string  `json:"geometrytype,omitempty"`

	// these are omitempty so they don't show in summary metadata
	Properties []*Property `json:"properties,omitempty"`

	Links []*Link `json:"links"`
	// used for HTML response only
	URLMetadataHTML string `json:"-"`
	URLMetadataJSON string `json:"-"`
	URLItemsHTML    string `json:"-"`
	URLItemsJSON    string `json:"-"`
}

CollectionInfo for a collection

func NewCollectionInfo

func NewCollectionInfo(tbl *data.Table) *CollectionInfo

type CollectionsInfo

type CollectionsInfo struct {
	Links       []*Link           `json:"links"`
	Collections []*CollectionInfo `json:"collections"`
}

CollectionsInfo for all collections

func NewCollectionsInfo

func NewCollectionsInfo(tables []*data.Table) *CollectionsInfo

type Conformance

type Conformance struct {
	ConformsTo []string `json:"conformsTo"`
}

func GetConformance

func GetConformance() *Conformance

type Extent

type Extent struct {
	Spatial *Bbox `json:"spatial"`
}

Extent OAPIF Extent structure (partial)

type FeatureCollectionRaw

type FeatureCollectionRaw struct {
	Type           string             `json:"type"`
	Features       []*json.RawMessage `json:"features"`
	NumberMatched  uint               `json:"numberMatched,omitempty"`
	NumberReturned uint               `json:"numberReturned"`
	TimeStamp      string             `json:"timeStamp,omitempty"`
	Links          []*Link            `json:"links"`
}

FeatureCollection info

func NewFeatureCollectionInfo

func NewFeatureCollectionInfo(featureJSON []string) *FeatureCollectionRaw

type FunctionInfo

type FunctionInfo struct {
	Name        string `json:"id"`
	Description string `json:"description,omitempty"`

	// these properties are always present but may be empty arrays
	Parameters []*Parameter `json:"parameters"`
	Properties []*Property  `json:"properties"`

	Links []*Link `json:"links"`

	//--- additional data used during processing
	Function *data.Function `json:"-"`
}

FunctionInfo is the API metadata for a function

func NewFunctionInfo

func NewFunctionInfo(fn *data.Function) *FunctionInfo

type FunctionSummary

type FunctionSummary struct {
	Name        string  `json:"id"`
	Description string  `json:"description,omitempty"`
	Links       []*Link `json:"links"`

	//--- additional data used during processing
	Function *data.Function `json:"-"`
	// used for HTML response only
	URLMetadataHTML string `json:"-"`
	URLMetadataJSON string `json:"-"`
	URLItemsHTML    string `json:"-"`
	URLItemsJSON    string `json:"-"`
}

FunctionSummary contains a restricted set of function metadata for use in list display and JSON This allows not including parameters and properties in list metadata, but ensuring those keys are always present in full metadata JSON. Note: Collections do not follow same pattern because their list JSON metadata is supposed to contain all properties, and they are always expected to have attribute properties

func NewFunctionSummary

func NewFunctionSummary(fn *data.Function) *FunctionSummary

type FunctionsInfo

type FunctionsInfo struct {
	Links     []*Link            `json:"links"`
	Functions []*FunctionSummary `json:"functions"`
}

FunctionsInfo is the API metadata for all functions

func NewFunctionsInfo

func NewFunctionsInfo(fns []*data.Function) *FunctionsInfo
type Link struct {
	Href  string `json:"href"`
	Rel   string `json:"rel"`
	Type  string `json:"type"`
	Title string `json:"title"`
}

Link for links

func NewLink(href string, rel string, conType string, title string) *Link

type NameValMap

type NameValMap map[string]string

type Parameter

type Parameter struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Default     string `json:"default,omitempty"`
}

func FunctionParameters

func FunctionParameters(fn *data.Function) []*Parameter

type Property

type Property struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
}

func FunctionProperties

func FunctionProperties(fn *data.Function) []*Property

func TableProperties

func TableProperties(tbl *data.Table) []*Property

type RequestParam

type RequestParam struct {
	Crs           int
	Limit         int
	Offset        int
	Bbox          *data.Extent
	BboxCrs       int
	Properties    []string
	Filter        string
	FilterCrs     int
	GroupBy       []string
	SortBy        []data.Sorting
	Precision     int
	TransformFuns []data.TransformFunction
	Values        NameValMap
}

RequestParam holds the parameters for a request

type RootInfo

type RootInfo struct {
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Links       []*Link `json:"links"`
}

RootInfo content at root

func NewRootInfo

func NewRootInfo(conf *conf.Config) *RootInfo

Jump to

Keyboard shortcuts

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