mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
src/examples/wasm: Show both methods supported
Adds another example showing the simple case of executing main, adds a README explaining how everything fits together and how to execute the compiled code in the browser. Include a minimal webserver for local testing.
This commit is contained in:
committed by
Ron Evans
parent
a00a51e70e
commit
586023b45d
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const dir = "./html"
|
||||
|
||||
func main() {
|
||||
fs := http.FileServer(http.Dir(dir))
|
||||
log.Print("Serving " + dir + " on http://localhost:8080")
|
||||
http.ListenAndServe(":8080", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
if strings.HasSuffix(req.URL.Path, ".wasm") {
|
||||
resp.Header().Set("content-type", "application/wasm")
|
||||
}
|
||||
|
||||
fs.ServeHTTP(resp, req)
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user