comparison pkg/models/extservices.go @ 5601:1222b777f51f

Made golint finally happy.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 06 Aug 2022 02:09:57 +0200
parents 5f47eeea988d
children
comparison
equal deleted inserted replaced
5600:9967a78e43f4 5601:1222b777f51f
21 21
22 "gemma.intevation.de/gemma/pkg/auth" 22 "gemma.intevation.de/gemma/pkg/auth"
23 "gemma.intevation.de/gemma/pkg/log" 23 "gemma.intevation.de/gemma/pkg/log"
24 ) 24 )
25 25
26 // ExtEntry is an external WFS service.
26 type ExtEntry struct { 27 type ExtEntry struct {
27 Name string `json:"name"` 28 Name string `json:"name"`
28 URL string `json:"url"` 29 URL string `json:"url"`
29 WFS bool `json:"wfs"` 30 WFS bool `json:"wfs"`
30 } 31 }
31 32
33 // ExtServices is a list of the external services.
32 type ExtServices struct { 34 type ExtServices struct {
33 mu sync.Mutex 35 mu sync.Mutex
34 entries []ExtEntry 36 entries []ExtEntry
35 } 37 }
36 38
39 // ExternalServices is the list of external services
40 // the Gemma server manages as proxies.
37 var ExternalServices = &ExtServices{} 41 var ExternalServices = &ExtServices{}
38 42
39 const selectExternalServices = `SELECT local_name, remote_url, is_wfs 43 const selectExternalServices = `SELECT local_name, remote_url, is_wfs
40 FROM sys_admin.external_services ORDER BY local_name` 44 FROM sys_admin.external_services ORDER BY local_name`
41 45
46 // Find looks for a specific configures external service.
42 func (es *ExtServices) Find(name string) (string, bool) { 47 func (es *ExtServices) Find(name string) (string, bool) {
43 es.mu.Lock() 48 es.mu.Lock()
44 defer es.mu.Unlock() 49 defer es.mu.Unlock()
45 50
46 if es.entries == nil { 51 if es.entries == nil {
82 } 87 }
83 return rows.Err() 88 return rows.Err()
84 }) 89 })
85 } 90 }
86 91
92 // Invalidate invalidate the list of external services.
87 func (es *ExtServices) Invalidate() { 93 func (es *ExtServices) Invalidate() {
88 es.mu.Lock() 94 es.mu.Lock()
89 es.entries = nil 95 es.entries = nil
90 es.mu.Unlock() 96 es.mu.Unlock()
91 } 97 }
92 98
93 func ExternalAll(ExtEntry) bool { return true } 99 // ExternalAll passes all external entries as filter.
100 func ExternalAll(ExtEntry) bool { return true }
101
102 // ExternalWMS passes only external entries which are not WFSs.
94 func ExternalWMS(entry ExtEntry) bool { return !entry.WFS } 103 func ExternalWMS(entry ExtEntry) bool { return !entry.WFS }
104
105 // ExternalWFS passes only external enteries which are WFS.
95 func ExternalWFS(entry ExtEntry) bool { return entry.WFS } 106 func ExternalWFS(entry ExtEntry) bool { return entry.WFS }
96 107
108 // Filter returns a list of external services which met
109 // the condition of the given accept filter.
97 func (es *ExtServices) Filter(accept func(ExtEntry) bool) []ExtEntry { 110 func (es *ExtServices) Filter(accept func(ExtEntry) bool) []ExtEntry {
98 es.mu.Lock() 111 es.mu.Lock()
99 defer es.mu.Unlock() 112 defer es.mu.Unlock()
100 if es.entries == nil { 113 if es.entries == nil {
101 if err := es.load(); err != nil { 114 if err := es.load(); err != nil {