Mercurial > gemma
comparison pkg/imports/config.go @ 1704:897d4d8316ad
Import configuration: Made extra attributes updatable, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 07 Jan 2019 15:34:34 +0100 |
parents | 49b89575ab31 |
children | dcbe2a7dc532 |
comparison
equal
deleted
inserted
replaced
1703:d0830ebb3a23 | 1704:897d4d8316ad |
---|---|
32 // of the registered import types. | 32 // of the registered import types. |
33 ImportKind string | 33 ImportKind string |
34 | 34 |
35 // ConfigAttributes is a map of optional key/value attributes | 35 // ConfigAttributes is a map of optional key/value attributes |
36 // of an import configuration. | 36 // of an import configuration. |
37 ConfigAttributes map[string]*string | 37 ConfigAttributes map[string]string |
38 | 38 |
39 // Config is JSON serialized form of a import configuration. | 39 // Config is JSON serialized form of a import configuration. |
40 Config struct { | 40 Config struct { |
41 // Kind is the import type. | 41 // Kind is the import type. |
42 Kind ImportKind `json:"kind"` | 42 Kind ImportKind `json:"kind"` |
77 // return false. | 77 // return false. |
78 func (ca ConfigAttributes) Get(key string) (string, bool) { | 78 func (ca ConfigAttributes) Get(key string) (string, bool) { |
79 if ca == nil { | 79 if ca == nil { |
80 return "", false | 80 return "", false |
81 } | 81 } |
82 if value, found := ca[key]; found && value != nil { | 82 value, found := ca[key] |
83 return *value, true | 83 return value, found |
84 } | |
85 return "", false | |
86 } | 84 } |
87 | 85 |
88 // UnmarshalJSON checks if the incoming string | 86 // UnmarshalJSON checks if the incoming string |
89 // is a registered import type. | 87 // is a registered import type. |
90 func (ik *ImportKind) UnmarshalJSON(data []byte) error { | 88 func (ik *ImportKind) UnmarshalJSON(data []byte) error { |
167 rows, err := conn.QueryContext(ctx, loadConfigAttributesSQL, id) | 165 rows, err := conn.QueryContext(ctx, loadConfigAttributesSQL, id) |
168 if err != nil { | 166 if err != nil { |
169 return err | 167 return err |
170 } | 168 } |
171 defer rows.Close() | 169 defer rows.Close() |
172 var attributes map[string]*string | 170 var attributes map[string]string |
173 for rows.Next() { | 171 for rows.Next() { |
174 var k, v string | 172 var k, v string |
175 if err = rows.Scan(&k, &v); err != nil { | 173 if err = rows.Scan(&k, &v); err != nil { |
176 return err | 174 return err |
177 } | 175 } |
178 if attributes == nil { | 176 if attributes == nil { |
179 attributes = map[string]*string{} | 177 attributes = map[string]string{} |
180 } | 178 } |
181 attributes[k] = &v | 179 attributes[k] = v |
182 } | 180 } |
183 if err = rows.Err(); err != nil { | 181 if err = rows.Err(); err != nil { |
184 return err | 182 return err |
185 } | 183 } |
186 if len(attributes) > 0 { | 184 if len(attributes) > 0 { |