Created
February 23, 2023 15:49
-
-
Save ammmir/870584151d6f92bd3464f29f04bc6805 to your computer and use it in GitHub Desktop.
ExecAPI samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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