netmaker/netclient/main.go

50 lines
1.1 KiB
Go
Raw Normal View History

2021-08-31 03:58:23 +08:00
//go:generate goversioninfo -icon=windowsdata/resource/netmaker.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
2021-03-26 00:17:52 +08:00
package main
import (
2021-07-26 02:22:20 +08:00
"log"
"os"
2021-09-20 02:03:47 +08:00
"runtime/debug"
2021-12-09 05:52:32 +08:00
"github.com/gravitl/netmaker/netclient/cli_options"
2021-07-26 02:22:20 +08:00
"github.com/gravitl/netmaker/netclient/command"
2021-09-20 02:03:47 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2021-08-31 03:58:23 +08:00
"github.com/gravitl/netmaker/netclient/ncwindows"
2021-07-26 02:22:20 +08:00
"github.com/urfave/cli/v2"
2021-03-26 00:17:52 +08:00
)
func main() {
2021-07-26 02:22:20 +08:00
app := cli.NewApp()
app.Name = "Netclient CLI"
app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
2022-01-13 23:05:12 +08:00
app.Version = "v0.10.0"
2021-03-26 00:17:52 +08:00
2021-12-09 05:52:32 +08:00
cliFlags := cli_options.GetFlags(ncutils.GetHostname())
app.Commands = cli_options.GetCommands(cliFlags[:])
setGarbageCollection()
2021-09-20 02:03:47 +08:00
if ncutils.IsWindows() {
2021-08-31 03:58:23 +08:00
ncwindows.InitWindows()
} else {
2021-12-09 05:52:32 +08:00
ncutils.CheckUID()
ncutils.CheckWG()
2021-08-31 03:58:23 +08:00
}
2021-09-20 02:03:47 +08:00
if len(os.Args) == 1 && ncutils.IsWindows() {
2021-08-31 03:58:23 +08:00
command.RunUserspaceDaemon()
} else {
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
2021-07-26 02:22:20 +08:00
}
2021-03-26 00:17:52 +08:00
}
2021-09-20 02:03:47 +08:00
func setGarbageCollection() {
_, gcset := os.LookupEnv("GOGC")
if !gcset {
2021-09-20 02:03:47 +08:00
debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
}
2021-09-20 02:03:47 +08:00
}