comparison pkg/common/attributes.go @ 2563:dc4fae4bdb8f

Expose axis snapping tolerance to users
author Tom Gottfried <tom@intevation.de>
date Fri, 08 Mar 2019 19:15:47 +0100
parents 2c67c51d57ad
children 8c5df0f3562e
comparison
equal deleted inserted replaced
2562:ce39e9954e85 2563:dc4fae4bdb8f
2 // without warranty, see README.md and license for details. 2 // without warranty, see README.md and license for details.
3 // 3 //
4 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // SPDX-License-Identifier: AGPL-3.0-or-later
5 // License-Filename: LICENSES/AGPL-3.0.txt 5 // License-Filename: LICENSES/AGPL-3.0.txt
6 // 6 //
7 // Copyright (C) 2018 by via donau 7 // Copyright (C) 2018, 2019 by via donau
8 // – Österreichische Wasserstraßen-Gesellschaft mbH 8 // – Österreichische Wasserstraßen-Gesellschaft mbH
9 // Software engineering by Intevation GmbH 9 // Software engineering by Intevation GmbH
10 // 10 //
11 // Author(s): 11 // Author(s):
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> 12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13 // * Tom Gottfried <tom.gottfried@intevation.de>
13 14
14 package common 15 package common
15 16
16 import ( 17 import (
17 "log" 18 "log"
156 func (ca Attributes) SetInt(key string, value int) bool { 157 func (ca Attributes) SetInt(key string, value int) bool {
157 v := strconv.Itoa(value) 158 v := strconv.Itoa(value)
158 return ca.Set(key, v) 159 return ca.Set(key, v)
159 } 160 }
160 161
162 func (ca Attributes) Float(key string) (float64, bool) {
163 s, found := ca.Get(key)
164 if !found {
165 return 0, false
166 }
167 f, err := strconv.ParseFloat(s, 64)
168 if err != nil {
169 log.Printf("error: %v\n", err)
170 return 0, false
171 }
172 return f, true
173 }
174
175 func (ca Attributes) SetFloat(key string, value float64) bool {
176 v := strconv.FormatFloat(value, 'e', -1, 64)
177 return ca.Set(key, v)
178 }
179
161 func (ca Attributes) Duration(key string) (time.Duration, bool) { 180 func (ca Attributes) Duration(key string) (time.Duration, bool) {
162 s, found := ca.Get(key) 181 s, found := ca.Get(key)
163 if !found { 182 if !found {
164 return 0, false 183 return 0, false
165 } 184 }