Browse Source

fix indentation

master
Nicolas Massé 8 years ago
parent
commit
74e7b315b9
  1. 48
      src/itix.fr/forward/main.go

48
src/itix.fr/forward/main.go

@ -6,7 +6,7 @@ import (
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os" "os"
"strconv" "strconv"
) )
// The MyResponseWriter is a wrapper around the standard http.ResponseWriter // The MyResponseWriter is a wrapper around the standard http.ResponseWriter
@ -52,7 +52,7 @@ func SetupReverseProxy(local_port int, target string) {
// added automatically by the net/http package. // added automatically by the net/http package.
req.Host = "" req.Host = ""
} }
handler := http.NewServeMux() handler := http.NewServeMux()
handler.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) { handler.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
// Log the incoming request (including headers) // Log the incoming request (including headers)
fmt.Printf("%v %v HTTP/1.1\n", req.Method, req.URL) fmt.Printf("%v %v HTTP/1.1\n", req.Method, req.URL)
@ -74,27 +74,27 @@ func SetupReverseProxy(local_port int, target string) {
}) })
fmt.Printf("Listening on port %v for incoming requests...\n", local_port) fmt.Printf("Listening on port %v for incoming requests...\n", local_port)
err = http.ListenAndServe(fmt.Sprintf(":%v", local_port), handler) err = http.ListenAndServe(fmt.Sprintf(":%v", local_port), handler)
if (err != nil) { if err != nil {
fmt.Println("ERROR: %s", err) fmt.Println("ERROR: %s", err)
} }
} }
func main() { func main() {
portal_endpoint := os.Getenv("THREESCALE_PORTAL_ENDPOINT") portal_endpoint := os.Getenv("THREESCALE_PORTAL_ENDPOINT")
backend_endpoint := os.Getenv("BACKEND_ENDPOINT_OVERRIDE") backend_endpoint := os.Getenv("BACKEND_ENDPOINT_OVERRIDE")
portal_port_opt := os.Getenv("PORTAL_LISTEN_PORT") portal_port_opt := os.Getenv("PORTAL_LISTEN_PORT")
if (portal_port_opt == "") { if portal_port_opt == "" {
portal_port_opt = "9090" portal_port_opt = "9090"
fmt.Println("WARNING: No PORTAL_LISTEN_PORT environment variable found, defaulting to '9090'...") fmt.Println("WARNING: No PORTAL_LISTEN_PORT environment variable found, defaulting to '9090'...")
} }
backend_port_opt := os.Getenv("BACKEND_LISTEN_PORT") backend_port_opt := os.Getenv("BACKEND_LISTEN_PORT")
if (backend_port_opt == "") { if backend_port_opt == "" {
backend_port_opt = "9091" backend_port_opt = "9091"
fmt.Println("WARNING: No BACKEND_LISTEN_PORT environment variable found, defaulting to '9091'...") fmt.Println("WARNING: No BACKEND_LISTEN_PORT environment variable found, defaulting to '9091'...")
} }
error := false error := false
if portal_endpoint == "" { if portal_endpoint == "" {
@ -105,16 +105,16 @@ func main() {
fmt.Println("ERROR: No BACKEND_ENDPOINT_OVERRIDE environment variable found !") fmt.Println("ERROR: No BACKEND_ENDPOINT_OVERRIDE environment variable found !")
error = true error = true
} }
portal_port, err := strconv.Atoi(portal_port_opt) portal_port, err := strconv.Atoi(portal_port_opt)
if (err != nil) { if err != nil {
fmt.Printf("ERROR: Cannot parse the PORTAL_LISTEN_PORT environment variable (%s): %s\n", portal_port_opt, err) fmt.Printf("ERROR: Cannot parse the PORTAL_LISTEN_PORT environment variable (%s): %s\n", portal_port_opt, err)
error = true error = true
} }
backend_port, err := strconv.Atoi(backend_port_opt) backend_port, err := strconv.Atoi(backend_port_opt)
if (err != nil) { if err != nil {
fmt.Printf("ERROR: Cannot parse the BACKEND_LISTEN_PORT environment variable (%s): %s\n", backend_port_opt, err) fmt.Printf("ERROR: Cannot parse the BACKEND_LISTEN_PORT environment variable (%s): %s\n", backend_port_opt, err)
error = true error = true
} }
if error { if error {
os.Exit(1) os.Exit(1)
} }

Loading…
Cancel
Save