1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/juju/network"
12
var netLookupHost = net.LookupHost
14
// HostAddress returns an network.Address for the specified
15
// hostname, depending on whether it is an IP or a resolvable
16
// hostname. The address is given public scope.
17
func HostAddress(hostname string) (network.Address, error) {
18
if ip := net.ParseIP(hostname); ip != nil {
19
addr := network.Address{
21
Type: network.DeriveAddressType(ip.String()),
22
Scope: network.ScopePublic,
26
// Only a resolvable hostname may be used as a public address.
27
if _, err := netLookupHost(hostname); err != nil {
28
return network.Address{}, err
30
addr := network.Address{
32
Type: network.HostName,
33
Scope: network.ScopePublic,