move application code into beszel folder

This commit is contained in:
Henry Dollman
2024-08-11 13:41:57 -04:00
parent ea71492d13
commit 9da1e5751a
103 changed files with 84 additions and 7 deletions

48
beszel/cmd/agent/agent.go Normal file
View File

@@ -0,0 +1,48 @@
package main
import (
"beszel"
"beszel/internal/agent"
"beszel/internal/update"
"fmt"
"log"
"os"
"strings"
)
func main() {
// handle flags / subcommands
if len(os.Args) > 1 {
switch os.Args[1] {
case "-v":
fmt.Println(beszel.AppName+"-agent", beszel.Version)
case "update":
update.UpdateBeszelAgent()
}
os.Exit(0)
}
var pubKey []byte
if pubKeyEnv, exists := os.LookupEnv("KEY"); exists {
pubKey = []byte(pubKeyEnv)
} else {
log.Fatal("KEY environment variable is not set")
}
var port string
if p, exists := os.LookupEnv("PORT"); exists {
// allow passing an address in the form of "127.0.0.1:45876"
if !strings.Contains(port, ":") {
port = ":" + port
}
port = p
} else {
port = ":45876"
}
a := agent.NewAgent(pubKey, port)
a.Run()
}