changeset 456:a8e217119085

Fixed internal proxy resolution.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 22 Aug 2018 13:14:13 +0200
parents 1c4834aa7776
children 62ffb6c8a42e
files pkg/models/pubservices.go
diffstat 1 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/models/pubservices.go	Wed Aug 22 12:15:38 2018 +0200
+++ b/pkg/models/pubservices.go	Wed Aug 22 13:14:13 2018 +0200
@@ -3,10 +3,10 @@
 import (
 	"database/sql"
 	"log"
-	"sort"
 	"sync"
 
 	"gemma.intevation.de/gemma/pkg/auth"
+	"gemma.intevation.de/gemma/pkg/config"
 )
 
 type PubEntry struct {
@@ -27,23 +27,28 @@
 var PublishedServices = &PubServices{}
 
 func (ps *PubServices) Find(name string) (string, bool) {
-	ps.mu.Lock()
-	defer ps.mu.Unlock()
+	if ps.has(name) {
+		return config.GeoServerURL() + "/" + name, true
+	}
+	return "", false
+}
 
-	if ps.entries == nil {
-		if err := ps.load(); err != nil {
-			log.Printf("error: %v\n", err)
-			return "", false
+func (ps *PubServices) has(service string) bool {
+	var check func(*PubEntry) bool
+	switch service {
+	case "wms":
+		check = func(e *PubEntry) bool { return e.WMS }
+	case "wfs":
+		check = func(e *PubEntry) bool { return e.WFS }
+	default:
+		return false
+	}
+	for i := range ps.entries {
+		if check(&ps.entries[i]) {
+			return true
 		}
 	}
-
-	n := sort.Search(len(ps.entries), func(i int) bool {
-		return ps.entries[i].Name >= name
-	})
-	if n == len(ps.entries) || ps.entries[n].Name != name {
-		return "", false
-	}
-	return name, true
+	return false
 }
 
 func (ps *PubServices) load() error {