Skip to content

Commit

Permalink
cmd/metro2: fixup server to add timeouts, resolve gosec error
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Sep 6, 2022
1 parent e587397 commit 3924638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 13 additions & 4 deletions cmd/metro2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"os"
"path/filepath"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -62,12 +63,20 @@ var webCmd = &cobra.Command{
port, _ := cmd.Flags().GetString("port")
fmt.Fprintf(os.Stdout, "Starting web server on port %s\n\n", port)

listen := "0.0.0.0:" + port
h, _ := server.ConfigureHandlers()
timeout, _ := time.ParseDuration("30s")
handler, _ := server.ConfigureHandlers()
serve := &http.Server{
Addr: "0.0.0.0:" + port,
Handler: handler,
ReadTimeout: timeout,
ReadHeaderTimeout: timeout,
WriteTimeout: timeout,
IdleTimeout: timeout,
}

test, _ := cmd.Flags().GetBool("test")
if !test {
err := http.ListenAndServe(listen, h)
if err != nil {
if err := serve.ListenAndServe(); err != nil {
return err
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

func parseInputFromRequest(r *http.Request) (file.File, error) {

src, _, err := r.FormFile("file")
if err != nil {

Expand Down

0 comments on commit 3924638

Please sign in to comment.