From ea7aef4d9e79bf35d6968f2d370f6f67271d3e73 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 23 Jan 2025 15:23:08 +0100 Subject: Get token from stdin instead of flag --- main.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 56445a9..3c8b1a5 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "path" "path/filepath" "flag" + "bufio" "github.com/google/uuid" ) @@ -114,13 +115,22 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func main() { host := flag.String("n", "", "The hostname to listen on") port := flag.Int("p", 8080, "The port to listen on") - token := flag.String("t", "", "The token to use to protect uploads") + isToken := flag.Bool("t", false, "Use a token to protect uploads/deletes") filesPath := flag.String("d", "", "The path to the files") deleteEnabled := flag.Bool("D", false, "Enable deleting resources") flag.Parse() + + token := "" + if *isToken { + fmt.Print("Token: ") + sc := bufio.NewScanner(os.Stdin) + sc.Scan() + token = sc.Text() + } + boxHandler := BoxHandler { *filesPath, - *token, + token, *deleteEnabled, } if boxHandler.filesPath != "" { -- cgit v1.2.3