go-fastcgi是为Go语言实现的fastcgi应用库,简单易学。
示例代码:
packagemainimport( "fmt" "fastcgi" "os")typeApplicationstruct{}func(a*Application)Handle(r*fastcgi.Request)bool{ fmt.Fprintf(r.Stdout,"Content-type:text/html\r\n\r\n") fmt.Fprintf(r.Stdout,"helloworld!\n") fmt.Fprintf(r.Stdout,"stdin:(") for{ s,e:=r.Stdin.ReadString('\n') ife!=nil{ break } fmt.Fprintf(r.Stdout,"%s",s) } returntrue}funcmain(){ a:=new(Application) err:=fastcgi.RunStandalone(":12345",a) iferr!=nil{ fmt.Fprintf(os.Stderr,"errinmain:%s",err.String()) os.Exit(1) }}
评论