diff pkg/imports/config.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 59055c8301df
children d29ac997eb34
line wrap: on
line diff
--- a/pkg/imports/config.go	Thu Jan 24 16:17:37 2019 +0100
+++ b/pkg/imports/config.go	Thu Jan 24 17:14:10 2019 +0100
@@ -19,16 +19,12 @@
 	"encoding/json"
 	"fmt"
 
-	"github.com/robfig/cron"
-
 	"gemma.intevation.de/gemma/pkg/auth"
 	"gemma.intevation.de/gemma/pkg/common"
+	"gemma.intevation.de/gemma/pkg/models"
 )
 
 type (
-	// CronSpec is a string containing a cron line.
-	CronSpec string
-
 	// ImportKind is a string which has to be one
 	// of the registered import types.
 	ImportKind string
@@ -44,7 +40,7 @@
 		// Cron is the cron schedule
 		// of this configuration if this value is not
 		// nil. If nil the import is not scheduled.
-		Cron *CronSpec `json:"cron"`
+		Cron *models.CronSpec `json:"cron"`
 		// URL is an optional URL used by the import.
 		URL *string `json:"url"`
 		// Attributes are optional key/value pairs for a configuration.
@@ -58,7 +54,7 @@
 		User       string            `json:"user"`
 		Kind       ImportKind        `json:"kind"`
 		SendEMail  bool              `json:"send-email"`
-		Cron       *CronSpec         `json:"cron,omitempty"`
+		Cron       *models.CronSpec  `json:"cron,omitempty"`
 		URL        *string           `json:"url,omitempty"`
 		Attributes common.Attributes `json:"attributes,omitempty"`
 	}
@@ -81,21 +77,6 @@
 	return nil
 }
 
-// UnmarshalJSON checks if the incoming string is
-// a valid cron line.
-func (cs *CronSpec) UnmarshalJSON(data []byte) error {
-	var spec string
-	if err := json.Unmarshal(data, &spec); err != nil {
-		return err
-	}
-	if _, err := cron.Parse(spec); err != nil {
-		return err
-	}
-	*cs = CronSpec(spec)
-
-	return nil
-}
-
 const (
 	configUser = "sys_admin"
 
@@ -138,7 +119,7 @@
 
 	cfg.Kind = ImportKind(kind)
 	if cron.Valid {
-		c := CronSpec(cron.String)
+		c := models.CronSpec(cron.String)
 		cfg.Cron = &c
 	}
 	if url.Valid {