annotate pkg/controllers/common.go @ 3776:6521c962a7b6

Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 02 Jul 2019 16:44:04 +0200
parents 4c254651d80b
children 5f47eeea988d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2019 by via donau
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 package controllers
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "fmt"
3217
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
18 "log"
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
19 "strconv"
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "strings"
3217
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
21
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
22 "github.com/jackc/pgx/pgtype"
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 )
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
3194
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
25 type (
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
26 filterNode interface {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
27 serialize(*strings.Builder, *[]interface{})
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
28 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
29
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
30 filterTerm struct {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
31 format string
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
32 args []interface{}
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
33 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
34
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
35 filterNot struct {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
36 filterNode
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
37 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
38
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
39 filterAnd []filterNode
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
40 filterOr []filterNode
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
41 )
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
42
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
43 func (ft *filterTerm) serialize(stmt *strings.Builder, args *[]interface{}) {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
44 indices := make([]interface{}, len(ft.args))
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
45 for i := range indices {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
46 indices[i] = len(*args) + i + 1
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
47 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
48 fmt.Fprintf(stmt, ft.format, indices...)
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
49 *args = append(*args, (*ft).args...)
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
3194
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
52 func buildFilterTerm(format string, args ...interface{}) *filterTerm {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
53 return &filterTerm{format: format, args: args}
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
54 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
55
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
56 func (fa filterAnd) serialize(stmt *strings.Builder, args *[]interface{}) {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
57 for i, node := range fa {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
58 if i > 0 {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
59 stmt.WriteString(" AND ")
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
60 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
61 stmt.WriteByte('(')
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
62 node.serialize(stmt, args)
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
63 stmt.WriteByte(')')
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 }
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
3194
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
67 func (fo filterOr) serialize(stmt *strings.Builder, args *[]interface{}) {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
68 for i, node := range fo {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
69 if i > 0 {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
70 stmt.WriteString(" OR ")
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
71 }
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
72 stmt.WriteByte('(')
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
73 node.serialize(stmt, args)
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
74 stmt.WriteByte(')')
3190
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
54a3e40cfbed controllers: moved filter builder to a separate file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
3194
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
77
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
78 func (fn *filterNot) serialize(stmt *strings.Builder, args *[]interface{}) {
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
79 stmt.WriteString("NOT (")
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
80 fn.filterNode.serialize(stmt, args)
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
81 stmt.WriteByte(')')
eeff2cc4ff9d controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3190
diff changeset
82 }
3217
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
83
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
84 func toInt8Array(txt string) *pgtype.Int8Array {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
85 parts := strings.Split(txt, ",")
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
86 var ints []int64
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
87 for _, part := range parts {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
88 part = strings.TrimSpace(part)
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
89 v, err := strconv.ParseInt(part, 10, 64)
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
90 if err != nil {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
91 continue
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
92 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
93 ints = append(ints, v)
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
94 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
95 var ia pgtype.Int8Array
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
96 if err := ia.Set(ints); err != nil {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
97 log.Printf("warn: %v\n", err)
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
98 return nil
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
99 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
100 return &ia
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
101 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
102
3776
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
103 func sliceToTextArray(s []string) *pgtype.TextArray {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
104 if len(s) == 0 {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
105 return nil
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
106 }
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
107 var ta pgtype.TextArray
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
108 if err := ta.Set(s); err != nil {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
109 log.Printf("warn: %v\n", err)
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
110 return nil
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
111 }
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
112 return &ta
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
113 }
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
114
3217
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
115 func toTextArray(txt string, allowed []string) *pgtype.TextArray {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
116 parts := strings.Split(txt, ",")
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
117 var accepted []string
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
118 for _, part := range parts {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
119 if part = strings.ToLower(strings.TrimSpace(part)); len(part) == 0 {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
120 continue
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
121 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
122 for _, a := range allowed {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
123 if part == a {
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
124 accepted = append(accepted, part)
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
125 break
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
126 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
127 }
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
128 }
3776
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
129 return sliceToTextArray(accepted)
3217
4c254651d80b Added template types "map", "diagram", "report".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3194
diff changeset
130 }
3776
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
131
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
132 func splitUpper(s string) []string {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
133 s = strings.Map(func(r rune) rune {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
134 if ('A' <= r && r <= 'Z') || r == ',' {
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
135 return r
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
136 }
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
137 return -1
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
138 }, strings.ToUpper(s))
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
139 return strings.FieldsFunc(s, func(r rune) bool { return r != ',' })
6521c962a7b6 Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3217
diff changeset
140 }