package main import ( "fmt" "net/http" "os" "strconv" "strings" ) func main() { serverPort := 12345 path := "" reverseHost := "" if len(os.Args) > 1 { for k, v := range os.Args { if k == 0 { continue } arg := strings.TrimSpace(v) hasPortL := strings.HasPrefix(arg, "--port=") hasPortS := strings.HasPrefix(arg, "-p=") hasPath := strings.HasPrefix(arg, "--path=") if strings.HasPrefix(arg, "--host=") { reverseHost = strings.TrimPrefix(arg, "--host=") } if hasPortL { i, err := strconv.ParseInt(strings.ReplaceAll(arg, "--port=", ""), 10, 32) if err == nil { serverPort = int(i) break } } if hasPortS { i, err := strconv.ParseInt(strings.ReplaceAll(arg, "-p=", ""), 10, 32) if err == nil { serverPort = int(i) break } } if hasPath { path = strings.ReplaceAll(arg, "--path=", "") } } } if strings.HasSuffix(path, "/") { path = strings.TrimSuffix(path, "/") } if len(path) > 0 && !strings.HasPrefix(path, "/") { path = fmt.Sprintf("/%s", path) } http.HandleFunc(fmt.Sprintf("%s/", path), createIndexHandler(reverseHost)) http.HandleFunc(fmt.Sprintf("%s/jrebel/leases", path), jrebelLeasesHandler) http.HandleFunc(fmt.Sprintf("%s/jrebel/leases/1", path), jrebelLeases1Handler) http.HandleFunc(fmt.Sprintf("%s/agent/leases", path), jrebelLeasesHandler) http.HandleFunc(fmt.Sprintf("%s/agent/leases/1", path), jrebelLeases1Handler) http.HandleFunc(fmt.Sprintf("%s/jrebel/validate-connection", path), jrebelValidateHandler) http.HandleFunc(fmt.Sprintf("%s/rpc/ping.action", path), pingHandler) http.HandleFunc(fmt.Sprintf("%s/rpc/obtainTicket.action", path), obtainTicketHandler) http.HandleFunc(fmt.Sprintf("%s/rpc/releaseTicket.action", path), releaseTicketHandler) fmt.Printf("start server with port = %d\n", serverPort) _ = http.ListenAndServe(":"+strconv.Itoa(serverPort), nil) }