comparison pkg/imports/config.go @ 1696:ad5e1cddaa09

Imports: Resolved the remaining golint issues with this package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 04 Jan 2019 13:41:07 +0100
parents 06f08458d666
children 49b89575ab31
comparison
equal deleted inserted replaced
1695:be78b429ef6e 1696:ad5e1cddaa09
17 "context" 17 "context"
18 "database/sql" 18 "database/sql"
19 "encoding/json" 19 "encoding/json"
20 "fmt" 20 "fmt"
21 21
22 "github.com/robfig/cron"
23
22 "gemma.intevation.de/gemma/pkg/auth" 24 "gemma.intevation.de/gemma/pkg/auth"
23 "github.com/robfig/cron"
24 ) 25 )
25 26
26 type ( 27 type (
27 CronSpec string 28 // CronSpec is a string containing a cron line.
29 CronSpec string
30
31 // ImportKind is a string which has to be one
32 // of the registered import types.
28 ImportKind string 33 ImportKind string
29 34
35 // Config is JSON serialized form of a import configuration.
30 Config struct { 36 Config struct {
31 Kind ImportKind `json:"kind"` 37 // Kind is the import type.
32 SendEMail bool `json:"send-email"` 38 Kind ImportKind `json:"kind"`
33 AutoAccept bool `json:"auto-accept"` 39 // SendEMail indicates if a mail should be be send
34 Cron *CronSpec `json:"cron"` 40 // when the import was changed to states
35 URL *string `json:"url"` 41 // 'pending' or 'failed'.
42 SendEMail bool `json:"send-email"`
43 // AutoAccept indicates that an import
44 // automatically will change from state
45 // 'pending' to state 'accepted'.
46 AutoAccept bool `json:"auto-accept"`
47 // Cron is the cron schedule
48 // of this configuration if this value is not
49 // nil. If nil the import is not scheduled.
50 Cron *CronSpec `json:"cron"`
51 // URL is an optional URL used by the import.
52 URL *string `json:"url"`
36 } 53 }
37 54
55 // IDConfig is the same as Config with an ID.
56 // Mainly used for server delivered configurations.
38 IDConfig struct { 57 IDConfig struct {
39 ID int64 `json:"id"` 58 ID int64 `json:"id"`
40 User string `json:"user"` 59 User string `json:"user"`
41 Kind ImportKind `json:"kind"` 60 Kind ImportKind `json:"kind"`
42 SendEMail bool `json:"send-email"` 61 SendEMail bool `json:"send-email"`
44 Cron *CronSpec `json:"cron,omitempty"` 63 Cron *CronSpec `json:"cron,omitempty"`
45 URL *string `json:"url,omitempty"` 64 URL *string `json:"url,omitempty"`
46 } 65 }
47 ) 66 )
48 67
68 // UnmarshalJSON checks if the incoming string
69 // is a registered import type.
49 func (ik *ImportKind) UnmarshalJSON(data []byte) error { 70 func (ik *ImportKind) UnmarshalJSON(data []byte) error {
50 var s string 71 var s string
51 if err := json.Unmarshal(data, &s); err != nil { 72 if err := json.Unmarshal(data, &s); err != nil {
52 return err 73 return err
53 } 74 }
59 *ik = ImportKind(s) 80 *ik = ImportKind(s)
60 81
61 return nil 82 return nil
62 } 83 }
63 84
85 // UnmarshalJSON checks if the incoming string is
86 // a valid cron line.
64 func (cs *CronSpec) UnmarshalJSON(data []byte) error { 87 func (cs *CronSpec) UnmarshalJSON(data []byte) error {
65 var spec string 88 var spec string
66 if err := json.Unmarshal(data, &spec); err != nil { 89 if err := json.Unmarshal(data, &spec); err != nil {
67 return err 90 return err
68 } 91 }