-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (34 loc) · 902 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
backend := flag.String("backend", "localhost:8080", "backend's host:port")
https := flag.Bool("https", true, "terminate https?")
crt := flag.String("crt", "crt", "certificate file path")
key := flag.String("key", "key", "key file path")
flag.Parse()
localAddr := ":80"
if *https {
localAddr = ":443"
}
log.Println("Using following config:")
log.Println("\thttps:", *https)
log.Println("\tcrt:", *crt)
log.Println("\tkey:", *key)
log.Println("\tbackend:", *backend)
proxy := httputil.NewSingleHostReverseProxy(&url.URL{
Scheme: "http",
Host: *backend,
})
log.Println("Listening on:", localAddr)
if *https {
log.Fatal(http.ListenAndServeTLS(localAddr, *crt, *key, proxy))
} else {
log.Fatal(http.ListenAndServe(localAddr, proxy))
}
}