Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
init function godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterVisscher committed Jun 26, 2021
1 parent 4fa956e commit 9d5b98d
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A a GeoJSON implementation with a Geopackage as a data provider.

The specification is a preliminary one, with `go generate` the routing based on api spec, provider interfaces en types structs and convenient parameter extractions are generated to stay easily up to date.

* FeatureCollectionGeoJSON is overridden in the GeoPackage provider to use the [GeoJSON](https://github.com/go-spatial/geom/tree/master/encoding/geojson) equivalent for decoding blobs
* FeatureCollection is overridden in the GeoPackage provider to use the [GeoJSON](https://github.com/go-spatial/geom/tree/master/encoding/geojson) equivalent for decoding blobs
* <https://github.com/opengeospatial/ogcapi-features/blob/master/core/openapi/ogcapi-features-1.yaml>

## Build
Expand Down
7 changes: 7 additions & 0 deletions core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

// GetApiProvider is returned by the NewGetApiProvider
// containing the data and contenttype for the response
type GetApiProvider struct {
data *openapi3.T
contenttype string
}

// NewGetApiProvider handles the request and return the GetApiProvider
func NewGetApiProvider(api *openapi3.T) func(r *http.Request) (codegen.Provider, error) {

return func(r *http.Request) (codegen.Provider, error) {
Expand All @@ -29,18 +32,22 @@ func NewGetApiProvider(api *openapi3.T) func(r *http.Request) (codegen.Provider,
}
}

// Provide provides the data
func (gap *GetApiProvider) Provide() (interface{}, error) {
return gap.data, nil
}

// ContentType returns the ContentType
func (gap *GetApiProvider) ContentType() string {
return gap.contenttype
}

// String returns the provider name
func (gap *GetApiProvider) String() string {
return "api"
}

// SrsId returns the srsid
func (gap *GetApiProvider) SrsId() string {
return "n.a"
}
7 changes: 7 additions & 0 deletions core/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"oaf-server/codegen"
)

// DescribeCollectionProvider is returned by the NewDescribeCollectionProvider
// containing the data and contenttype for the response
type DescribeCollectionProvider struct {
data codegen.Collection
contenttype string
}

// NewDescribeCollectionProvider handles the request and return the DescribeCollectionProvider
func NewDescribeCollectionProvider(config Config) func(r *http.Request) (codegen.Provider, error) {

return func(r *http.Request) (codegen.Provider, error) {
Expand Down Expand Up @@ -66,18 +69,22 @@ func NewDescribeCollectionProvider(config Config) func(r *http.Request) (codegen

}

// Provide returns the srsid
func (dcp *DescribeCollectionProvider) Provide() (interface{}, error) {
return dcp.data, nil
}

// ContentType returns the srsid
func (dcp *DescribeCollectionProvider) ContentType() string {
return dcp.contenttype
}

// SrsStringId returns the provider name
func (dcp *DescribeCollectionProvider) String() string {
return "collection"
}

// SrsId returns the srsid
func (dcp *DescribeCollectionProvider) SrsId() string {
return "n.a."
}
7 changes: 7 additions & 0 deletions core/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"oaf-server/codegen"
)

// GetCollectionsProvider is returned by the NewGetCollectionsProvider
// containing the data and contenttype for the response
type GetCollectionsProvider struct {
data codegen.Collections
contenttype string
}

// NewGetCollectionsProvider handles the request and return the GetCollectionsProvider
func NewGetCollectionsProvider(config Config) func(r *http.Request) (codegen.Provider, error) {

return func(r *http.Request) (codegen.Provider, error) {
Expand Down Expand Up @@ -72,18 +75,22 @@ func NewGetCollectionsProvider(config Config) func(r *http.Request) (codegen.Pro
}
}

// Provide provides the data
func (gcp *GetCollectionsProvider) Provide() (interface{}, error) {
return gcp.data, nil
}

// ContentType returns the ContentType
func (gcp *GetCollectionsProvider) ContentType() string {
return gcp.contenttype
}

// String returns the provider name
func (gcp *GetCollectionsProvider) String() string {
return "collections"
}

// SrsId returns the srsid
func (gcp *GetCollectionsProvider) SrsId() string {
return "n.a."
}
13 changes: 13 additions & 0 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/yaml.v3"
)

// Config wrappes all the available configuration
type Config struct {
ApplicationId string `yaml:"applicationid,omitempty"`
UserVersion string `yaml:"userversion,omitempty"`
Expand All @@ -20,6 +21,7 @@ type Config struct {
Service Service `yaml:"service" json:"service"`
}

// ContactPoint needed for the ld+json
type ContactPoint struct {
Type string `yaml:"@type" json:"@type,omitempty"`
Email string `yaml:"email" json:"email,omitempty"`
Expand All @@ -28,6 +30,8 @@ type ContactPoint struct {
ContactType string `yaml:"contactType" json:"contactType,omitempty"`
Description string `yaml:"description" json:"description,omitempty"`
}

// Address needed for the ld+json
type Address struct {
Type string `yaml:"@type" json:"@type,omitempty"`
StreetAddress string `yaml:"streetAddress" json:"streetAddress,omitempty"`
Expand All @@ -37,6 +41,7 @@ type Address struct {
AddressCountry string `yaml:"addressCountry" json:"addressCountry,omitempty"`
}

// Provider needed for the ld+json
type Provider struct {
Type string `yaml:"@type" json:"@type"`
Name string `yaml:"name" json:"name"`
Expand All @@ -45,6 +50,7 @@ type Provider struct {
ContactPoint *ContactPoint `yaml:"contactPoint" json:"contactPoint,omitempty"` // pointer, omitting when empty
}

// Service contains the necessary information for building the right ld+json objects
type Service struct {
Context string `yaml:"@context" json:"@context"`
Type string `yaml:"@type" json:"@type"`
Expand All @@ -58,6 +64,7 @@ type Service struct {
Provider Provider `yaml:"provider" json:"provider"`
}

// Datasource wrappes the datasources, collections, dataset boundingbox and SRID
type Datasource struct {
Geopackage *Geopackage `yaml:"gpkg"`
PostGIS *PostGIS `yaml:"postgis"`
Expand All @@ -66,15 +73,18 @@ type Datasource struct {
Srid int `yaml:"srid"`
}

// Geopackage contains the Geopackage file locations and a alternative Fid column
type Geopackage struct {
File string `yaml:"file"`
Fid string `yaml:"fid"`
}

// PostGIS contains the PostGIS connection string
type PostGIS struct {
Connection string `yaml:"connection"`
}

// Collection contains all the needed information for a collections
type Collection struct {
Schemaname string `yaml:"schemaname"`
Tablename string `yaml:"tablename"`
Expand All @@ -93,13 +103,15 @@ type Collection struct {
Links []codegen.Link `yaml:"links"`
}

// Columns stores the Fid, Offset, BoundingBox and Geometry columns from the datasources
type Columns struct {
Fid string `yaml:"fid"`
Offset string `yaml:"offset"`
BBox string `yaml:"bbox"`
Geometry string `yaml:"geometry"`
}

// NewService initializes a Service
func NewService() Service {
address := Address{
Type: "PostalAddress",
Expand All @@ -120,6 +132,7 @@ func NewService() Service {
return service
}

// ReadConfig reads the from the given path the configuration
func (c *Config) ReadConfig(path string) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions core/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const (
gjson = "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"
)

// GetConformanceDeclarationProvider is returned by the NewGetConformanceDeclarationProvider
// containing the data and contenttype for the response
type GetConformanceDeclarationProvider struct {
data map[string][]string
contenttype string
}

// NewGetConformanceDeclarationProvider handles the request and return the GetConformanceDeclarationProvider
func NewGetConformanceDeclarationProvider(api *openapi3.T) func(r *http.Request) (codegen.Provider, error) {
return func(r *http.Request) (codegen.Provider, error) {
p := &GetConformanceDeclarationProvider{}
Expand Down Expand Up @@ -52,18 +55,22 @@ func NewGetConformanceDeclarationProvider(api *openapi3.T) func(r *http.Request)

}

// Provide provides the data
func (gcdp *GetConformanceDeclarationProvider) Provide() (interface{}, error) {
return gcdp.data, nil
}

// ContentType returns the ContentType
func (gcdp *GetConformanceDeclarationProvider) ContentType() string {
return gcdp.contenttype
}

// String returns the provider name
func (gcdp *GetConformanceDeclarationProvider) String() string {
return "conformance"
}

// SrsId returns the srsid
func (gcdp *GetConformanceDeclarationProvider) SrsId() string {
return "n.a."
}
2 changes: 1 addition & 1 deletion core/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/go-spatial/geom/encoding/geojson"
)

type FeatureCollectionGeoJSON struct {
type FeatureCollection struct {
NumberReturned int64 `json:"numberReturned,omitempty"`
TimeStamp string `json:"timeStamp,omitempty"`
Type string `json:"type"`
Expand Down
7 changes: 7 additions & 0 deletions core/landingpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"oaf-server/codegen"
)

// GetLandingPageProvider is returned by the NewGetLandingPageProvider
// containing the data and contenttype for the response
type GetLandingPageProvider struct {
Links []codegen.Link `json:"links,omitempty"`
contenttype string
Expand All @@ -14,6 +16,7 @@ type GetLandingPageProvider struct {
*Service
}

// NewGetLandingPageProvider handles the request and return the GetLandingPageProvider
func NewGetLandingPageProvider(serviceConfig Service) func(r *http.Request) (codegen.Provider, error) {

return func(r *http.Request) (codegen.Provider, error) {
Expand Down Expand Up @@ -48,18 +51,22 @@ func NewGetLandingPageProvider(serviceConfig Service) func(r *http.Request) (cod
}
}

// Provide provides the data
func (glp *GetLandingPageProvider) Provide() (interface{}, error) {
return glp, nil
}

// ContentType returns the ContentType
func (glp *GetLandingPageProvider) ContentType() string {
return glp.contenttype
}

// String returns the provider name
func (glp *GetLandingPageProvider) String() string {
return "landingpage"
}

// SrsId returns the srsid
func (glp *GetLandingPageProvider) SrsId() string {
return "n.a"
}
17 changes: 11 additions & 6 deletions geopackage/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ import (
"oaf-server/core"
)

func (gp *GeoPackageProvider) NewDescribeCollectionProvider(r *http.Request) (codegen.Provider, error) {
return core.NewDescribeCollectionProvider(gp.Config)(r)
// NewGetLandingPageProvider passes the request to the Core NewGetLandingPageProvider with the GeoPackage Config
func (gp *GeoPackageProvider) NewGetLandingPageProvider(r *http.Request) (codegen.Provider, error) {
return core.NewGetLandingPageProvider(gp.Config.Service)(r)
}

// NewGetApiProvider passes the request to the Core NewGetApiProvider with the GeoPackage Config
func (gp *GeoPackageProvider) NewGetApiProvider(r *http.Request) (codegen.Provider, error) {
return core.NewGetApiProvider(gp.ApiProcessed)(r)
}

// NewGetConformanceDeclarationProvider passes the request to the Core NewGetConformanceDeclarationProvider with the GeoPackage Config
func (gp *GeoPackageProvider) NewGetConformanceDeclarationProvider(r *http.Request) (codegen.Provider, error) {
return core.NewGetConformanceDeclarationProvider(gp.ApiProcessed)(r)
}

func (gp *GeoPackageProvider) NewGetLandingPageProvider(r *http.Request) (codegen.Provider, error) {
return core.NewGetLandingPageProvider(gp.Config.Service)(r)
}

// NewGetCollectionsProvider passes the request to the Core NewGetCollectionsProvider with the GeoPackage Config
func (gp *GeoPackageProvider) NewGetCollectionsProvider(r *http.Request) (codegen.Provider, error) {
return core.NewGetCollectionsProvider(gp.Config)(r)
}

// NewDescribeCollectionProvider passes the request to the Core NewDescribeCollectionProvider with the GeoPackage Config
func (gp *GeoPackageProvider) NewDescribeCollectionProvider(r *http.Request) (codegen.Provider, error) {
return core.NewDescribeCollectionProvider(gp.Config)(r)
}
7 changes: 7 additions & 0 deletions geopackage/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"oaf-server/core"
)

// GetFeatureProvider is returned by the NewGetFeatureProvider
// containing the data, srsid and contenttype for the response
type GetFeatureProvider struct {
data *core.Feature
srsid string
contenttype string
}

// NewGetFeatureProvider handles the request and return the GetFeatureProvider
func (gp *GeoPackageProvider) NewGetFeatureProvider(r *http.Request) (codegen.Provider, error) {

collectionId, featureId, _ := codegen.ParametersForGetFeature(r)
Expand Down Expand Up @@ -60,18 +63,22 @@ func (gp *GeoPackageProvider) NewGetFeatureProvider(r *http.Request) (codegen.Pr
return p, nil
}

// Provide provides the data
func (gfp *GetFeatureProvider) Provide() (interface{}, error) {
return gfp.data, nil
}

// ContentType returns the ContentType
func (gfp *GetFeatureProvider) ContentType() string {
return gfp.contenttype
}

// String returns the provider name
func (gfp *GetFeatureProvider) String() string {
return "feature"
}

// SrsId returns the srsid
func (gfp *GetFeatureProvider) SrsId() string {
return gfp.srsid
}
Loading

0 comments on commit 9d5b98d

Please sign in to comment.