diff --git a/config/config.go b/config/config.go index a4151bf3..3ca76ccb 100644 --- a/config/config.go +++ b/config/config.go @@ -138,13 +138,17 @@ var ( ) var ( - keyPath = flag.String("keypath", "", "path of the file with hex-encoded key") - saltPath = flag.String("saltpath", "", "path of the file with hex-encoded salt") - presetsPath = flag.String("presets", "", "path of the file with presets") + keyPath string + saltPath string + presetsPath string ) func init() { Reset() + + flag.StringVar(&keyPath, "keypath", "", "path of the file with hex-encoded key") + flag.StringVar(&saltPath, "saltpath", "", "path of the file with hex-encoded salt") + flag.StringVar(&presetsPath, "presets", "", "path of the file with presets") } func Reset() { @@ -270,8 +274,6 @@ func Reset() { } func Configure() error { - flag.Parse() - if port := os.Getenv("PORT"); len(port) > 0 { Bind = fmt.Sprintf(":%s", port) } @@ -335,10 +337,10 @@ func Configure() error { } configurators.Int(&SignatureSize, "IMGPROXY_SIGNATURE_SIZE") - if err := configurators.HexFile(&Keys, *keyPath); err != nil { + if err := configurators.HexFile(&Keys, keyPath); err != nil { return err } - if err := configurators.HexFile(&Salts, *saltPath); err != nil { + if err := configurators.HexFile(&Salts, saltPath); err != nil { return err } @@ -373,7 +375,7 @@ func Configure() error { configurators.String(&BaseURL, "IMGPROXY_BASE_URL") configurators.StringSlice(&Presets, "IMGPROXY_PRESETS") - if err := configurators.StringSliceFile(&Presets, *presetsPath); err != nil { + if err := configurators.StringSliceFile(&Presets, presetsPath); err != nil { return err } configurators.Bool(&OnlyPresets, "IMGPROXY_ONLY_PRESETS") diff --git a/main.go b/main.go index 637e33a4..f5a7db8b 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "fmt" "os" "os/signal" @@ -112,14 +113,14 @@ func run() error { } func main() { - if len(os.Args) > 1 { - switch os.Args[1] { - case "health": - os.Exit(healthcheck()) - case "version": - fmt.Println(version.Version()) - os.Exit(0) - } + flag.Parse() + + switch flag.Arg(0) { + case "health": + os.Exit(healthcheck()) + case "version": + fmt.Println(version.Version()) + os.Exit(0) } if err := run(); err != nil {