Mercurial > gemma
comparison pkg/imports/config.go @ 4178:51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 05 Aug 2019 17:45:03 +0200 |
parents | 8b75ac5e243e |
children | 6270951dda28 |
comparison
equal
deleted
inserted
replaced
4177:8b75ac5e243e | 4178:51e90370eced |
---|---|
27 type ( | 27 type ( |
28 // ImportKind is a string which has to be one | 28 // ImportKind is a string which has to be one |
29 // of the registered import types. | 29 // of the registered import types. |
30 ImportKind string | 30 ImportKind string |
31 | 31 |
32 // ImportConfigIn is used to de-serialize JSON | |
33 // configurations coming from the REST endpoints | |
34 // to be stored in the database. | |
32 ImportConfigIn struct { | 35 ImportConfigIn struct { |
33 Kind ImportKind `json:"kind"` | 36 Kind ImportKind `json:"kind"` |
34 Config json.RawMessage `json:"config"` | 37 Config json.RawMessage `json:"config"` |
35 } | 38 } |
36 | 39 |
40 // ImportConfigOut is used to serialize | |
41 // JSON versions to the REST endpoints | |
42 // which are stored in the database. | |
37 ImportConfigOut struct { | 43 ImportConfigOut struct { |
38 ID int64 `json:"id"` | 44 ID int64 `json:"id"` |
39 Kind ImportKind `json:"kind"` | 45 Kind ImportKind `json:"kind"` |
40 User string `json:"user"` | 46 User string `json:"user"` |
41 Config interface{} `json:"config,omitempty"` | 47 Config interface{} `json:"config,omitempty"` |
42 } | 48 } |
43 | 49 |
50 // PersistentConfig is the the in-memory | |
51 // representation of a configuration | |
52 // which is stored in the database. | |
44 PersistentConfig struct { | 53 PersistentConfig struct { |
45 ID int64 | 54 ID int64 |
46 User string | 55 User string |
47 Kind string | 56 Kind string |
48 Attributes common.Attributes | 57 Attributes common.Attributes |
121 INSERT INTO import.import_configuration_attributes | 130 INSERT INTO import.import_configuration_attributes |
122 (import_configuration_id, k, v) | 131 (import_configuration_id, k, v) |
123 VALUES ($1, $2, $3)` | 132 VALUES ($1, $2, $3)` |
124 ) | 133 ) |
125 | 134 |
135 // UpdateContext stores an updated configuration to the database. | |
126 func (pc *PersistentConfig) UpdateContext(ctx context.Context, tx *sql.Tx) error { | 136 func (pc *PersistentConfig) UpdateContext(ctx context.Context, tx *sql.Tx) error { |
127 if _, err := tx.ExecContext( | 137 if _, err := tx.ExecContext( |
128 ctx, | 138 ctx, |
129 updateImportConfigurationSQL, | 139 updateImportConfigurationSQL, |
130 pc.ID, pc.User, pc.Kind, | 140 pc.ID, pc.User, pc.Kind, |
139 return err | 149 return err |
140 } | 150 } |
141 return storeConfigAttributes(ctx, tx, pc.ID, pc.Attributes) | 151 return storeConfigAttributes(ctx, tx, pc.ID, pc.Attributes) |
142 } | 152 } |
143 | 153 |
154 // LoadPersistentConfigContext loads a configuration from the database. | |
144 func LoadPersistentConfigContext( | 155 func LoadPersistentConfigContext( |
145 ctx context.Context, | 156 ctx context.Context, |
146 conn *sql.Conn, | 157 conn *sql.Conn, |
147 id int64, | 158 id int64, |
148 ) (*PersistentConfig, error) { | 159 ) (*PersistentConfig, error) { |
199 return err | 210 return err |
200 }) | 211 }) |
201 return cfg, err | 212 return cfg, err |
202 } | 213 } |
203 | 214 |
215 // ListAllPersistentConfigurationsContext iterates over all | |
216 // configurations stored in the database and reports every | |
217 // particular one to the callback fn. | |
204 func ListAllPersistentConfigurationsContext( | 218 func ListAllPersistentConfigurationsContext( |
205 ctx context.Context, | 219 ctx context.Context, |
206 conn *sql.Conn, | 220 conn *sql.Conn, |
207 fn func(*ImportConfigOut) error, | 221 fn func(*ImportConfigOut) error, |
208 ) error { | 222 ) error { |
287 err = send() | 301 err = send() |
288 } | 302 } |
289 return err | 303 return err |
290 } | 304 } |
291 | 305 |
306 // DeletePersistentConfigurationContext deletes | |
307 // a configuration from the database identified by | |
308 // its id. | |
292 func DeletePersistentConfigurationContext( | 309 func DeletePersistentConfigurationContext( |
293 ctx context.Context, | 310 ctx context.Context, |
294 tx *sql.Tx, | 311 tx *sql.Tx, |
295 id int64, | 312 id int64, |
296 ) error { | 313 ) error { |
348 } | 365 } |
349 } | 366 } |
350 return nil | 367 return nil |
351 } | 368 } |
352 | 369 |
370 // StoreContext stores a configuration to the database and returns | |
371 // its new database id. | |
353 func (pc *PersistentConfig) StoreContext(ctx context.Context, tx *sql.Tx) (int64, error) { | 372 func (pc *PersistentConfig) StoreContext(ctx context.Context, tx *sql.Tx) (int64, error) { |
354 var id int64 | 373 var id int64 |
355 if err := tx.QueryRowContext( | 374 if err := tx.QueryRowContext( |
356 ctx, | 375 ctx, |
357 insertImportConfigurationSQL, | 376 insertImportConfigurationSQL, |