gorilla / mux

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
20.89k stars 1.85k forks source link

I would like to know how I could use Mux for TSL configuration and handle https requests #702

Open Leon16 opened 1 year ago

Leon16 commented 1 year ago

I would like to know how I could use Mux for TSL configuration and handle https requests. Should I just implement the following to achieve it:

r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)

server := &http.Server{ Addr: ":" + port, ReadTimeout: 5 time.Minute, WriteTimeout: 10 time.Second, TLSConfig: &tls.Config{ServerName: host}, Handler: r,

}

if err := server.ListenAndServeTLS(srvCert, srvKey); err != nil { log.Fatal(err) }

Where the paths to host, port, sevCert and srvKey will be provided via command line call

Not sure this would work.

amustaque97 commented 1 year ago

Syntax is correct and it should work. For taking input from CLI, you need to write additional code using either os.Args, flag or a package like cobra.

amustaque97 commented 1 year ago

@Leon16 can we close this issue? if there are no further questions or doubts?