mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Replace attributes map with new Attribute object
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user