config

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 14 Imported by: 0

README

Config

This config package is used to validate and unmarshal a YAML config file to structs.

Documentation

Index

Constants

View Source
const (
	CookieMaxAge = 60 * 60 * 24
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectionLinks struct {
}

type Config

type Config struct {
	// Version of the API. When releasing a new version which contains backwards-incompatible changes, a new major version must be released.
	Version string `yaml:"version" json:"version" validate:"required,semver" default:"1.0.0"`

	// Human friendly title of the API.
	Title string `yaml:"title" json:"title"  validate:"required" default:"Location API"`

	// Shorted title / abbreviation describing the API.
	ServiceIdentifier string `yaml:"serviceIdentifier"  json:"serviceIdentifier" validate:"required" default:"Location API"`

	// Human friendly description of the API and dataset.
	Abstract string `yaml:"abstract" json:"abstract" validate:"required" default:"Location search & geocoding API"`

	// Licensing term that apply to this API and dataset
	License License `yaml:"license" json:"license" validate:"required"`

	// The base URL - that's the part until the OGC API landing page - under which this API is served
	BaseURL URL `yaml:"baseUrl" json:"baseUrl" validate:"required"`

	// The languages/translations to offer, valid options are Dutch (nl) and English (en). Dutch is the default.
	AvailableLanguages []Language `yaml:"availableLanguages,omitempty" json:"availableLanguages,omitempty"`

	// Reference to a PNG image to use a thumbnail on the landing page.
	// The full path is constructed by appending Resources + Thumbnail.
	// +optional
	Thumbnail *string `yaml:"thumbnail,omitempty" json:"thumbnail,omitempty"`

	// Moment in time when the dataset was last updated
	LastUpdated *string `yaml:"lastUpdated,omitempty" json:"lastUpdated,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"`

	// Who updated the dataset
	LastUpdatedBy string `yaml:"lastUpdatedBy,omitempty" json:"lastUpdatedBy,omitempty"`

	// Available support channels
	Support *Support `yaml:"support,omitempty" json:"support,omitempty"`

	// Location where resources (e.g. thumbnails) specific to the given dataset are hosted
	Resources *Resources `yaml:"resources,omitempty" json:"resources,omitempty"`

	// Order in which collections should be returned.
	// When not specified collections are returned in alphabetic order.
	CollectionOrder []string `yaml:"collectionOrder,omitempty" json:"collectionOrder,omitempty"`

	// Collections offered through this API
	Collections GeoSpatialCollections `yaml:"collections,omitempty" json:"collections,omitempty" validate:"required,dive"`
}

func NewConfig

func NewConfig(configFile string) (*Config, error)

NewConfig read YAML config file, required to start Gomagpie

func (*Config) AllCollections

func (c *Config) AllCollections() GeoSpatialCollections

AllCollections get all collections - with for example features, tiles, 3d tiles - offered through this OGC API. Results are returned in alphabetic or literal order.

func (*Config) CookieMaxAge

func (c *Config) CookieMaxAge() int

func (*Config) HasCollections

func (c *Config) HasCollections() bool

HasCollections does this API offer collections with for example features, tiles, 3d tiles, etc

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML hooks into unmarshalling to set defaults and validate config

type Extent

type Extent struct {
	// Projection (SRS/CRS) to be used. When none is provided WGS84 (http://www.opengis.net/def/crs/OGC/1.3/CRS84) is used.
	Srs string `yaml:"srs,omitempty" json:"srs,omitempty" validate:"omitempty,startswith=EPSG:"`

	// Geospatial extent
	Bbox []string `yaml:"bbox" json:"bbox"`

	// Temporal extent
	Interval []string `yaml:"interval,omitempty" json:"interval,omitempty" validate:"omitempty,len=2"`
}

type FeatureTable

type FeatureTable struct {
	Name string
	FID  string
	Geom string
}

type GeoSpatialCollection

type GeoSpatialCollection struct {
	// Unique ID of the collection
	ID string `yaml:"id" json:"id" validate:"required"`

	// Metadata describing the collection contents
	Metadata *GeoSpatialCollectionMetadata `yaml:"metadata,omitempty" json:"metadata,omitempty"`

	// Links pertaining to this collection (e.g., downloads, documentation)
	Links *CollectionLinks `yaml:"links,omitempty" json:"links,omitempty"`

	// Search config related to location search/suggest
	Search *Search `yaml:"search,omitempty" json:"search,omitempty"`
}

func CollectionByID added in v0.0.2

func CollectionByID(cfg *Config, id string) *GeoSpatialCollection

type GeoSpatialCollectionMetadata

type GeoSpatialCollectionMetadata struct {
	// Human friendly title of this collection. When no title is specified the collection ID is used.
	Title *string `yaml:"title,omitempty" json:"title,omitempty"`

	// Describes the content of this collection
	Description *string `yaml:"description" json:"description" validate:"required"`

	// Reference to a PNG image to use a thumbnail on the collections.
	// The full path is constructed by appending Resources + Thumbnail.
	// +optional
	Thumbnail *string `yaml:"thumbnail,omitempty" json:"thumbnail,omitempty"`

	// Keywords to make this collection beter discoverable
	Keywords []string `yaml:"keywords,omitempty" json:"keywords,omitempty"`

	// Moment in time when the collection was last updated
	LastUpdated *string `yaml:"lastUpdated,omitempty" json:"lastUpdated,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"`

	// Who updated this collection
	LastUpdatedBy string `yaml:"lastUpdatedBy,omitempty" json:"lastUpdatedBy,omitempty"`

	// Extent of the collection, both geospatial and/or temporal
	Extent *Extent `yaml:"extent,omitempty" json:"extent,omitempty"`

	// The CRS identifier which the features are originally stored, meaning no CRS transformations are applied when features are retrieved in this CRS.
	// WGS84 is the default storage CRS.
	StorageCrs *string `` /* 163-byte string literal not displayed */
}

type GeoSpatialCollections

type GeoSpatialCollections []GeoSpatialCollection

func (GeoSpatialCollections) ContainsID

func (g GeoSpatialCollections) ContainsID(id string) bool

ContainsID check if given collection - by ID - exists. Don't use in hot path (creates a map on every invocation).

func (GeoSpatialCollections) Unique

Unique lists all unique GeoSpatialCollections (no duplicate IDs). Don't use in hot path (creates a map on every invocation).

type Language

type Language struct {
	language.Tag
}

Language represents a BCP 47 language tag. +kubebuilder:validation:Type=string

func (*Language) DeepCopy

func (l *Language) DeepCopy() *Language

DeepCopy copy the receiver, create a new Language.

func (*Language) DeepCopyInto

func (l *Language) DeepCopyInto(out *Language)

DeepCopyInto copy the receiver, write into out. in must be non-nil.

func (Language) MarshalJSON

func (l Language) MarshalJSON() ([]byte, error)

MarshalJSON turn language tag into JSON Value instead of pointer receiver because only that way it can be used for both.

func (*Language) UnmarshalJSON

func (l *Language) UnmarshalJSON(b []byte) error

UnmarshalJSON turn JSON into Language

type License

type License struct {
	// Name of the license, e.g. MIT, CC0, etc
	Name string `yaml:"name" json:"name" validate:"required" default:"CC0"`

	// URL to license text on the web
	URL URL `yaml:"url" json:"url" validate:"required" default:"https://creativecommons.org/publicdomain/zero/1.0/deed"`
}

type RelatedOGCAPIFeaturesCollection

type RelatedOGCAPIFeaturesCollection struct {
	// Base URL/Href to the OGC Features API
	APIBaseURL URL `yaml:"api" json:"api" validate:"required"`

	// Geometry type of the features in the related collection.
	// A collections in an OGC Features API has a single geometry type.
	// But a searchable collection has no geometry type distinction and thus
	// could be assembled of multiple OGC Feature API collections (with the same feature type).
	GeometryType string `yaml:"geometryType" json:"geometryType" validate:"required"`

	// Collection ID in the OGC Features API
	CollectionID string `yaml:"collection" json:"collection" validate:"required"`

	// `datetime` query parameter for the OGC Features API. In case it's temporal.
	// E.g.: "{now()-1h}"
	// +optional
	Datetime *string `yaml:"datetime,omitempty" json:"datetime,omitempty"`
}

type Resources

type Resources struct {
	// Location where resources (e.g. thumbnails) specific to the given dataset are hosted. This is optional if Directory is set
	URL *URL `yaml:"url,omitempty" json:"url,omitempty" validate:"required_without=Directory,omitempty"`

	// Location where resources (e.g. thumbnails) specific to the given dataset are hosted. This is optional if URL is set
	Directory *string `yaml:"directory,omitempty" json:"directory,omitempty" validate:"required_without=URL,omitempty,dirpath|filepath"`
}
type Search struct {
	// Fields that make up the display name and/or suggestions. These fields can be used as variables in the DisplayNameTemplate and SuggestTemplates.
	Fields []string `yaml:"fields,omitempty" json:"fields,omitempty" validate:"required"`

	// Template that indicates how a search record is displayed. Uses Go text/template syntax to reference fields.
	DisplayNameTemplate string `yaml:"displayNameTemplate,omitempty" json:"displayNameTemplate,omitempty" validate:"required"`

	// Version of the collection used to link to search results
	Version int `yaml:"version,omitempty" json:"version,omitempty" default:"1"`

	// (Links to) the individual OGC API (feature) collections that are searchable in this collection.
	// +kubebuilder:validation:MinItems=1
	OGCCollections []RelatedOGCAPIFeaturesCollection `yaml:"ogcCollections" json:"ogcCollections" validate:"required,min=1"`

	ETL SearchETL `yaml:"etl" json:"etl" validate:"required"`
}

type SearchETL

type SearchETL struct {
	// One or more optional templates that make up the autosuggestions. Uses Go text/template syntax to reference fields.
	SuggestTemplates []string `yaml:"suggestTemplates,omitempty" json:"suggestTemplates,omitempty"`

	// SQLite WHERE clause to filter features when importing/ETL-ing
	// (Without the WHERE keyword, only the clause)
	// +Optional
	Filter string `yaml:"filter,omitempty" json:"filter,omitempty"`
}

type Support

type Support struct {
	// Name of the support organization
	Name string `yaml:"name" json:"name" validate:"required"`

	// URL to external support webpage
	URL URL `yaml:"url" json:"url" validate:"required"`

	// Email for support questions
	Email string `yaml:"email,omitempty" json:"email,omitempty" validate:"omitempty,email"`
}

type URL

type URL struct {
	// This is a pointer so the wrapper can directly be used in templates, e.g.: {{ .Config.BaseURL }}
	// Otherwise you would need .String() or template.URL(). (Might be a bug.)
	*url.URL
}

URL Custom net.URL compatible with YAML and JSON (un)marshalling and kubebuilder. In addition, it also removes trailing slash if present, so we can easily append a longer path without having to worry about double slashes.

Allow only http/https URLs or environment variables like ${FOOBAR} +kubebuilder:validation:Pattern=`^(https?://.+)|(\$\{.+\}.*)` +kubebuilder:validation:Type=string

func (*URL) DeepCopy

func (u *URL) DeepCopy() *URL

DeepCopy copies the receiver, creates a new URL.

func (*URL) DeepCopyInto

func (u *URL) DeepCopyInto(out *URL)

DeepCopyInto copies the receiver, writes into out.

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON turns URL into JSON. Value instead of pointer receiver because only that way it can be used for both.

func (URL) MarshalYAML

func (u URL) MarshalYAML() (interface{}, error)

MarshalYAML turns URL into YAML. Value instead of pointer receiver because only that way it can be used for both.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(b []byte) error

UnmarshalJSON parses a string to URL and also removes trailing slash if present, so we can easily append a longer path without having to worry about double slashes.

func (*URL) UnmarshalYAML

func (u *URL) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML parses a string to URL and also removes trailing slash if present, so we can easily append a longer path without having to worry about double slashes.

Jump to

Keyboard shortcuts

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