feat: initialize Go agent module with config, Makefile and project structure
This commit is contained in:
17
Agent/Makefile
Normal file
17
Agent/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
.PHONY: build build-windows build-linux clean
|
||||
|
||||
BINARY=nexus-agent
|
||||
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)"
|
||||
|
||||
build:
|
||||
go build $(LDFLAGS) -o bin/$(BINARY) ./cmd/agent
|
||||
|
||||
build-windows:
|
||||
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY).exe ./cmd/agent
|
||||
|
||||
build-linux:
|
||||
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/$(BINARY)-linux ./cmd/agent
|
||||
|
||||
clean:
|
||||
rm -rf bin/
|
||||
BIN
Agent/agent.exe
Normal file
BIN
Agent/agent.exe
Normal file
Binary file not shown.
9
Agent/cmd/agent/main.go
Normal file
9
Agent/cmd/agent/main.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
fmt.Printf("NexusRMM Agent %s\n", version)
|
||||
}
|
||||
24
Agent/go.mod
Normal file
24
Agent/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/nexusrmm/agent
|
||||
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/shirou/gopsutil/v4 v4.24.0
|
||||
google.golang.org/grpc v1.60.0
|
||||
google.golang.org/protobuf v1.32.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.7.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d84 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
||||
github.com/tklauser/numcpus v0.8.0 // indirect
|
||||
github.com/yusufpapurcu/info v0.0.0-20240514213526-8f62d0eb11ac // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
|
||||
)
|
||||
40
Agent/internal/config/config.go
Normal file
40
Agent/internal/config/config.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServerAddress string `yaml:"server_address"`
|
||||
AgentID string `yaml:"agent_id"`
|
||||
HeartbeatInterval int `yaml:"heartbeat_interval"`
|
||||
TLSEnabled bool `yaml:"tls_enabled"`
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
cfg := &Config{
|
||||
ServerAddress: "localhost:5001",
|
||||
HeartbeatInterval: 60,
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return cfg, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if err := yaml.Unmarshal(data, cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (c *Config) Save(path string) error {
|
||||
data, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0600)
|
||||
}
|
||||
Reference in New Issue
Block a user