Created
November 17, 2022 21:49
-
-
Save jamesrr39/4b773d46cd4e6910c81c48c0fc70943e to your computer and use it in GitHub Desktop.
Go HTTPS server example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"fmt" | |
) | |
/* | |
To generate a key/cert pair: | |
openssl genrsa 2048 > host.key | |
chmod 400 host.key | |
openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.cert | |
*/ | |
func main() { | |
s := &http.Server{ | |
Addr: ":443", | |
} | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "hello world") | |
}) | |
err := s.ListenAndServeTLS("host.cert", "host.key") | |
if err != nil { | |
panic(err) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment