summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hostname.go53
-rw-r--r--hostname_linux.go22
-rw-r--r--init.go3
-rw-r--r--patchset.Make.go5
-rw-r--r--structs.go21
5 files changed, 17 insertions, 87 deletions
diff --git a/hostname.go b/hostname.go
deleted file mode 100644
index 85d61c6..0000000
--- a/hostname.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// +build linux
-
-package main
-
-import (
- "fmt"
- "os"
- "syscall"
-)
-
-// scutil --get ComputerName
-
-// getDomainName fetches the domain name using the getdomainname syscall.
-func getDomainName() (string, error) {
- var buf [256]byte
- err := syscall.Getdomainname(buf[:])
- if err != nil {
- return "", fmt.Errorf("failed to get domain name: %w", err)
- }
- // Trim null bytes
- n := 0
- for ; n < len(buf); n++ {
- if buf[n] == 0 {
- break
- }
- }
- return string(buf[:n]), nil
-}
-
-// GetFullHostname returns the hostname + domain name (if set).
-func GetFullHostname() (string, error) {
- host, err := os.Hostname()
- if err != nil {
- return "", fmt.Errorf("failed to get hostname: %w", err)
- }
-
- domain, err := getDomainName()
- if err != nil || domain == "" {
- return host, nil // fallback to short hostname
- }
-
- return fmt.Sprintf("%s.%s", host, domain), nil
-}
-
-func main() {
- fqdn, err := GetFullHostname()
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
- fmt.Println("Hostname + Domain:", fqdn)
-}
-
diff --git a/hostname_linux.go b/hostname_linux.go
deleted file mode 100644
index 4ab6dee..0000000
--- a/hostname_linux.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package main
-
-import (
- "fmt"
- "os"
- "syscall"
-)
-
-// GetFullHostname returns the hostname + domain name (if set).
-func getFullHostname() (string, error) {
- host, err := os.Hostname()
- if err != nil {
- return "", fmt.Errorf("failed to get hostname: %w", err)
- }
-
- domain, err := getDomainName()
- if err != nil || domain == "" {
- return host, nil // fallback to short hostname
- }
-
- return fmt.Sprintf("%s.%s", host, domain), nil
-}
diff --git a/init.go b/init.go
index 94b58d3..e91b9e9 100644
--- a/init.go
+++ b/init.go
@@ -9,6 +9,7 @@ import (
"time"
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/hostname"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -149,6 +150,8 @@ func (f *Forge) InitMachine() {
usr, _ := user.Current()
f.Config.Username = usr.Username
}
+ f.hostname, _ = hostname.Get()
+ // log.Info(hostname, err)
}
// only init's the protobuf. intended to not scan or change anything
diff --git a/patchset.Make.go b/patchset.Make.go
index 37c7c7d..a33c930 100644
--- a/patchset.Make.go
+++ b/patchset.Make.go
@@ -9,17 +9,18 @@ import (
"time"
"github.com/google/uuid"
+ "go.wit.com/lib/hostname"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
-func (f *Forge) newPatchset(name string) *Patchset {
+func newPatchset(name string) *Patchset {
pset := new(Patchset)
pset.Name = name
pset.Ctime = timestamppb.New(time.Now())
pset.Uuid = uuid.New().String()
- pset.Hostname = f.Machine.hostname
+ pset.Hostname, _ = hostname.Get()
return pset
}
diff --git a/structs.go b/structs.go
index 6682f87..1b540d3 100644
--- a/structs.go
+++ b/structs.go
@@ -10,17 +10,18 @@ import (
// maybe an interface someday?
type Forge struct {
// one-time initialized data
- initOnce sync.Once
- initErr error // init error, if any
- goSrc string // the path to go/src
- configDir string // normally ~/.config/forge
- goWork bool // means the user is currently using a go.work file
- Config *ForgeConfigs // config repos for readonly, private, etc
- Repos *gitpb.Repos // the repo protobufs
+ initOnce sync.Once
+ initErr error // init error, if any
+ goSrc string // the path to go/src
+ configDir string // normally ~/.config/forge
+ goWork bool // means the user is currently using a go.work file
+ Config *ForgeConfigs // config repos for readonly, private, etc
+ Repos *gitpb.Repos // the repo protobufs
+ configSave bool // if you need to save the config because things changed
+ hasFullScan bool // track last scan so it can be throttled
+ fullscan time.Time // time of the last scan so it can be throttled
+ hostname string // your hostname
// Machine *zoopb.Machine // things for virtigo to track vm's
- configSave bool // if you need to save the config because things changed
- hasFullScan bool // track last scan so it can be throttled
- fullscan time.Time // time of the last scan so it can be throttled
}
func (f *Forge) GetGoSrc() string {