mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
36 lines
611 B
Go
36 lines
611 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type machine struct {
|
|
hostname string
|
|
raftPort int
|
|
clientPort int
|
|
}
|
|
|
|
var machinesMap = map[string]machine{}
|
|
|
|
func addMachine(name string, hostname string, raftPort int, clientPort int) {
|
|
|
|
machinesMap[name] = machine{hostname, raftPort, clientPort}
|
|
|
|
}
|
|
|
|
func getClientAddr(name string) (string, bool) {
|
|
machine, ok := machinesMap[name]
|
|
if !ok {
|
|
return "", false
|
|
}
|
|
|
|
addr := fmt.Sprintf("%s:%v", machine.hostname, machine.clientPort)
|
|
|
|
return addr, true
|
|
}
|
|
|
|
// machineNum returns the number of machines in the cluster
|
|
func machineNum() int {
|
|
return len(machinesMap)
|
|
}
|