From ecb305256b70f9e93cd519698f3726dbc2eef4de Mon Sep 17 00:00:00 2001 From: Nodauf Date: Wed, 12 Jan 2022 10:12:24 +0400 Subject: [PATCH] Add verbose flag --- src/cmd/web.go | 7 ++++++- src/controllers/upload.go | 1 - src/routers/router.go | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/cmd/web.go b/src/cmd/web.go index 131293f..faa6698 100644 --- a/src/cmd/web.go +++ b/src/cmd/web.go @@ -62,6 +62,9 @@ var SearchAndReplaceMap = make(map[string]string) // TLSConfig contains the configuration for the webserver var TLSConfig tls.Config +// Verbose enable a verbose output +var Verbose bool + // cert contains certificate and private key var cert *tls.Certificate @@ -105,7 +108,7 @@ var webCmd = &cobra.Command{ } else if TLS && (!utils.FileExists(tlsCertificate) || !utils.FileExists(tlsKey)) { //if TLS enable check if the certificate and key files not exist return errors.New("Certificate file " + tlsCertificate + " or key file " + tlsKey + " not found") - } else if TLS && utils.FileExists(tlsCertificate) && utils.FileExists(tlsKey){ + } else if TLS && utils.FileExists(tlsCertificate) && utils.FileExists(tlsKey) { cer, err := tls.LoadX509KeyPair(tlsCertificate, tlsKey) if err != nil { return errors.New(err.Error()) @@ -189,4 +192,6 @@ func init() { webCmd.Flags().BoolVarP(&DisableListing, "disableListing", "d", false, "Disable directory listing") + webCmd.Flags().BoolVarP(&Verbose, "verbose", "v", false, "Verbose output") + } diff --git a/src/controllers/upload.go b/src/controllers/upload.go index 4525c83..e060a38 100644 --- a/src/controllers/upload.go +++ b/src/controllers/upload.go @@ -17,7 +17,6 @@ func UploadFile(w http.ResponseWriter, r *http.Request) { r.URL.Path = strings.Replace(r.URL.Path, "/private/", "", 1) filepath = path.Join((cmd.PrivateFolder), path.Clean(r.URL.Path)) } - fmt.Println(r.URL.Path) // Maximum upload of 1000 MB files r.ParseMultipartForm(10000000 << 20) // If the variable files exists diff --git a/src/routers/router.go b/src/routers/router.go index d190ba9..62f05c6 100644 --- a/src/routers/router.go +++ b/src/routers/router.go @@ -1,8 +1,10 @@ package routers import ( + "Swego/src/cmd" "Swego/src/controllers" "fmt" + "io/ioutil" "net/http" ) @@ -27,6 +29,17 @@ func Router(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "ParseForm() err: %v", err) return } + if cmd.Verbose { + data, err := ioutil.ReadAll(req.Body) + if err == nil && len(data) > 0 { + fmt.Println(string(data)) + } + req.ParseForm() + for key, value := range req.Form { + fmt.Printf("%s => %s \n", key, value) + } + + } controllers.UploadFile(w, req) default: