chore: clean the start of the server
This commit is contained in:
41
app.go
41
app.go
@ -55,27 +55,32 @@ var upgrader = websocket.Upgrader{
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
http.HandleFunc("/data", dataHandler)
|
mux := http.NewServeMux()
|
||||||
http.HandleFunc("/echo", echoHandler)
|
mux.HandleFunc("/data", dataHandler)
|
||||||
http.HandleFunc("/bench", benchHandler)
|
mux.HandleFunc("/echo", echoHandler)
|
||||||
http.HandleFunc("/", whoamiHandler)
|
mux.HandleFunc("/bench", benchHandler)
|
||||||
http.HandleFunc("/api", apiHandler)
|
mux.HandleFunc("/", whoamiHandler)
|
||||||
http.HandleFunc("/health", healthHandler)
|
mux.HandleFunc("/api", apiHandler)
|
||||||
|
mux.HandleFunc("/health", healthHandler)
|
||||||
|
|
||||||
fmt.Println("Starting up on port " + port)
|
if cert == "" || key == "" {
|
||||||
|
log.Printf("Starting up on port %s", port)
|
||||||
|
|
||||||
if len(cert) > 0 && len(key) > 0 {
|
log.Fatal(http.ListenAndServe(":"+port, mux))
|
||||||
server := &http.Server{
|
|
||||||
Addr: ":" + port,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ca) > 0 {
|
|
||||||
server.TLSConfig = setupMutualTLS(ca)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Fatal(server.ListenAndServeTLS(cert, key))
|
|
||||||
}
|
}
|
||||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":" + port,
|
||||||
|
Handler: mux,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ca) > 0 {
|
||||||
|
server.TLSConfig = setupMutualTLS(ca)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Starting up with TLS on port %s", port)
|
||||||
|
|
||||||
|
log.Fatal(server.ListenAndServeTLS(cert, key))
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupMutualTLS(ca string) *tls.Config {
|
func setupMutualTLS(ca string) *tls.Config {
|
||||||
|
Reference in New Issue
Block a user