Skip to content

Commit 999885f

Browse files
committed
Add version and listen cli-flags.
1 parent 1863b9f commit 999885f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.git
2+
http-echo*

main.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
package main
22

33
import (
4+
"flag"
5+
"fmt"
46
"log"
57
"net/http"
8+
"os"
69
"strings"
710
)
811

12+
const Version = "0.0.1"
13+
14+
var (
15+
httpAddr = flag.String("listen", ":80", "Listen address")
16+
versDisp = flag.Bool("version", false, "Display version")
17+
)
18+
919
func redirect(w http.ResponseWriter, req *http.Request) {
1020
hostname := strings.Split(req.Host, ":")
1121
target := "https://" + hostname[0] + req.URL.Path
1222
if len(req.URL.RawQuery) > 0 {
1323
target += "?" + req.URL.RawQuery
1424
}
15-
log.Printf("redirect to: %s", target)
25+
log.Printf("redirect to: %s from: ", target, req.RemoteAddr)
1626
http.Redirect(w, req, target,
1727
http.StatusTemporaryRedirect)
1828
}
1929

2030
func main() {
21-
http.ListenAndServe(":80", http.HandlerFunc(redirect))
31+
flag.Parse()
32+
33+
if *versDisp {
34+
fmt.Printf("Version: v%s\n", Version)
35+
os.Exit(0)
36+
}
37+
38+
http.ListenAndServe(*httpAddr, http.HandlerFunc(redirect))
2239
}

0 commit comments

Comments
 (0)