pub
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ports := []string{"18081", "18082", "18083"}
|
||||
|
||||
for _, port := range ports {
|
||||
go startEchoServer(port)
|
||||
}
|
||||
|
||||
// Block main goroutine
|
||||
select {}
|
||||
}
|
||||
|
||||
func startEchoServer(port string) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
msg := fmt.Sprintf("Response from Backend Server [Port: %s] | Requested Path: %s", port, r.URL.Path)
|
||||
// Print to console so we can see which server handled it
|
||||
log.Printf("[Port %s] Handled request for %s", port, r.URL.Path)
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(msg + "\n"))
|
||||
})
|
||||
|
||||
log.Printf("Starting Echo Server on :%s", port)
|
||||
if err := http.ListenAndServe(":"+port, mux); err != nil {
|
||||
log.Fatalf("Server on %s failed: %v", port, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user