https://github.com/iwind/gofcgi
golang client for fastcgi
https://github.com/iwind/gofcgi
call client fastcgi fcgi golang
Last synced: 28 days ago
JSON representation
golang client for fastcgi
- Host: GitHub
- URL: https://github.com/iwind/gofcgi
- Owner: iwind
- License: mit
- Created: 2018-10-07T23:59:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-28T02:37:47.000Z (over 4 years ago)
- Last Synced: 2025-10-12T15:32:00.261Z (4 months ago)
- Topics: call, client, fastcgi, fcgi, golang
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 15
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Description
a **golang client for fastcgi**, support connection pool and easy to use.
# Pool usage
~~~golang
// retrieve shared pool
pool := fcgi.SharedPool("tcp", "127.0.0.1:9000", 16)
client, err := pool.Client()
if err != nil {
return
}
// create a request
req := fcgi.NewRequest()
params := map[string]string{
"SCRIPT_FILENAME": "[PATH TO YOUR SCRIPT]/index.php",
"SERVER_SOFTWARE": "gofcgi/1.0.0",
"REMOTE_ADDR": "127.0.0.1",
"QUERY_STRING": "NAME=VALUE",
"SERVER_NAME": "example.com",
"SERVER_ADDR": "127.0.0.1:80",
"SERVER_PORT": "80",
"REQUEST_URI": "/index.php",
"DOCUMENT_ROOT": "[PATH TO YOUR SCRIPT]",
"GATEWAY_INTERFACE": "CGI/1.1",
"REDIRECT_STATUS": "200",
"HTTP_HOST": "example.com",
"REQUEST_METHOD": "POST", // for post method
"CONTENT_TYPE": "application/x-www-form-urlencoded", // for post
}
req.SetTimeout(5 * time.Second)
req.SetParams(params)
// set request body
r := bytes.NewReader([]byte("name=lu&age=20"))
req.SetBody(r, uint32(r.Len()))
// call request
resp, err := client.Call(req)
if err != nil {
return
}
// read data from response
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
log.Println("resp body:", string(data))
~~~