Skip to content
Node: os.hostname()github.com/sahilkhaire/gox/osutil

Hostname

Overview

Hostname returns the host name.

If you are coming from Node.js, the closest pattern is os.hostname().

Signature

go
func Hostname() (string, error)

Compare: Node.js · Standard Go · gox

js
os.hostname();
go
val, err := os.Hostname()
go
import "github.com/sahilkhaire/gox/osutil"

name, err := osutil.Hostname()

Example

go
import "github.com/sahilkhaire/gox/osutil"

name, err := osutil.Hostname()

Tips

Import github.com/sahilkhaire/gox/osutil and call Hostname directly. See the comparison below for the standard library equivalent.

Standard library alternative

Use the standard library directly:

go
val, err := os.Hostname()

Back to osutil package overview

MIT Licensed · Built for Node.js developers moving to Go