comparison pkg/models/importbase.go @ 2036:74e24ae3205a unify_imports

Imports: Added a persistent model for the extra attributes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 25 Jan 2019 11:52:54 +0100
parents 83108e90b223
children d29ac997eb34
comparison
equal deleted inserted replaced
2035:2f6cadcb3558 2036:74e24ae3205a
13 13
14 package models 14 package models
15 15
16 import ( 16 import (
17 "encoding/json" 17 "encoding/json"
18 "errors"
18 "time" 19 "time"
19 20
21 "gemma.intevation.de/gemma/pkg/common"
20 "github.com/robfig/cron" 22 "github.com/robfig/cron"
21 ) 23 )
22 24
23 type ( 25 type (
24 // CronSpec is a string containing a cron line. 26 // CronSpec is a string containing a cron line.
78 return err 80 return err
79 } 81 }
80 *cs = CronSpec(spec) 82 *cs = CronSpec(spec)
81 return nil 83 return nil
82 } 84 }
85
86 func (ut *URLType) MarshalAttributes(attrs common.Attributes) error {
87 attrs.Set("url", ut.URL)
88 if ut.Insecure {
89 attrs.SetBool("insecure", ut.Insecure)
90 }
91 if ut.User != nil {
92 attrs.Set("user", *ut.User)
93 }
94 if ut.Password != nil {
95 attrs.Set("password", *ut.Password)
96 }
97 return nil
98 }
99
100 func (ut *URLType) UnmarshalAttributes(attrs common.Attributes) error {
101 url, found := attrs.Get("url")
102 if !found {
103 return errors.New("missing 'url' attribute")
104 }
105 ut.URL = url
106 if user, found := attrs.Get("user"); found {
107 ut.User = &user
108 }
109 if password, found := attrs.Get("password"); found {
110 ut.Password = &password
111 }
112 return nil
113 }