File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 11.git
2+ http-echo *
Original file line number Diff line number Diff line change 11package main
22
33import (
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+
919func 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
2030func 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}
You can’t perform that action at this time.
0 commit comments