github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/acceptance/testdata/mock_stack/windows/run/server.go (about) 1 /* 2 -p="8080": port to expose 3 -g: file globs to read (comma-separated) 4 */ 5 package main 6 7 import ( 8 "flag" 9 "log" 10 "net/http" 11 "os" 12 "path/filepath" 13 "strings" 14 ) 15 16 func main() { 17 port := flag.String("p", "8080", "port to expose") 18 glob := flag.String("g", "", "file globs to read") 19 flag.Parse() 20 21 var resp []string 22 23 globs := strings.Split(*glob, ",") 24 for _, glob := range globs { 25 paths, err := filepath.Glob(strings.TrimSpace(glob)) 26 if err != nil { 27 panic(err.Error()) 28 } 29 30 for _, path := range paths { 31 contents, err := os.ReadFile(filepath.Clean(path)) 32 if err != nil { 33 panic(err.Error()) 34 } 35 36 resp = append(resp, string(contents)) 37 } 38 } 39 40 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 41 w.Write([]byte(strings.Join(resp, "\n"))) 42 }) 43 44 log.Printf("Serving %s on HTTP port: %s\n", *glob, *port) 45 log.Fatal(http.ListenAndServe(":"+*port, nil)) 46 }