annotate pkg/models/common.go @ 4611:b5aa1eb83bb0 geoserver_sql_views

Add possibility to configure SRS for GeoServer SQL view Automatic detection of spatial reference system for SQL views in GeoServer does not always find the correct SRS.
author Tom Gottfried <tom@intevation.de>
date Fri, 06 Sep 2019 11:58:03 +0200
parents 8080007d3c06
children 4847ac70103a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1017
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
2 // without warranty, see README.md and license for details.
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
3 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
6 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
7 // Copyright (C) 2018 by via donau
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
9 // Software engineering by Intevation GmbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
10 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
11 // Author(s):
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 645
diff changeset
13
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 package models
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
16 import (
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
17 "database/sql/driver"
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
18 "encoding/json"
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
19 "errors"
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
20 "fmt"
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
21 "strings"
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
22 "time"
2059
ae0021feaac8 Imports: Made stretch import marshable (even if it is not needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1979
diff changeset
23
ae0021feaac8 Imports: Made stretch import marshable (even if it is not needed).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1979
diff changeset
24 "gemma.intevation.de/gemma/pkg/common"
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
25 )
643
756f3fc62da6 Cross sections: Using the database in the web service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
645
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
27 var (
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
28 errNoString = errors.New("Not a string")
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
29 errNoByteSlice = errors.New("Not a byte slice")
794592cad75a Cross sections: Fixed SQL, endian, WKB and JSON encoding errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 643
diff changeset
30 )
1373
84e78d2e2d95 Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
31
84e78d2e2d95 Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
32 // WGS84 is the EPSG of the World Geodetic System 1984.
84e78d2e2d95 Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
33 const WGS84 = 4326
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
34
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
35 type (
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
36 Date struct{ time.Time }
2150
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
37 Time struct{ time.Time }
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
38
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
39 // Country is a valid country 2 letter code.
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
40 Country string
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
41 // UniqueCountries is a list of unique countries.
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
42 UniqueCountries []Country
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
43 )
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
44
2150
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
45 func (d Date) MarshalJSON() ([]byte, error) {
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
46 return json.Marshal(d.Format(common.DateFormat))
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
47 }
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
48
2150
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
49 func (d *Date) UnmarshalJSON(data []byte) error {
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
50 var s string
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
51 if err := json.Unmarshal(data, &s); err != nil {
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
52 return err
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
53 }
2150
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
54 d2, err := time.Parse(common.DateFormat, s)
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
55 if err == nil {
2150
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
56 *d = Date{d2}
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
57 }
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
58 return err
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
59 }
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
60
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
61 func (t Time) MarshalJSON() ([]byte, error) {
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
62 return json.Marshal(t.Format(common.TimeFormat))
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
63 }
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
64
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
65 func (t *Time) UnmarshalJSON(data []byte) error {
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
66 var s string
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
67 if err := json.Unmarshal(data, &s); err != nil {
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
68 return err
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
69 }
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
70 t2, err := time.Parse(common.TimeFormat, s)
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
71 if err == nil {
2c67c51d57ad Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2059
diff changeset
72 *t = Time{t2}
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
73 }
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
74 return err
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1373
diff changeset
75 }
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
76
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
77 var (
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
78 validCountries = []string{
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
79 "AT", "BG", "DE", "HU", "HR",
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
80 "MD", "RO", "RS", "SK", "UA",
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
81 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
82 )
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
83
4332
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
84 // Valid checks if the given country is a known one.
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
85 func (c Country) Valid() bool {
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
86 for _, v := range validCountries {
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
87 if string(c) == v {
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
88 return true
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
89 }
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
90 }
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
91 return false
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
92 }
8080007d3c06 shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2231
diff changeset
93
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
94 // UnmarshalJSON ensures that the given string forms a valid
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
95 // two letter country code.
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
96 func (c *Country) UnmarshalJSON(data []byte) error {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
97 var s string
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
98 if err := json.Unmarshal(data, &s); err != nil {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
99 return err
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
100 }
1979
0bc0312105e4 Improved the error message a bit if an invalid country name is passed via JSON api.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1901
diff changeset
101 u := strings.ToUpper(s)
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
102 for _, v := range validCountries {
1979
0bc0312105e4 Improved the error message a bit if an invalid country name is passed via JSON api.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1901
diff changeset
103 if v == u {
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
104 *c = Country(v)
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
105 return nil
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
106 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
107 }
1979
0bc0312105e4 Improved the error message a bit if an invalid country name is passed via JSON api.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1901
diff changeset
108 return fmt.Errorf("'%s' is not a valid country", s)
1901
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
109 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
110
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
111 // Value implements the driver.Valuer interface.
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
112 func (c Country) Value() (driver.Value, error) {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
113 return string(c), nil
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
114 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
115
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
116 // Scan implements the sql.Scanner interfaces.
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
117 func (c *Country) Scan(src interface{}) (err error) {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
118 if s, ok := src.(string); ok {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
119 *c = Country(s)
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
120 } else {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
121 err = errNoString
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
122 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
123 return
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
124 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
125
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
126 func (uc *UniqueCountries) UnmarshalJSON(data []byte) error {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
127 var countries []Country
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
128 if err := json.Unmarshal(data, &countries); err != nil {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
129 return err
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
130 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
131 unique := map[Country]struct{}{}
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
132 for _, c := range countries {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
133 if _, found := unique[c]; found {
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
134 return fmt.Errorf("country '%s' is not unique", string(c))
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
135 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
136 unique[c] = struct{}{}
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
137 }
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
138 *uc = countries
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
139 return nil
71b722809b2b Stretch import: Added stub.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
140 }
2231
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
141
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
142 func (uc UniqueCountries) String() string {
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
143 var b strings.Builder
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
144 for i, c := range uc {
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
145 if i > 0 {
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
146 b.WriteString(", ")
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
147 }
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
148 b.WriteString(string(c))
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
149 }
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
150 return b.String()
97bba8b51b9c Stretch import: Be more verbose about range before inserting data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2150
diff changeset
151 }