comparison pkg/models/common.go @ 2150:2c67c51d57ad

Print templates: Implemented GET of all templates.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 08 Feb 2019 11:31:57 +0100
parents ae0021feaac8
children 97bba8b51b9c
comparison
equal deleted inserted replaced
2148:4057a1f15174 2150:2c67c51d57ad
32 // WGS84 is the EPSG of the World Geodetic System 1984. 32 // WGS84 is the EPSG of the World Geodetic System 1984.
33 const WGS84 = 4326 33 const WGS84 = 4326
34 34
35 type ( 35 type (
36 Date struct{ time.Time } 36 Date struct{ time.Time }
37 Time struct{ time.Time }
38
37 // Country is a valid country 2 letter code. 39 // Country is a valid country 2 letter code.
38 Country string 40 Country string
39 // UniqueCountries is a list of unique countries. 41 // UniqueCountries is a list of unique countries.
40 UniqueCountries []Country 42 UniqueCountries []Country
41 ) 43 )
42 44
43 func (srd Date) MarshalJSON() ([]byte, error) { 45 func (d Date) MarshalJSON() ([]byte, error) {
44 return json.Marshal(srd.Format(common.DateFormat)) 46 return json.Marshal(d.Format(common.DateFormat))
45 } 47 }
46 48
47 func (srd *Date) UnmarshalJSON(data []byte) error { 49 func (d *Date) UnmarshalJSON(data []byte) error {
48 var s string 50 var s string
49 if err := json.Unmarshal(data, &s); err != nil { 51 if err := json.Unmarshal(data, &s); err != nil {
50 return err 52 return err
51 } 53 }
52 d, err := time.Parse(common.DateFormat, s) 54 d2, err := time.Parse(common.DateFormat, s)
53 if err == nil { 55 if err == nil {
54 *srd = Date{d} 56 *d = Date{d2}
57 }
58 return err
59 }
60
61 func (t Time) MarshalJSON() ([]byte, error) {
62 return json.Marshal(t.Format(common.TimeFormat))
63 }
64
65 func (t *Time) UnmarshalJSON(data []byte) error {
66 var s string
67 if err := json.Unmarshal(data, &s); err != nil {
68 return err
69 }
70 t2, err := time.Parse(common.TimeFormat, s)
71 if err == nil {
72 *t = Time{t2}
55 } 73 }
56 return err 74 return err
57 } 75 }
58 76
59 var ( 77 var (