go-fastcgi 是为 Go 语言实现的 fastcgi 应用库,简单易学。
示例代码:
package main import ( "fmt" "fastcgi" "os" ) type Application struct { } func (a *Application) Handle(r *fastcgi.Request) bool { fmt.Fprintf(r.Stdout, "Content-type: text/html\r\n\r\n") fmt.Fprintf(r.Stdout, "hello world!\n") fmt.Fprintf(r.Stdout, "stdin: (") for { s, e := r.Stdin.ReadString('\n') if e != nil { break } fmt.Fprintf(r.Stdout, "%s", s) } return true } func main() { a := new(Application) err := fastcgi.RunStandalone(":12345", a) if err != nil { fmt.Fprintf(os.Stderr, "err in main: %s", err.String()) os.Exit(1) } }