From 35474b635a3081f6caccace642450314b51a905d Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Fri, 11 Nov 2016 20:49:17 -0800 Subject: [PATCH] Have service listen and server over TLS Pass in command line arguments to the path of the certificate and key files. --- what-is-my-ip.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/what-is-my-ip.go b/what-is-my-ip.go index 70f71a8..cd91948 100644 --- a/what-is-my-ip.go +++ b/what-is-my-ip.go @@ -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) {