Extend the cmd with argument handling

- add cobra to relay server
- add logger instance for handshaker
This commit is contained in:
Zoltán Papp
2024-06-19 17:40:16 +02:00
parent 11de2ec42e
commit 0261e15aad
8 changed files with 67 additions and 20 deletions

View File

@@ -6,13 +6,27 @@ import (
"syscall"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/netbirdio/netbird/relay/server"
"github.com/netbirdio/netbird/util"
)
var (
listenAddress string
rootCmd = &cobra.Command{
Use: "relay",
Short: "Relay service",
Long: "Relay service for Netbird agents",
Run: execute,
}
)
func init() {
util.InitLog("trace", "console")
_ = util.InitLog("trace", "console")
rootCmd.PersistentFlags().StringVarP(&listenAddress, "listen-address", "l", ":1235", "listen address")
}
func waitForExitSignal() {
@@ -21,10 +35,9 @@ func waitForExitSignal() {
_ = <-osSigs
}
func main() {
address := "10.145.236.1:1235"
func execute(cmd *cobra.Command, args []string) {
srv := server.NewServer()
err := srv.Listen(address)
err := srv.Listen(listenAddress)
if err != nil {
log.Errorf("failed to bind server: %s", err)
os.Exit(1)
@@ -38,3 +51,10 @@ func main() {
os.Exit(1)
}
}
func main() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}