Skip to content

Instantly share code, notes, and snippets.

@kylemarsh
Last active August 29, 2015 14:25
Show Gist options
  • Save kylemarsh/f638e8ae705868d28ad0 to your computer and use it in GitHub Desktop.
Save kylemarsh/f638e8ae705868d28ad0 to your computer and use it in GitHub Desktop.
Hello World for running Go under FCGI
# Rename the binary created from hello-fcgi.go to "fcgitest.fcgi"
# chmod 755 fcgitest.fcgi
# Credit goes to http://www.dav-muz.net/blog/2013/09/how-to-use-go-and-fastcgi/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ fcgitest.fcgi/$1 [QSA,L]
package main
import (
"fmt"
"net/http"
"net/http/fcgi"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World!")
}
func main() {
http.HandleFunc("/", hello)
fcgi.Serve(nil, nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment