Skip to content

Instantly share code, notes, and snippets.

@ammmir
Created February 23, 2023 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ammmir/870584151d6f92bd3464f29f04bc6805 to your computer and use it in GitHub Desktop.
Save ammmir/870584151d6f92bd3464f29f04bc6805 to your computer and use it in GitHub Desktop.
ExecAPI samples
// tinygo build -target=generic -target=wasi -gc=leaking -no-debug go-cgi.go
package main
import (
"fmt"
"net/http"
"net/http/cgi"
)
func main() {
req, err := cgi.Request()
if err != nil {
panic(err)
}
err = cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
name := req.URL.Query().Get("name")
if name != "" {
w.Write([]byte(fmt.Sprintf("Hello, %s", name)))
} else {
w.Write([]byte("Hello, anonymous"))
}
}))
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment