git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/httpx/example/main.go (about) 1 package main 2 3 import ( 4 "embed" 5 "io/fs" 6 "log" 7 "net/http" 8 "os" 9 10 "git.sr.ht/~pingoo/stdx/httpx" 11 ) 12 13 //go:embed webapp/* 14 var webapp embed.FS 15 16 func main() { 17 server := http.NewServeMux() 18 webappFS, _ := fs.Sub(webapp, "webapp") 19 webappHandler, err := httpx.WebappHandler(webappFS, nil) 20 if err != nil { 21 log.Fatal(err) 22 return 23 } 24 25 port := os.Getenv("PORT") 26 if port == "" { 27 port = "8080" 28 } 29 server.HandleFunc("/", webappHandler) 30 err = http.ListenAndServe(":"+port, server) 31 if err != nil { 32 log.Fatal(err) 33 } 34 }