Mercurial > gemma
view pkg/models/common.go @ 1900:6a67cd819e93
To prepare stretch import made some model data types re-usable.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 18 Jan 2019 15:04:53 +0100 |
parents | 84e78d2e2d95 |
children | 71b722809b2b |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> package models import ( "encoding/json" "errors" "time" ) var ( errNoString = errors.New("Not a string") errNoByteSlice = errors.New("Not a byte slice") ) // WGS84 is the EPSG of the World Geodetic System 1984. const WGS84 = 4326 const DateFormat = "2006-01-02" type Date struct{ time.Time } func (srd Date) MarshalJSON() ([]byte, error) { return json.Marshal(srd.Format(DateFormat)) } func (srd *Date) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { return err } d, err := time.Parse(DateFormat, s) if err == nil { *srd = Date{d} } return err }