Mercurial > gemma
comparison pkg/geoserver/boot.go @ 5712:6270951dda28 revive-cleanup
/interface{}/any/
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 20 Feb 2024 22:37:51 +0100 |
parents | 5f47eeea988d |
children |
comparison
equal
deleted
inserted
replaced
5711:2dd155cc95ec | 5712:6270951dda28 |
---|---|
48 return func(req *http.Request) { | 48 return func(req *http.Request) { |
49 req.SetBasicAuth(user, password) | 49 req.SetBasicAuth(user, password) |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 func toStream(x interface{}) io.Reader { | 53 func toStream(x any) io.Reader { |
54 var buf bytes.Buffer | 54 var buf bytes.Buffer |
55 | 55 |
56 if err := json.NewEncoder(&buf).Encode(x); err != nil { | 56 if err := json.NewEncoder(&buf).Encode(x); err != nil { |
57 // Should not happen | 57 // Should not happen |
58 log.Warnf("bad JSON: %v\n", err) | 58 log.Warnf("bad JSON: %v\n", err) |
60 return bytes.NewReader(buf.Bytes()) | 60 return bytes.NewReader(buf.Bytes()) |
61 } | 61 } |
62 | 62 |
63 // XXX: Creating SQL views with JSON via GeoServer REST-API fails | 63 // XXX: Creating SQL views with JSON via GeoServer REST-API fails |
64 // Begin code for handling with XML instead | 64 // Begin code for handling with XML instead |
65 func toXMLStream(x interface{}) io.Reader { | 65 func toXMLStream(x any) io.Reader { |
66 buf := bytes.NewBufferString(xml.Header) | 66 buf := bytes.NewBufferString(xml.Header) |
67 if err := xml.NewEncoder(buf).Encode(x); err != nil { | 67 if err := xml.NewEncoder(buf).Encode(x); err != nil { |
68 // Should not happen | 68 // Should not happen |
69 log.Warnf("bad XML: %v\n", err) | 69 log.Warnf("bad XML: %v\n", err) |
70 } | 70 } |
164 | 164 |
165 // Create datastore. | 165 // Create datastore. |
166 log.Infoln("creating datastore " + datastoreName) | 166 log.Infoln("creating datastore " + datastoreName) |
167 | 167 |
168 type entry struct { | 168 type entry struct { |
169 Key interface{} `json:"@key"` | 169 Key any `json:"@key"` |
170 Value interface{} `json:"$"` | 170 Value any `json:"$"` |
171 } | 171 } |
172 | 172 |
173 // Create datastore. | 173 // Create datastore. |
174 ds := map[string]interface{}{ | 174 ds := map[string]any{ |
175 "dataStore": map[string]interface{}{ | 175 "dataStore": map[string]any{ |
176 "name": datastoreName, | 176 "name": datastoreName, |
177 "connectionParameters": map[string]interface{}{ | 177 "connectionParameters": map[string]any{ |
178 "entry": []entry{ | 178 "entry": []entry{ |
179 {"host", config.DBHost()}, | 179 {"host", config.DBHost()}, |
180 {"port", config.DBPort()}, | 180 {"port", config.DBPort()}, |
181 {"database", config.DBName()}, | 181 {"database", config.DBName()}, |
182 {"schema", models.DatabaseScheme}, | 182 {"schema", models.DatabaseScheme}, |
299 // Create featuretype. | 299 // Create featuretype. |
300 log.Infof("creating featuretype %s.\n", table) | 300 log.Infof("creating featuretype %s.\n", table) |
301 | 301 |
302 var req *http.Request | 302 var req *http.Request |
303 | 303 |
304 ft := map[string]interface{}{ | 304 ft := map[string]any{ |
305 "name": table, | 305 "name": table, |
306 "nativeName": table, | 306 "nativeName": table, |
307 "title": table, | 307 "title": table, |
308 } | 308 } |
309 if srs := tables[i].SRS; srs != nil { | 309 if srs := tables[i].SRS; srs != nil { |
310 ft["srs"] = *srs | 310 ft["srs"] = *srs |
311 // A bit of a hack! | 311 // A bit of a hack! |
312 if *srs == "EPSG:4326" { | 312 if *srs == "EPSG:4326" { |
313 box := map[string]interface{}{ | 313 box := map[string]any{ |
314 "minx": -180, | 314 "minx": -180, |
315 "maxx": +180, | 315 "maxx": +180, |
316 "miny": -90, | 316 "miny": -90, |
317 "maxy": +90, | 317 "maxy": +90, |
318 "crs": "EPSG:4326", | 318 "crs": "EPSG:4326", |
320 ft["nativeBoundingBox"] = box | 320 ft["nativeBoundingBox"] = box |
321 ft["latLonBoundingBox"] = box | 321 ft["latLonBoundingBox"] = box |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 var entries []map[string]interface{} | 325 var entries []map[string]any |
326 | 326 |
327 if models.IntSQLView(tables[i]) { | 327 if models.IntSQLView(tables[i]) { |
328 vt := map[string]interface{}{ | 328 vt := map[string]any{ |
329 "name": table, | 329 "name": table, |
330 "sql": *tables[i].SQL, | 330 "sql": *tables[i].SQL, |
331 } | 331 } |
332 if kc := tables[i].KeyColumn; kc != nil { | 332 if kc := tables[i].KeyColumn; kc != nil { |
333 vt["keyColumn"] = *kc | 333 vt["keyColumn"] = *kc |
334 } | 334 } |
335 entry := map[string]interface{}{ | 335 entry := map[string]any{ |
336 "@key": "JDBC_VIRTUAL_TABLE", | 336 "@key": "JDBC_VIRTUAL_TABLE", |
337 "virtualTable": vt, | 337 "virtualTable": vt, |
338 } | 338 } |
339 entries = append(entries, entry) | 339 entries = append(entries, entry) |
340 } | 340 } |
341 | 341 |
342 if attr := tables[i].WMSTAttribute; attr != nil { | 342 if attr := tables[i].WMSTAttribute; attr != nil { |
343 di := map[string]interface{}{ | 343 di := map[string]any{ |
344 "enabled": true, | 344 "enabled": true, |
345 "attribute": *attr, | 345 "attribute": *attr, |
346 "presentation": "CONTINUOUS_INTERVAL", | 346 "presentation": "CONTINUOUS_INTERVAL", |
347 "units": "ISO8601", | 347 "units": "ISO8601", |
348 "nearestMatchEnabled": false, | 348 "nearestMatchEnabled": false, |
352 }, | 352 }, |
353 } | 353 } |
354 if endAttr := tables[i].WMSTEndAttribute; endAttr != nil { | 354 if endAttr := tables[i].WMSTEndAttribute; endAttr != nil { |
355 di["endAttribute"] = *endAttr | 355 di["endAttribute"] = *endAttr |
356 } | 356 } |
357 entry := map[string]interface{}{ | 357 entry := map[string]any{ |
358 "@key": "time", | 358 "@key": "time", |
359 "dimensionInfo": di, | 359 "dimensionInfo": di, |
360 } | 360 } |
361 entries = append(entries, entry) | 361 entries = append(entries, entry) |
362 } | 362 } |
363 | 363 |
364 if len(entries) > 0 { | 364 if len(entries) > 0 { |
365 ft["metadata"] = map[string]interface{}{ | 365 ft["metadata"] = map[string]any{ |
366 "entry": entries, | 366 "entry": entries, |
367 } | 367 } |
368 } | 368 } |
369 | 369 |
370 doc := map[string]interface{}{ | 370 doc := map[string]any{ |
371 "featureType": ft, | 371 "featureType": ft, |
372 } | 372 } |
373 | 373 |
374 req, err = http.NewRequest( | 374 req, err = http.NewRequest( |
375 http.MethodPost, | 375 http.MethodPost, |