main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //go:generate goversioninfo -icon=windowsdata/resource/netmaker.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
  2. package main
  3. import (
  4. "log"
  5. "os"
  6. "runtime/debug"
  7. "github.com/gravitl/netmaker/netclient/cli_options"
  8. "github.com/gravitl/netmaker/netclient/command"
  9. "github.com/gravitl/netmaker/netclient/ncutils"
  10. "github.com/gravitl/netmaker/netclient/ncwindows"
  11. "github.com/urfave/cli/v2"
  12. )
  13. func main() {
  14. app := cli.NewApp()
  15. app.Name = "Netclient CLI"
  16. app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
  17. app.Version = "v0.10.0"
  18. cliFlags := cli_options.GetFlags(ncutils.GetHostname())
  19. app.Commands = cli_options.GetCommands(cliFlags[:])
  20. setGarbageCollection()
  21. if ncutils.IsWindows() {
  22. ncwindows.InitWindows()
  23. } else {
  24. ncutils.CheckUID()
  25. ncutils.CheckWG()
  26. }
  27. if len(os.Args) == 1 && ncutils.IsWindows() {
  28. command.RunUserspaceDaemon()
  29. } else {
  30. err := app.Run(os.Args)
  31. if err != nil {
  32. log.Fatal(err)
  33. }
  34. }
  35. }
  36. func setGarbageCollection() {
  37. _, gcset := os.LookupEnv("GOGC")
  38. if !gcset {
  39. debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
  40. }
  41. }