Mercurial > gemma
comparison pkg/models/importbase.go @ 2016:25967829cf00 unify_imports
Started to simplify the import models.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 24 Jan 2019 17:14:10 +0100 |
parents | |
children | 070ac9dd61a1 |
comparison
equal
deleted
inserted
replaced
2003:917c672591c2 | 2016:25967829cf00 |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2018 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package models | |
15 | |
16 import ( | |
17 "encoding/json" | |
18 "time" | |
19 | |
20 "github.com/robfig/cron" | |
21 ) | |
22 | |
23 type ( | |
24 // CronSpec is a string containing a cron line. | |
25 CronSpec string | |
26 | |
27 QueueConfigurationType struct { | |
28 Trys *int `json:"trys,omitempty"` | |
29 WaitRetry *time.Duration `json:"wait-retry,omitempty"` | |
30 Cron *CronSpec `json:"cron,omitempty"` | |
31 EMail bool `json:"send-email,omitempty"` | |
32 } | |
33 | |
34 QueueConfigurationGetter interface { | |
35 GetQueueConfiguration() *QueueConfigurationType | |
36 } | |
37 | |
38 URLType struct { | |
39 URL string `json:"url"` | |
40 Insecure bool `json:"insecure,omitempty"` | |
41 User *string `json:"user,omitempty"` | |
42 Password *string `json:"password,omitempty"` | |
43 } | |
44 | |
45 URLTypeGetter interface { | |
46 GetURLType() *URLType | |
47 } | |
48 ) | |
49 | |
50 func (qct *QueueConfigurationType) GetQueueConfiguration() *QueueConfigurationType { | |
51 return qct | |
52 } | |
53 | |
54 func (ut *URLType) GetURLType() *URLType { | |
55 return ut | |
56 } | |
57 | |
58 // UnmarshalJSON checks if the incoming string is a valid cron line. | |
59 func (cs *CronSpec) UnmarshalJSON(data []byte) error { | |
60 var spec string | |
61 if err := json.Unmarshal(data, &spec); err != nil { | |
62 return err | |
63 } | |
64 if _, err := cron.Parse(spec); err != nil { | |
65 return err | |
66 } | |
67 *cs = CronSpec(spec) | |
68 return nil | |
69 } |