Mercurial > gemma
changeset 473:b2dea4e56ff1
/api/published (GET) returns a JSON document of the geo-services published by the gemma server.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 23 Aug 2018 13:24:26 +0200 |
parents | 39b5deee8810 |
children | 11d80120ed3d |
files | pkg/controllers/publish.go pkg/controllers/routes.go pkg/models/extservices.go pkg/models/pubservices.go |
diffstat | 4 files changed, 36 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- /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 +}
--- 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)
--- 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()
--- 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 }