Replace attributes map with new Attribute object

This commit is contained in:
Alex Dadgar
2018-10-13 14:08:58 -07:00
parent 521a1cf22f
commit 41bd0da920
3 changed files with 41 additions and 5 deletions

View File

@@ -72,6 +72,27 @@ type Attribute struct {
Unit string
}
func (a *Attribute) Copy() *Attribute {
ca := &Attribute{
Unit: a.Unit,
}
if a.Float != nil {
ca.Float = helper.Float64ToPtr(*a.Float)
}
if a.Int != nil {
ca.Int = helper.Int64ToPtr(*a.Int)
}
if a.Bool != nil {
ca.Bool = helper.BoolToPtr(*a.Bool)
}
if a.String != nil {
ca.String = helper.StringToPtr(*a.String)
}
return ca
}
// GoString returns a string representation of the attribute
func (a *Attribute) GoString() string {
if a == nil {

View File

@@ -88,3 +88,16 @@ func Pow(a, b int64) int64 {
}
return p
}
// CopyMapStringAttribute copies a map of string to Attribute
func CopyMapStringAttribute(in map[string]*Attribute) map[string]*Attribute {
if in == nil {
return nil
}
out := make(map[string]*Attribute, len(in))
for k, v := range in {
out[k] = v.Copy()
}
return out
}