Have service listen and server over TLS

Pass in command line arguments to the path of the certificate and key
files.
master
Buddy Sandidge 10 years ago
parent d1b889eac2
commit 35474b635a

@ -14,7 +14,7 @@ import (
func main() {
app := cli.NewApp()
app.Name = "what-is-my-ip"
app.Version = "0.1.0"
app.Version = "0.2.0"
app.Usage = "Webapp that gives the IP address for incoming requests"
app.Action = action
@ -25,6 +25,20 @@ func main() {
EnvVar: "WHAT_IS_MY_IP_ADDRESS",
Usage: "Address and port to bind to",
},
cli.StringFlag{
Name: "certificate, c",
Value: "cert.pem",
EnvVar: "WHAT_IS_MY_IP_CERTIFICATE",
Usage: "path to certificate file for https server",
},
cli.StringFlag{
Name: "key, k",
Value: "key.pem",
EnvVar: "WHAT_IS_MY_IP_KEY",
Usage: "path to key file for https server",
},
}
app.Run(os.Args)
@ -33,8 +47,10 @@ func main() {
func action(c *cli.Context) error {
http.HandleFunc("/", getIP)
address := c.String("address")
certificate := c.String("certificate")
key := c.String("key")
fmt.Printf("listening on %s\n", address)
return http.ListenAndServe(address, nil)
return http.ListenAndServeTLS(address, certificate, key, nil)
}
func getIP(w http.ResponseWriter, req *http.Request) {

Loading…
Cancel
Save