You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
535 B
41 lines
535 B
1 year ago
|
package zones
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
// A Machine is a machine on a Zone
|
||
|
type Machine struct {
|
||
|
mu sync.Mutex
|
||
|
|
||
|
zone *Zone
|
||
|
id int
|
||
|
Name string
|
||
|
}
|
||
|
|
||
|
func (m *Machine) String() string {
|
||
|
return m.Name
|
||
|
}
|
||
|
|
||
|
// ID return the index within the [Zone] associated to this [Machine]
|
||
|
func (m *Machine) ID() int {
|
||
|
m.mu.Lock()
|
||
|
defer m.mu.Unlock()
|
||
|
|
||
|
if m.id == 0 {
|
||
|
zoneName := m.zone.Name
|
||
|
|
||
|
s := m.Name[len(zoneName)+1:]
|
||
|
|
||
|
id, err := strconv.ParseInt(s, 10, 8)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
m.id = int(id)
|
||
|
}
|
||
|
|
||
|
return m.id
|
||
|
}
|