Created
February 23, 2018 12:06
-
-
Save JensRantil/534cfeb6e3f0b4058a008d3f5889aa82 to your computer and use it in GitHub Desktop.
Test of running multiple HTTP listeners.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bash-3.2$ curl -v http://localhost:8080/bar && echo | |
| * Trying ::1... | |
| * TCP_NODELAY set | |
| * Connected to localhost (::1) port 8080 (#0) | |
| > GET /bar HTTP/1.1 | |
| > Host: localhost:8080 | |
| > User-Agent: curl/7.54.0 | |
| > Accept: */* | |
| > | |
| < HTTP/1.1 200 OK | |
| < Date: Fri, 23 Feb 2018 12:06:35 GMT | |
| < Content-Length: 13 | |
| < Content-Type: text/plain; charset=utf-8 | |
| < | |
| * Connection #0 to host localhost left intact | |
| Hello, "/bar" | |
| bash-3.2$ curl -v http://localhost:8081/bar && echo | |
| * Trying ::1... | |
| * TCP_NODELAY set | |
| * Connection failed | |
| * connect to ::1 port 8081 failed: Connection refused | |
| * Trying 127.0.0.1... | |
| * TCP_NODELAY set | |
| * Connection failed | |
| * connect to 127.0.0.1 port 8081 failed: Connection refused | |
| * Failed to connect to localhost port 8081: Connection refused | |
| * Closing connection 0 | |
| curl: (7) Failed to connect to localhost port 8081: Connection refused |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "html" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) | |
| }) | |
| go log.Fatal(http.ListenAndServe(":8080", nil)) | |
| log.Fatal(http.ListenAndServe(":8081", nil)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment