gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/go-control-plane/internal/upstream/main.go (about) 1 // Copyright 2020 Envoyproxy 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 package main 15 16 import ( 17 "flag" 18 "fmt" 19 "log" 20 "net/http" 21 ) 22 23 func main() { 24 var ( 25 upstreamPort uint 26 hello string 27 ) 28 29 flag.UintVar(&upstreamPort, "upstream", 18080, "Upstream HTTP/1.1 port") 30 flag.StringVar(&hello, "message", "Default message", "Message to send in response") 31 flag.Parse() 32 33 log.Printf("upstream listening HTTP/1.1 on %d\n", upstreamPort) 34 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 35 if _, err := w.Write([]byte(hello)); err != nil { 36 log.Println(err) 37 } 38 }) 39 if err := http.ListenAndServe(fmt.Sprintf(":%d", upstreamPort), nil); err != nil { 40 log.Println(err) 41 } 42 }