Mercurial > gemma
changeset 2047:78002c5e838c unify_imports
Imports: Code simplification.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 25 Jan 2019 18:24:14 +0100 |
parents | 725884a4c89a |
children | 3c4b8f4815af |
files | pkg/common/attributes.go pkg/controllers/importconfig.go pkg/imports/scheduled.go |
diffstat | 3 files changed, 16 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/common/attributes.go Fri Jan 25 18:17:37 2019 +0100 +++ b/pkg/common/attributes.go Fri Jan 25 18:24:14 2019 +0100 @@ -35,6 +35,17 @@ } ) +func (ca Attributes) Unmarshal(dst interface{}) error { + if ca == nil { + return nil + } + var err error + if um, ok := dst.(AttributesUnmarshaler); ok { + err = um.UnmarshalAttributes(ca) + } + return err +} + func (ca Attributes) Delete(key string) bool { if ca == nil { return false
--- a/pkg/controllers/importconfig.go Fri Jan 25 18:17:37 2019 +0100 +++ b/pkg/controllers/importconfig.go Fri Jan 25 18:24:14 2019 +0100 @@ -21,7 +21,6 @@ "github.com/gorilla/mux" - "gemma.intevation.de/gemma/pkg/common" "gemma.intevation.de/gemma/pkg/imports" ) @@ -240,12 +239,11 @@ Message: fmt.Sprintf("No constructor for kind '%s' found", cfg.Kind), } } + what := ctor() - if um, ok := what.(common.AttributesUnmarshaler); ok { - if err = um.UnmarshalAttributes(cfg.Attributes); err != nil { - return - } + if err = cfg.Attributes.Unmarshal(what); err != nil { + return } jr = JSONResult{Result: &imports.ImportConfigOut{
--- a/pkg/imports/scheduled.go Fri Jan 25 18:17:37 2019 +0100 +++ b/pkg/imports/scheduled.go Fri Jan 25 18:24:14 2019 +0100 @@ -71,10 +71,8 @@ what := ctor() // Fill the data structure - if um, ok := what.(common.AttributesUnmarshaler); ok { - if err := um.UnmarshalAttributes(cfg.Attributes); err != nil { - return 0, err - } + if err := cfg.Attributes.Unmarshal(what); err != nil { + return 0, err } converted := ConvertToInternal(kind, what)