# HG changeset patch # User Sascha L. Teichmann # Date 1535023466 -7200 # Node ID b2dea4e56ff1fe5bb9ab2334a9137f663ef07631 # Parent 39b5deee8810405e676887ed20c7fa4c094d37b8 /api/published (GET) returns a JSON document of the geo-services published by the gemma server. diff -r 39b5deee8810 -r b2dea4e56ff1 pkg/controllers/publish.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/controllers/publish.go Thu Aug 23 13:24:26 2018 +0200 @@ -0,0 +1,21 @@ +package controllers + +import ( + "database/sql" + "net/http" + + "gemma.intevation.de/gemma/pkg/models" +) + +func published(_ interface{}, req *http.Request, _ *sql.DB) (jr JSONResult, err error) { + jr = JSONResult{ + Result: struct { + Internal []models.PubEntry `json:"internal"` + External []models.ExtEntry `json:"external"` + }{ + Internal: models.PublishedServices.Filter(models.PublishedAll), + External: models.ExternalServices.Filter(models.ExternalAll), + }, + } + return +} diff -r 39b5deee8810 -r b2dea4e56ff1 pkg/controllers/routes.go --- a/pkg/controllers/routes.go Thu Aug 23 12:57:15 2018 +0200 +++ b/pkg/controllers/routes.go Thu Aug 23 13:24:26 2018 +0200 @@ -90,6 +90,10 @@ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete) + api.Handle("/published", any(&JSONHandler{ + Handle: published, + })).Methods(http.MethodGet) + // Token handling: Login/Logout. api.HandleFunc("/login", login). Methods(http.MethodGet, http.MethodPost) diff -r 39b5deee8810 -r b2dea4e56ff1 pkg/models/extservices.go --- a/pkg/models/extservices.go Thu Aug 23 12:57:15 2018 +0200 +++ b/pkg/models/extservices.go Thu Aug 23 13:24:26 2018 +0200 @@ -10,9 +10,9 @@ ) type ExtEntry struct { - Name string - URL string - WFS bool + Name string `json:"name"` + URL string `json:"url"` + WFS bool `json:"wfs"` } type ExtServices struct { @@ -74,8 +74,9 @@ es.mu.Unlock() } -func ExternalWMS(entry PubEntry) bool { return !entry.WFS } -func ExternalWFS(entry PubEntry) bool { return entry.WFS } +func ExternalAll(ExtEntry) bool { return true } +func ExternalWMS(entry ExtEntry) bool { return !entry.WFS } +func ExternalWFS(entry ExtEntry) bool { return entry.WFS } func (es *ExtServices) Filter(accept func(ExtEntry) bool) []ExtEntry { es.mu.Lock() diff -r 39b5deee8810 -r b2dea4e56ff1 pkg/models/pubservices.go --- a/pkg/models/pubservices.go Thu Aug 23 12:57:15 2018 +0200 +++ b/pkg/models/pubservices.go Thu Aug 23 13:24:26 2018 +0200 @@ -10,10 +10,10 @@ ) type PubEntry struct { - Name string - Style sql.NullString - WMS bool - WFS bool + Name string `json:"name"` + Style sql.NullString `json:"-"` // This should be done separately. + WMS bool `json:"wms"` + WFS bool `json:"wfs"` } type PubServices struct { @@ -91,6 +91,7 @@ ps.mu.Unlock() } +func PublishedAll(PubEntry) bool { return true } func PublishedWMS(entry PubEntry) bool { return entry.WMS } func PublishedWFS(entry PubEntry) bool { return entry.WFS }