add listening ip configuration

This commit is contained in:
Darko Luketic 2024-12-31 13:29:23 +01:00
parent d2e155dae4
commit 7e4621573e

View File

@ -10,7 +10,10 @@ import (
"github.com/spf13/cobra"
)
var port = "31337"
var (
ip = "127.0.0.1"
port = "31337"
)
// simpleCmd represents the simple command
var simpleCmd = &cobra.Command{
@ -31,7 +34,7 @@ var simpleCmd = &cobra.Command{
w.WriteHeader(http.StatusForbidden)
}
}))
addr := fmt.Sprintf("127.0.0.1:%s", port)
addr := fmt.Sprintf("%s:%s", ip, port)
fmt.Println("Listening on addr:", addr)
return http.ListenAndServe(addr, r)
},
@ -49,5 +52,6 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// simpleCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
simpleCmd.Flags().StringVarP(&ip, "addr", "a", "127.0.0.1", "IP Address to listen on")
simpleCmd.Flags().StringVarP(&port, "port", "p", "31337", "Port to listen on")
}