Skip to content

Commit

Permalink
chore: clean the start of the server
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Dec 3, 2021
1 parent a067f0e commit c36625c
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,32 @@ var upgrader = websocket.Upgrader{
func main() {
flag.Parse()

http.HandleFunc("/data", dataHandler)
http.HandleFunc("/echo", echoHandler)
http.HandleFunc("/bench", benchHandler)
http.HandleFunc("/", whoamiHandler)
http.HandleFunc("/api", apiHandler)
http.HandleFunc("/health", healthHandler)

fmt.Println("Starting up on port " + port)

if len(cert) > 0 && len(key) > 0 {
server := &http.Server{
Addr: ":" + port,
}
mux := http.NewServeMux()
mux.HandleFunc("/data", dataHandler)
mux.HandleFunc("/echo", echoHandler)
mux.HandleFunc("/bench", benchHandler)
mux.HandleFunc("/", whoamiHandler)
mux.HandleFunc("/api", apiHandler)
mux.HandleFunc("/health", healthHandler)

if cert == "" || key == "" {
log.Printf("Starting up on port %s", port)

log.Fatal(http.ListenAndServe(":"+port, mux))
}

if len(ca) > 0 {
server.TLSConfig = setupMutualTLS(ca)
}
server := &http.Server{
Addr: ":" + port,
Handler: mux,
}

log.Fatal(server.ListenAndServeTLS(cert, key))
if len(ca) > 0 {
server.TLSConfig = setupMutualTLS(ca)
}
log.Fatal(http.ListenAndServe(":"+port, nil))

log.Printf("Starting up with TLS on port %s", port)

log.Fatal(server.ListenAndServeTLS(cert, key))
}

func setupMutualTLS(ca string) *tls.Config {
Expand Down

0 comments on commit c36625c

Please sign in to comment.