Created
May 27, 2021 07:47
-
-
Save satr/0996d1762f50c5c2019f5fdc729cdf3b to your computer and use it in GitHub Desktop.
Two open http ports in Go app
This file contains 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 ( | |
"net/http" | |
) | |
func main() { | |
go func() { | |
http.ListenAndServe(":8001", &fooHandler{}) | |
}() | |
//the last call is outside goroutine to avoid that program just exit | |
http.ListenAndServe(":8002", &barHandler{}) | |
} | |
type fooHandler struct { | |
} | |
func (m *fooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("Listening on 8001: foo ")) | |
} | |
type barHandler struct { | |
} | |
func (m *barHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("Listening on 8002: bar ")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment