-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
42 lines (34 loc) · 976 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"net/http"
"log"
"io/ioutil"
"runtime"
)
func main() {
indexData, err := ioutil.ReadFile("static/index.html")
if err != nil {
log.Fatalf("Could not read index file: %s\n", err)
}
wasmExecLocation := runtime.GOROOT() + "/misc/wasm/wasm_exec.js"
wasmExecData, err := ioutil.ReadFile(wasmExecLocation)
if err != nil {
log.Fatalf("Could not read wasm_exec file: %s\n", err)
}
wasmData, err := ioutil.ReadFile("bundle.wasm")
if err != nil {
log.Fatalf("Could not read wasm file: %s\n", err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(indexData)
})
http.HandleFunc("/wasm_exec.js", func(w http.ResponseWriter, r *http.Request) {
w.Write(wasmExecData)
})
http.HandleFunc("/bundle.wasm", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/wasm")
w.WriteHeader(http.StatusOK)
w.Write(wasmData)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}