From b05886db734936fda16abbd87e296d3528d97ca3 Mon Sep 17 00:00:00 2001 From: Bolke de Bruin <bolke@xs4all.nl> Date: Thu, 11 Aug 2022 14:25:07 +0200 Subject: [PATCH] Remove cobra Cobra is pretty opnionated and its complexity isnt required currently. --- cmd/rdpgw/main.go | 18 ++++++++---------- go.mod | 5 ++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cmd/rdpgw/main.go b/cmd/rdpgw/main.go index 9f8510b..8ff1152 100644 --- a/cmd/rdpgw/main.go +++ b/cmd/rdpgw/main.go @@ -3,6 +3,7 @@ package main import ( "context" "crypto/tls" + "github.com/thought-machine/go-flags" "github.com/bolkedebruin/rdpgw/cmd/rdpgw/api" "github.com/bolkedebruin/rdpgw/cmd/rdpgw/common" "github.com/bolkedebruin/rdpgw/cmd/rdpgw/config" @@ -10,7 +11,6 @@ import ( "github.com/bolkedebruin/rdpgw/cmd/rdpgw/security" "github.com/coreos/go-oidc/v3/oidc" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/spf13/cobra" "golang.org/x/oauth2" "log" "net/http" @@ -18,21 +18,19 @@ import ( "strconv" ) -var cmd = &cobra.Command{ - Use: "rdpgw", - Long: "Remote Desktop Gateway", +var opts struct { + configFile string `short:"c" long:"conf" description:"config file (yaml)" default:"rdpgw.yaml"` } -var ( - configFile string -) - var conf config.Configuration func main() { // get config - cmd.PersistentFlags().StringVarP(&configFile, "conf", "c", "rdpgw.yaml", "config file (json, yaml, ini)") - conf = config.Load(configFile) + _, err := flags.Parse(&opts) + if err != nil { + panic(err) + } + conf = config.Load(opts.configFile) security.VerifyClientIP = conf.Security.VerifyClientIp diff --git a/go.mod b/go.mod index 939e2bd..5536858 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/knadh/koanf v1.4.2 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/prometheus/client_golang v1.12.1 - github.com/spf13/cobra v1.5.0 + github.com/thought-machine/go-flags v1.6.1 golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c ) @@ -20,7 +20,6 @@ require ( github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/gorilla/securecookie v1.1.1 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -29,7 +28,6 @@ require ( github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.7.1 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect @@ -37,4 +35,5 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect + gopkg.in/yaml.v3 v3.0.0 // indirect ) -- GitLab