diff --git a/README.md b/README.md index 20b4ee1..30dcda3 100644 --- a/README.md +++ b/README.md @@ -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 * ## Build diff --git a/core/api.go b/core/api.go index 86f9334..d932007 100644 --- a/core/api.go +++ b/core/api.go @@ -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) { @@ -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" } diff --git a/core/collection.go b/core/collection.go index 9860a57..7294b2f 100644 --- a/core/collection.go +++ b/core/collection.go @@ -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) { @@ -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." } diff --git a/core/collections.go b/core/collections.go index 119d8a6..9136afa 100644 --- a/core/collections.go +++ b/core/collections.go @@ -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) { @@ -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." } diff --git a/core/config.go b/core/config.go index b95ac27..896fd34 100644 --- a/core/config.go +++ b/core/config.go @@ -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"` @@ -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"` @@ -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"` @@ -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"` @@ -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"` @@ -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"` @@ -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"` @@ -93,6 +103,7 @@ 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"` @@ -100,6 +111,7 @@ type Columns struct { Geometry string `yaml:"geometry"` } +// NewService initializes a Service func NewService() Service { address := Address{ Type: "PostalAddress", @@ -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 { diff --git a/core/conformance.go b/core/conformance.go index 952ac88..7e51eb5 100644 --- a/core/conformance.go +++ b/core/conformance.go @@ -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{} @@ -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." } diff --git a/core/geojson.go b/core/geojson.go index f094765..a044c2f 100644 --- a/core/geojson.go +++ b/core/geojson.go @@ -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"` diff --git a/core/landingpage.go b/core/landingpage.go index ab5be7e..225760b 100644 --- a/core/landingpage.go +++ b/core/landingpage.go @@ -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 @@ -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) { @@ -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" } diff --git a/geopackage/core.go b/geopackage/core.go index 2532da4..c753726 100644 --- a/geopackage/core.go +++ b/geopackage/core.go @@ -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) +} diff --git a/geopackage/feature.go b/geopackage/feature.go index a33f6d2..44ec563 100644 --- a/geopackage/feature.go +++ b/geopackage/feature.go @@ -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) @@ -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 } diff --git a/geopackage/features.go b/geopackage/features.go index c50515e..a961a0f 100644 --- a/geopackage/features.go +++ b/geopackage/features.go @@ -8,12 +8,15 @@ import ( "oaf-server/core" ) +// GetFeaturesProvider is returned by the NewGetFeaturesProvider +// containing the data, srsid and contenttype for the response type GetFeaturesProvider struct { - data core.FeatureCollectionGeoJSON + data core.FeatureCollection srsid string contenttype string } +// NewGetFeaturesProvider handles the request and return the GetFeaturesProvider func (gp *GeoPackageProvider) NewGetFeaturesProvider(r *http.Request) (codegen.Provider, error) { collectionId, limit, offset, _, bbox, time := codegen.ParametersForGetFeatures(r) @@ -90,18 +93,22 @@ func (gp *GeoPackageProvider) NewGetFeaturesProvider(r *http.Request) (codegen.P return p, nil } +// Provide provides the data func (gfp *GetFeaturesProvider) Provide() (interface{}, error) { return gfp.data, nil } +// ContentType returns the ContentType func (gfp *GetFeaturesProvider) ContentType() string { return gfp.contenttype } +// String returns the provider name func (gfp *GetFeaturesProvider) String() string { return "features" } +// SrsId returns the srsid func (gfp *GetFeaturesProvider) SrsId() string { return gfp.srsid } diff --git a/geopackage/geopackage.go b/geopackage/geopackage.go index 9d665e5..159e97a 100644 --- a/geopackage/geopackage.go +++ b/geopackage/geopackage.go @@ -17,6 +17,8 @@ import ( "github.com/go-spatial/geom/encoding/gpkg" ) +// GeoPackageLayer used for reading the given GeoPackage +// This will later be translated to Collections type GeoPackageLayer struct { TableName string `db:"table_name"` DataType string `db:"data_type"` @@ -35,6 +37,7 @@ type GeoPackageLayer struct { Features []string // first table, second PK, rest features } +// Geopackage configuration type GeoPackage struct { ApplicationId string UserVersion int64 @@ -159,9 +162,10 @@ func (gpkg *GeoPackage) GetCollections(ctx context.Context, db *sqlx.DB) (result return } -func (geopackage GeoPackage) GetFeatures(ctx context.Context, db *sqlx.DB, collection core.Collection, collectionId string, offset uint64, limit uint64, featureId interface{}, bbox [4]float64) (result *core.FeatureCollectionGeoJSON, err error) { +// GetFeatures return the FeatureCollection +func (geopackage GeoPackage) GetFeatures(ctx context.Context, db *sqlx.DB, collection core.Collection, collectionId string, offset uint64, limit uint64, featureId interface{}, bbox [4]float64) (result *core.FeatureCollection, err error) { // Features bit of a hack // layer.Features => tablename, PK, ...FEATURES, assuming create table in sql statement first is PK - result = &core.FeatureCollectionGeoJSON{} + result = &core.FeatureCollection{} if len(bbox) > 4 { err = errors.New("bbox with 6 elements not supported") return @@ -309,6 +313,7 @@ func (geopackage GeoPackage) GetFeatures(ctx context.Context, db *sqlx.DB, colle return } +// GetApplicationID returns a string containing the GeoPackage application_id func (gpkg *GeoPackage) GetApplicationID(ctx context.Context, db *sqlx.DB) (string, error) { if gpkg.ApplicationId != "" { @@ -339,6 +344,7 @@ func (gpkg *GeoPackage) GetApplicationID(ctx context.Context, db *sqlx.DB) (stri } +// GetVersion returns a string containing the GeoPackage version func (gpkg *GeoPackage) GetVersion(ctx context.Context, db *sqlx.DB) (int64, error) { if gpkg.UserVersion != 0 { diff --git a/geopackage/initprovider.go b/geopackage/initprovider.go index d322eee..c85bf49 100644 --- a/geopackage/initprovider.go +++ b/geopackage/initprovider.go @@ -8,6 +8,7 @@ import ( "github.com/imdario/mergo" ) +// GeoPackageProvider type GeoPackageProvider struct { GeoPackage GeoPackage Config core.Config @@ -15,6 +16,8 @@ type GeoPackageProvider struct { ApiProcessed *openapi3.T } +// NewGeopackageWithCommonProvider returns a new GeoPackageProvider set with the +// given config and OAS3 spec func NewGeopackageWithCommonProvider(api *openapi3.T, config core.Config) *GeoPackageProvider { return &GeoPackageProvider{ Api: api, @@ -22,6 +25,8 @@ func NewGeopackageWithCommonProvider(api *openapi3.T, config core.Config) *GeoPa } } +// Init initialize the *GeoPackag +// and processed the OAS3 spec with the available collections func (gp *GeoPackageProvider) Init() (err error) { gp.GeoPackage, err = NewGeoPackage(gp.Config.Datasource.Geopackage.File, gp.Config.Datasource.Geopackage.Fid) diff --git a/postgis/core.go b/postgis/core.go index 69838fb..a803425 100644 --- a/postgis/core.go +++ b/postgis/core.go @@ -6,22 +6,27 @@ import ( "oaf-server/core" ) -func (pp *PostgisProvider) NewDescribeCollectionProvider(r *http.Request) (codegen.Provider, error) { - return core.NewDescribeCollectionProvider(pp.Config)(r) +// NewGetLandingPageProvider passes the request to the Core NewGetLandingPageProvider with the Postgis Config +func (pp *PostgisProvider) NewGetLandingPageProvider(r *http.Request) (codegen.Provider, error) { + return core.NewGetLandingPageProvider(pp.Config.Service)(r) } +// NewGetApiProvider passes the request to the Core NewGetApiProvider with the Postgis Config func (pp *PostgisProvider) NewGetApiProvider(r *http.Request) (codegen.Provider, error) { return core.NewGetApiProvider(pp.ApiProcessed)(r) } +// NewGetConformanceDeclarationProvider passes the request to the Core NewGetConformanceDeclarationProvider with the Postgis Config func (pp *PostgisProvider) NewGetConformanceDeclarationProvider(r *http.Request) (codegen.Provider, error) { return core.NewGetConformanceDeclarationProvider(pp.ApiProcessed)(r) } -func (pp *PostgisProvider) NewGetLandingPageProvider(r *http.Request) (codegen.Provider, error) { - return core.NewGetLandingPageProvider(pp.Config.Service)(r) -} - +// NewGetCollectionsProvider passes the request to the Core NewGetCollectionsProvider with the Postgis Config func (pp *PostgisProvider) NewGetCollectionsProvider(r *http.Request) (codegen.Provider, error) { return core.NewGetCollectionsProvider(pp.Config)(r) } + +// NewDescribeCollectionProvider passes the request to the Core NewDescribeCollectionProvider with the Postgis Config +func (pp *PostgisProvider) NewDescribeCollectionProvider(r *http.Request) (codegen.Provider, error) { + return core.NewDescribeCollectionProvider(pp.Config)(r) +} diff --git a/postgis/feature.go b/postgis/feature.go index ee6b533..0fb83c0 100644 --- a/postgis/feature.go +++ b/postgis/feature.go @@ -8,12 +8,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 (pp *PostgisProvider) NewGetFeatureProvider(r *http.Request) (codegen.Provider, error) { collectionId, featureId, _ := codegen.ParametersForGetFeature(r) @@ -75,18 +78,22 @@ func (pp *PostgisProvider) NewGetFeatureProvider(r *http.Request) (codegen.Provi return p, errors.New("Cannot find collection : " + collectionId) } +// 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 } diff --git a/postgis/features.go b/postgis/features.go index 94ea3c9..bf6fba4 100644 --- a/postgis/features.go +++ b/postgis/features.go @@ -9,12 +9,15 @@ import ( "oaf-server/core" ) +// GetFeaturesProvider is returned by the NewGetFeaturesProvider +// containing the data, srsid and contenttype for the response type GetFeaturesProvider struct { - data core.FeatureCollectionGeoJSON + data core.FeatureCollection srsid string contenttype string } +// NewGetFeaturesProvider handles the request and return the GetFeaturesProvider func (pp *PostgisProvider) NewGetFeaturesProvider(r *http.Request) (codegen.Provider, error) { collectionId, limit, offset, _, bbox, time := codegen.ParametersForGetFeatures(r) @@ -108,18 +111,22 @@ func (pp *PostgisProvider) NewGetFeaturesProvider(r *http.Request) (codegen.Prov return p, nil } +// Provide provides the data func (gfp *GetFeaturesProvider) Provide() (interface{}, error) { return gfp.data, nil } +// ContentType returns the ContentType func (gfp *GetFeaturesProvider) ContentType() string { return gfp.contenttype } +// String returns the provider name func (gfp *GetFeaturesProvider) String() string { return "features" } +// SrsId returns the srsid func (gfp *GetFeaturesProvider) SrsId() string { return gfp.srsid } diff --git a/postgis/initprovider.go b/postgis/initprovider.go index 38251a8..32b91b9 100644 --- a/postgis/initprovider.go +++ b/postgis/initprovider.go @@ -7,6 +7,7 @@ import ( _ "github.com/mattn/go-sqlite3" ) +// PostgisProvider type PostgisProvider struct { PostGis Postgis Config core.Config @@ -14,6 +15,8 @@ type PostgisProvider struct { ApiProcessed *openapi3.T } +// NewPostgisWithCommonProvider returns a new PostgisProvider set with the +// given config and OAS3 spec func NewPostgisWithCommonProvider(api *openapi3.T, config core.Config) *PostgisProvider { p := &PostgisProvider{ Config: config, @@ -22,6 +25,8 @@ func NewPostgisWithCommonProvider(api *openapi3.T, config core.Config) *PostgisP return p } +// Init initialize the PostGIS database +// and processed the OAS3 spec with the available collections func (pg *PostgisProvider) Init() (err error) { pg.PostGis, err = NewPostgis(pg.Config) pg.ApiProcessed = core.CreateProvidesSpecificParameters(pg.Api, &pg.PostGis.Collections) diff --git a/postgis/postgis.go b/postgis/postgis.go index dc1f8f1..e4c6cf3 100644 --- a/postgis/postgis.go +++ b/postgis/postgis.go @@ -14,6 +14,7 @@ import ( _ "github.com/lib/pq" ) +// Postgis configuration type Postgis struct { ApplicationId string UserVersion string @@ -23,6 +24,7 @@ type Postgis struct { Srid int64 } +// NewPostgis returns the Postgis build on the given Config func NewPostgis(config core.Config) (Postgis, error) { postgis := Postgis{} @@ -51,12 +53,14 @@ func NewPostgis(config core.Config) (Postgis, error) { return postgis, nil } +// Close closes the postgis database func (postgis Postgis) Close() error { return postgis.db.Close() } -func (postgis Postgis) GetFeatures(ctx context.Context, db *sqlx.DB, collection core.Collection, whereMap map[string]string, offset uint64, limit uint64, featureId interface{}, bbox [4]float64) (result core.FeatureCollectionGeoJSON, err error) { - result = core.FeatureCollectionGeoJSON{} +// GetFeatures return the FeatureCollection +func (postgis Postgis) GetFeatures(ctx context.Context, db *sqlx.DB, collection core.Collection, whereMap map[string]string, offset uint64, limit uint64, featureId interface{}, bbox [4]float64) (result core.FeatureCollection, err error) { + result = core.FeatureCollection{} if len(bbox) > 4 { err = errors.New("bbox with 6 elements not supported") return @@ -253,6 +257,7 @@ func (postgis Postgis) GetFeatures(ctx context.Context, db *sqlx.DB, collection return } +// GetVersion returns a string containing the PostGIS version func (postgis *Postgis) GetVersion(ctx context.Context, db *sqlx.DB) (string, error) { if postgis.UserVersion != "" { diff --git a/server/server.go b/server/server.go index 284fc85..b7f4380 100644 --- a/server/server.go +++ b/server/server.go @@ -17,6 +17,7 @@ import ( var isTesting = false +// Server type Server struct { ServiceEndpoint string ServiceSpecPath string @@ -27,6 +28,11 @@ type Server struct { Templates *template.Template } +// NewServer returns a initialized Server +// The returned Server contains: +// - openapi3.T +// - templates +// - set Max and Default feature limits func NewServer(serviceEndpoint, serviceSpecPath string, defaultReturnLimit, maxReturnLimit uint64) (*Server, error) { openapi, err := spec.GetOpenAPI(serviceSpecPath) @@ -70,6 +76,7 @@ func NewServer(serviceEndpoint, serviceSpecPath string, defaultReturnLimit, maxR return server, nil } +// SetProviders calls the Init() for the configured Provider func (s *Server) SetProviders(providers codegen.Providers) (*Server, error) { err := providers.Init() @@ -81,6 +88,8 @@ func (s *Server) SetProviders(providers codegen.Providers) (*Server, error) { return s, nil } +// HandleForProvider process the given Provider +// And does post-processing regarding the reponse like setting the Content-Type func (s *Server) HandleForProvider(providerFunc func(r *http.Request) (codegen.Provider, error)) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { diff --git a/spec/specificationloader.go b/spec/specificationloader.go index b174b7d..675e76c 100644 --- a/spec/specificationloader.go +++ b/spec/specificationloader.go @@ -6,6 +6,7 @@ import ( "github.com/getkin/kin-openapi/openapi3" ) +// GetOpenAPI reads a file containing the OAS3 spec and return the openapi3.T struct func GetOpenAPI(serviceSpecPath string) (*openapi3.T, error) { loader := openapi3.NewLoader()