main.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //go:generate goversioninfo -icon=windowsdata/resource/netclient.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
  2. // -build gui
  3. package main
  4. import (
  5. "log"
  6. "os"
  7. "runtime/debug"
  8. "github.com/gravitl/netmaker/netclient/cli_options"
  9. "github.com/gravitl/netmaker/netclient/config"
  10. "github.com/gravitl/netmaker/netclient/functions"
  11. "github.com/gravitl/netmaker/netclient/ncutils"
  12. "github.com/gravitl/netmaker/netclient/ncwindows"
  13. "github.com/urfave/cli/v2"
  14. )
  15. var version = "dev"
  16. func main() {
  17. app := cli.NewApp()
  18. app.Name = "Netclient"
  19. app.Version = version
  20. ncutils.SetVersion(version)
  21. cliFlags := cli_options.GetFlags(ncutils.GetHostname())
  22. app.Commands = cli_options.GetCommands(cliFlags[:])
  23. app.Description = "Used to perform interactions with Netmaker server and set local WireGuard config."
  24. app.Usage = "Netmaker's netclient agent and CLI."
  25. app.UsageText = "netclient [global options] command [command options] [arguments...]. Adjust verbosity of given command with -v, -vv or -vvv (max)."
  26. setGarbageCollection()
  27. functions.SetHTTPClient()
  28. if ncutils.IsWindows() {
  29. ncwindows.InitWindows()
  30. } else {
  31. ncutils.CheckUID()
  32. ncutils.CheckWG()
  33. if ncutils.IsLinux() {
  34. ncutils.CheckFirewall()
  35. }
  36. }
  37. if len(os.Args) <= 1 && config.GuiActive {
  38. config.GuiRun.(func())()
  39. } else {
  40. err := app.Run(os.Args)
  41. if err != nil {
  42. log.Fatal(err)
  43. }
  44. }
  45. }
  46. func setGarbageCollection() {
  47. _, gcset := os.LookupEnv("GOGC")
  48. if !gcset {
  49. debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
  50. }
  51. }