mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2026-01-12 01:59:14 +00:00
28 lines
523 B
Go
28 lines
523 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"net/http"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
wasmhttp "github.com/nlepage/go-wasm-http-server/v2"
|
||
|
|
)
|
||
|
|
|
||
|
|
var binaryName = ""
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
|
||
|
|
res.Header().Add("Content-Type", "application/json")
|
||
|
|
if err := json.NewEncoder(res).Encode(map[string]string{
|
||
|
|
"message": fmt.Sprintf("Hello from %s at path %s", binaryName, os.Getenv("WASM_HTTP_PATH")),
|
||
|
|
}); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
wasmhttp.Serve(nil)
|
||
|
|
|
||
|
|
select {}
|
||
|
|
}
|