diff pkg/common/attributes.go @ 4162:8c5df0f3562e

Made 'golint' and 'staticcheck' happy with common package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 02 Aug 2019 17:53:18 +0200
parents dc4fae4bdb8f
children 5f47eeea988d
line wrap: on
line diff
--- a/pkg/common/attributes.go	Fri Aug 02 17:14:13 2019 +0200
+++ b/pkg/common/attributes.go	Fri Aug 02 17:53:18 2019 +0200
@@ -26,15 +26,20 @@
 	// of a configuration.
 	Attributes map[string]string
 
+	// AttributesMarshaler is an interface to implement
+	// custom marshalling for the implementing type.
 	AttributesMarshaler interface {
 		MarshalAttributes(Attributes) error
 	}
 
+	// AttributesUnmarshaler is and interface to implement
+	// custom unmarshalling for the implementing type.
 	AttributesUnmarshaler interface {
 		UnmarshalAttributes(Attributes) error
 	}
 )
 
+// Marshal fills src into ca.
 func (ca Attributes) Marshal(src interface{}) error {
 	if ca == nil {
 		return nil
@@ -46,6 +51,7 @@
 	return err
 }
 
+// Unmarshal stored ca into dst.
 func (ca Attributes) Unmarshal(dst interface{}) error {
 	if ca == nil {
 		return nil
@@ -57,6 +63,8 @@
 	return err
 }
 
+// Delete removes a key and its associated value from these
+// attriibutes. Return true if the key/value pair was deleted.
 func (ca Attributes) Delete(key string) bool {
 	if ca == nil {
 		return false
@@ -79,6 +87,8 @@
 	return value, found
 }
 
+// Set stores a key/value pair in the attributes.
+// Returns true if the storing succeeded.
 func (ca Attributes) Set(key, value string) bool {
 	if ca == nil {
 		return false
@@ -93,6 +103,9 @@
 	return found && strings.ToLower(s) == "true"
 }
 
+// SetBool stores a bool value with a given key in
+// this attributes.
+// Returns true if the storing succeeded.
 func (ca Attributes) SetBool(key string, value bool) bool {
 	var v string
 	if value {
@@ -103,6 +116,9 @@
 	return ca.Set(key, v)
 }
 
+// Date returns a time.Time for a given key.
+// Returns true if the key was found and the
+// represents a date.
 func (ca Attributes) Date(key string) (time.Time, bool) {
 	s, found := ca.Get(key)
 	if !found {
@@ -116,6 +132,8 @@
 	return d, true
 }
 
+// SetDate stores a date with a given key in the attributes.
+// Returns true if the storage succeeded.
 func (ca Attributes) SetDate(key string, date time.Time) bool {
 	s := date.Format(DateFormat)
 	return ca.Set(key, s)
@@ -135,12 +153,17 @@
 	return t, true
 }
 
+// SetTime stores a time with a given key in the attributes.
+// Returns true if the storage succeeded.
 func (ca Attributes) SetTime(key string, t time.Time) bool {
 	value := t.Format(TimeFormat)
 	return ca.Set(key, value)
 
 }
 
+// Int returns an int for a given key.
+// Returns true if the key was found and the value
+// is an integer.
 func (ca Attributes) Int(key string) (int, bool) {
 	s, found := ca.Get(key)
 	if !found {
@@ -154,11 +177,16 @@
 	return i, true
 }
 
+// SetInt stores an int with a given key in the attributes.
+// Returns true if the storage succeeded.
 func (ca Attributes) SetInt(key string, value int) bool {
 	v := strconv.Itoa(value)
 	return ca.Set(key, v)
 }
 
+// Float returns a float64 for a given key.
+// Returns true if the key was found and the value
+// is a floating point value.
 func (ca Attributes) Float(key string) (float64, bool) {
 	s, found := ca.Get(key)
 	if !found {
@@ -172,11 +200,16 @@
 	return f, true
 }
 
+// SetFloat stores an float64 with a given key in the attributes.
+// Returns true if the storage succeeded.
 func (ca Attributes) SetFloat(key string, value float64) bool {
 	v := strconv.FormatFloat(value, 'e', -1, 64)
 	return ca.Set(key, v)
 }
 
+// Duration returns a duration for a given key.
+// Returns true if the key was found and the value
+// is a duration.
 func (ca Attributes) Duration(key string) (time.Duration, bool) {
 	s, found := ca.Get(key)
 	if !found {
@@ -190,6 +223,8 @@
 	return d, true
 }
 
+// SetDuration stores a duration with a given key in the attributes.
+// Returns true if the storage succeeded.
 func (ca Attributes) SetDuration(key string, value time.Duration) bool {
 	v := value.String()
 	return ca.Set(key, v)