From 6793f8360e1fee6072f30103d4173e9d80e62b95 Mon Sep 17 00:00:00 2001 From: Mark Pashmfouroush Date: Thu, 21 Mar 2024 18:06:06 +0000 Subject: [PATCH] misc: add json config file parsing Signed-off-by: Mark Pashmfouroush --- example_config.json | 11 +++++++++++ main.go | 12 +++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 example_config.json diff --git a/example_config.json b/example_config.json new file mode 100644 index 000000000..6d24f3da7 --- /dev/null +++ b/example_config.json @@ -0,0 +1,11 @@ +{ + "verbose": false, + "bind": "127.0.0.1:8086", + "endpoint": "", + "key": "", + "gool": false, + "cfon": false, + "country": "DE", + "scan": true, + "rtt": "1000ms" +} diff --git a/main.go b/main.go index fa8b3500a..9e6cf8390 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "github.com/peterbourgon/ff/v4" "github.com/peterbourgon/ff/v4/ffhelp" + "github.com/peterbourgon/ff/v4/ffjson" ) var psiphonCountries = []string{ @@ -66,12 +67,17 @@ func main() { gool = fs.BoolLong("gool", "enable gool mode (warp in warp)") psiphon = fs.BoolLong("cfon", "enable psiphon mode (must provide country as well)") country = fs.StringEnumLong("country", fmt.Sprintf("psiphon country code (valid values: %s)", psiphonCountries), psiphonCountries...) - scan = fs.BoolLong("scan", "enable warp scanning (experimental)") + scan = fs.BoolLong("scan", "enable warp scanning") rtt = fs.DurationLong("rtt", 1000*time.Millisecond, "scanner rtt limit") + _ = fs.String('c', "config", "", "path to config file") ) - // Config file and envvars can be added through ff later - err := ff.Parse(fs, os.Args[1:]) + err := ff.Parse( + fs, + os.Args[1:], + ff.WithConfigFileFlag("config"), + ff.WithConfigFileParser(ffjson.Parse), + ) switch { case errors.Is(err, ff.ErrHelp): fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs))