fqdn

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2020 License: Apache-2.0 Imports: 6 Imported by: 62

README

go-fqdn

Go package to provide reasonable robust access to fully qualified hostname. It first tries to looks up your hostname in hosts file. If that fails, it falls back to doing lookup via dns.

Basically it tries to mirror how standard linux hostname -f works. For that reason, your hosts file should be configured properly, please refer to hosts(5) for that.

It also has no 3rd party dependencies.

Usage

This package uses go modules, so just writing code that uses it should be enough. For example of usage you can check out the example.

Documentation can be found here.

Supported go versions

Current and current - 1 versions of go are supported.

Known issues

On macos, when not using cgo (CGO_ENABLED=0), getting the fqdn hostname might not work. Depends on rest of your setup and how /etc/resolv.conf looks like. Since that file is not used much (at least based on documentation) by macos programs, it is possible it is not in correct state.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFqdnNotFound = errFqdnNotFound{}

Error for cases when we could not found fqdn for whatever reason.

View Source
var ErrHostnameFailed = errHostnameFailed{}

Error for cases when os.Hostname() fails.

Functions

func FqdnHostname

func FqdnHostname() (string, error)

Try to get fully qualified hostname for current machine.

It tries to mimic how `hostname -f` works, so except for few edge cases you should get the same result from both. One thing that needs to be mentioned is that it does not guarantee that you get back fqdn. There is no way to do that and `hostname -f` can also return non-fqdn hostname if your /etc/hosts is fucked up.

It checks few sources in this order:

  1. hosts file It parses hosts file if present and readable and returns first canonical hostname that also references your hostname. See hosts(5) for more details.
  2. dns lookup If lookup in hosts file fails, it tries to ask dns.

If none of steps above succeeds, ErrFqdnNotFound is returned as error. You will probably want to just use output from os.Hostname() at that point.

func Get deprecated

func Get() string

Get Fully Qualified Domain Name returns "unknown" or hostname in case of error

Deprecated:

This function has bad API, works poorly and is replace by
FqdnHostname. Please please do not use it. It *will* be removed
in the next version.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL