package garage import ( "fmt" "net" "strconv" ) // Node describes the common fields of both a [RemoteNode] and [LocalNode] type Node struct { IP string RPCPort int S3APIPort int } // RPCAddr returns the address of the node's RPC port. func (p Node) RPCAddr() string { return net.JoinHostPort(p.IP, strconv.Itoa(p.RPCPort)) } // S3APIAddr returns the address of the node's S3 API port. func (p Node) S3APIAddr() string { return net.JoinHostPort(p.IP, strconv.Itoa(p.S3APIPort)) } // RemoteNode describes all information necessary to connect to a given garage // node. type RemoteNode struct { Node ID string } // RPCNodeAddr returns the full node address (e.g. "id@ip:port") of the garage // node for use in communicating over RPC. func (p RemoteNode) RPCNodeAddr() string { return fmt.Sprintf("%s@%s", p.ID, p.RPCAddr()) } // LocalNode describes the configuration of a local garage instance. type LocalNode struct { Node AdminPort int } // AdminAddr returns the address of the node's S3 API port. func (p LocalNode) AdminAddr() string { return net.JoinHostPort(p.IP, strconv.Itoa(p.AdminPort)) }