Skip to content

Commit

Permalink
Change to multiple listening ports
Browse files Browse the repository at this point in the history
  • Loading branch information
rancher-max authored Jan 6, 2020
1 parent 5579172 commit 1201e3b
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,53 @@ package main

import (
"fmt"
"log"
"net/http"
"time"
)

func handler(w http.ResponseWriter, r *http.Request) {
// Arbitrary sleep so that we can demonstrate autoscaler
log.Println("Basic logging -- request received")
time.Sleep(51 * time.Millisecond)
fmt.Fprintln(w, "Stampede 2020 Demo: Initial Commit")
func main() {
finish := make(chan bool)

server8001 := http.NewServeMux()
server8001.HandleFunc("/", default8001)
server8001.HandleFunc("/foo", foo8001)
server8001.HandleFunc("/bar", bar8001)

server8002 := http.NewServeMux()
server8002.HandleFunc("/", default8002)
server8002.HandleFunc("/foo", foo8002)
server8002.HandleFunc("/bar", bar8002)

go func() {
http.ListenAndServe(":8001", server8001)
}()

go func() {
http.ListenAndServe(":8002", server8002)
}()

<-finish
}

func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
func default8001(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8001")
}

func foo8001(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8001: foo ")
}

func bar8001(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8001: bar ")
}

func default8002(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8002")
}

func foo8002(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8002: foo ")
}

func bar8002(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Listening on 8002: bar ")
}

0 comments on commit 1201e3b

Please sign in to comment.