Mercurial > gemma
diff pkg/imports/config.go @ 1708:49e047c2106e
Imports: Made imports re-runnable if they fail.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 08 Jan 2019 13:35:44 +0100 |
parents | dcbe2a7dc532 |
children | 61fa62f01f20 |
line wrap: on
line diff
--- a/pkg/imports/config.go Tue Jan 08 12:34:29 2019 +0100 +++ b/pkg/imports/config.go Tue Jan 08 13:35:44 2019 +0100 @@ -18,11 +18,11 @@ "database/sql" "encoding/json" "fmt" - "strings" "github.com/robfig/cron" "gemma.intevation.de/gemma/pkg/auth" + "gemma.intevation.de/gemma/pkg/common" ) type ( @@ -33,10 +33,6 @@ // of the registered import types. ImportKind string - // ConfigAttributes is a map of optional key/value attributes - // of an import configuration. - ConfigAttributes map[string]string - // Config is JSON serialized form of a import configuration. Config struct { // Kind is the import type. @@ -56,40 +52,23 @@ // URL is an optional URL used by the import. URL *string `json:"url"` // Attributes are optional key/value pairs for a configuration. - Attributes ConfigAttributes `json:"attributes,omitempty"` + Attributes common.Attributes `json:"attributes,omitempty"` } // IDConfig is the same as Config with an ID. // Mainly used for server delivered configurations. IDConfig struct { - ID int64 `json:"id"` - User string `json:"user"` - Kind ImportKind `json:"kind"` - SendEMail bool `json:"send-email"` - AutoAccept bool `json:"auto-accept"` - Cron *CronSpec `json:"cron,omitempty"` - URL *string `json:"url,omitempty"` - Attributes ConfigAttributes `json:"attributes,omitempty"` + ID int64 `json:"id"` + User string `json:"user"` + Kind ImportKind `json:"kind"` + SendEMail bool `json:"send-email"` + AutoAccept bool `json:"auto-accept"` + Cron *CronSpec `json:"cron,omitempty"` + URL *string `json:"url,omitempty"` + Attributes common.Attributes `json:"attributes,omitempty"` } ) -// Get fetches a value for given key out of the configuration. -// If the key was not found the bool component of the return value -// return false. -func (ca ConfigAttributes) Get(key string) (string, bool) { - if ca == nil { - return "", false - } - value, found := ca[key] - return value, found -} - -// Bool returns a bool value for a given key. -func (ca ConfigAttributes) Bool(key string) bool { - s, found := ca.Get(key) - return found && strings.ToLower(s) == "true" -} - // UnmarshalJSON checks if the incoming string // is a registered import type. func (ik *ImportKind) UnmarshalJSON(data []byte) error { @@ -174,14 +153,14 @@ return err } defer rows.Close() - var attributes map[string]string + var attributes common.Attributes for rows.Next() { var k, v string if err = rows.Scan(&k, &v); err != nil { return err } if attributes == nil { - attributes = map[string]string{} + attributes = common.Attributes{} } attributes[k] = v }