From 064b401da17348554c8fd10fa2424d7fc121fcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Thu, 29 Aug 2024 14:10:47 +0200 Subject: [PATCH] add host --- host/host.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 host/host.go diff --git a/host/host.go b/host/host.go new file mode 100644 index 0000000..5f32f42 --- /dev/null +++ b/host/host.go @@ -0,0 +1,21 @@ +package host + +import ( + "context" + "os/exec" +) + +// GetFQDN returns the fully qualified hostname of the current host +func GetFQDN(ctx context.Context) (string, error) { + cmd := exec.CommandContext(ctx, "hostname", "--fqdn") + if err := cmd.Run(); err != nil { + return "", err + } + + b, err := cmd.Output() + if err != nil { + return "", err + } + + return string(b), nil +}