Skip to content

Commit

Permalink
Add https to http test util
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedearing committed Jan 25, 2024
1 parent c62c6ca commit 2d1952f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions go-httpserver/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"net/http"
"net/http/httputil"
Expand All @@ -10,8 +11,19 @@ import (
)

func main() {
var (
tlsCertificate string
tlsKey string
port string
)

flag.StringVar(&tlsCertificate, "cert-file", "", "Specify the certificate file")
flag.StringVar(&tlsKey, "cert-key", "", "Specify the certificate key")
flag.StringVar(&port, "port", ":8080", "The port to run the server on")

flag.Parse()
hs := http.Server{
Addr: ":8080",
Addr: port,
}

mux := http.NewServeMux()
Expand All @@ -26,5 +38,11 @@ func main() {
w.WriteHeader(http.StatusOK)
w.Write([]byte("👋 Hello🏻"))
})
log.Error(hs.ListenAndServe())
if tlsCertificate != "" {
log.Info("Serving TLS")
log.Error(hs.ListenAndServeTLS(tlsCertificate, tlsKey))
} else {
log.Info("Serving plain HTTP")
log.Error(hs.ListenAndServe())
}
}

0 comments on commit 2d1952f

Please sign in to comment.