1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-10-30 23:08:02 +02:00

Proper cli command detection

This commit is contained in:
DarthSim
2021-11-15 15:33:32 +06:00
parent bed786372f
commit 0f7b8790ce
2 changed files with 19 additions and 16 deletions

View File

@@ -138,13 +138,17 @@ var (
) )
var ( var (
keyPath = flag.String("keypath", "", "path of the file with hex-encoded key") keyPath string
saltPath = flag.String("saltpath", "", "path of the file with hex-encoded salt") saltPath string
presetsPath = flag.String("presets", "", "path of the file with presets") presetsPath string
) )
func init() { func init() {
Reset() 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() { func Reset() {
@@ -270,8 +274,6 @@ func Reset() {
} }
func Configure() error { func Configure() error {
flag.Parse()
if port := os.Getenv("PORT"); len(port) > 0 { if port := os.Getenv("PORT"); len(port) > 0 {
Bind = fmt.Sprintf(":%s", port) Bind = fmt.Sprintf(":%s", port)
} }
@@ -335,10 +337,10 @@ func Configure() error {
} }
configurators.Int(&SignatureSize, "IMGPROXY_SIGNATURE_SIZE") configurators.Int(&SignatureSize, "IMGPROXY_SIGNATURE_SIZE")
if err := configurators.HexFile(&Keys, *keyPath); err != nil { if err := configurators.HexFile(&Keys, keyPath); err != nil {
return err return err
} }
if err := configurators.HexFile(&Salts, *saltPath); err != nil { if err := configurators.HexFile(&Salts, saltPath); err != nil {
return err return err
} }
@@ -373,7 +375,7 @@ func Configure() error {
configurators.String(&BaseURL, "IMGPROXY_BASE_URL") configurators.String(&BaseURL, "IMGPROXY_BASE_URL")
configurators.StringSlice(&Presets, "IMGPROXY_PRESETS") configurators.StringSlice(&Presets, "IMGPROXY_PRESETS")
if err := configurators.StringSliceFile(&Presets, *presetsPath); err != nil { if err := configurators.StringSliceFile(&Presets, presetsPath); err != nil {
return err return err
} }
configurators.Bool(&OnlyPresets, "IMGPROXY_ONLY_PRESETS") configurators.Bool(&OnlyPresets, "IMGPROXY_ONLY_PRESETS")

17
main.go
View File

@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@@ -112,14 +113,14 @@ func run() error {
} }
func main() { func main() {
if len(os.Args) > 1 { flag.Parse()
switch os.Args[1] {
case "health": switch flag.Arg(0) {
os.Exit(healthcheck()) case "health":
case "version": os.Exit(healthcheck())
fmt.Println(version.Version()) case "version":
os.Exit(0) fmt.Println(version.Version())
} os.Exit(0)
} }
if err := run(); err != nil { if err := run(); err != nil {