istio.io/istio@v0.0.0-20240520182934-d79c90f27776/samples/health-check/server.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"net/http"
    19  )
    20  
    21  func main() {
    22  	finish := make(chan bool)
    23  	server8001 := http.NewServeMux()
    24  	server8001.HandleFunc("/foo", foo8001)
    25  	server8001.HandleFunc("/bar", bar8001)
    26  
    27  	server8002 := http.NewServeMux()
    28  	server8002.HandleFunc("/foo", foo8002)
    29  	server8002.HandleFunc("/bar", bar8002)
    30  
    31  	go func() {
    32  		http.ListenAndServe(":8001", server8001)
    33  	}()
    34  
    35  	go func() {
    36  		http.ListenAndServe(":8002", server8002)
    37  	}()
    38  
    39  	<-finish
    40  }
    41  
    42  func foo8001(w http.ResponseWriter, _ *http.Request) {
    43  	w.Write([]byte("Listening on 8001: foo "))
    44  }
    45  
    46  func bar8001(w http.ResponseWriter, _ *http.Request) {
    47  	w.Write([]byte("Listening on 8001: bar "))
    48  }
    49  
    50  func foo8002(w http.ResponseWriter, _ *http.Request) {
    51  	w.Write([]byte("Listening on 8002: foo "))
    52  }
    53  
    54  func bar8002(w http.ResponseWriter, _ *http.Request) {
    55  	w.Write([]byte("Listening on 8002: bar "))
    56  }