diff --git a/.dockerignore b/.dockerignore index 6b8710a..3235d0d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ .git +http-echo* diff --git a/main.go b/main.go index b78747d..d314281 100644 --- a/main.go +++ b/main.go @@ -1,22 +1,39 @@ package main import ( + "flag" + "fmt" "log" "net/http" + "os" "strings" ) +const Version = "0.0.1" + +var ( + httpAddr = flag.String("listen", ":80", "Listen address") + versDisp = flag.Bool("version", false, "Display version") +) + func redirect(w http.ResponseWriter, req *http.Request) { hostname := strings.Split(req.Host, ":") target := "https://" + hostname[0] + req.URL.Path if len(req.URL.RawQuery) > 0 { target += "?" + req.URL.RawQuery } - log.Printf("redirect to: %s", target) + log.Printf("redirect to: %s from: ", target, req.RemoteAddr) http.Redirect(w, req, target, http.StatusTemporaryRedirect) } func main() { - http.ListenAndServe(":80", http.HandlerFunc(redirect)) + flag.Parse() + + if *versDisp { + fmt.Printf("Version: v%s\n", Version) + os.Exit(0) + } + + http.ListenAndServe(*httpAddr, http.HandlerFunc(redirect)) }