1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
### Go fastcgi client with fcgi params support
[](https://travis-ci.org/tomasen/fcgi_client)
[](http://godoc.org/github.com/tomasen/fcgi_client)
### Examples
simple get request
```go
func main() {
reqParams := "name=value"
env := make(map[string]string)
env["SCRIPT_FILENAME"] = "/home/www/test.php"
env["SERVER_SOFTWARE"] = "go / fcgiclient "
env["REMOTE_ADDR"] = "127.0.0.1"
env["QUERY_STRING"] = reqParams
fcgi, err := fcgiclient.Dial("unix", "/tmp/php-fpm.sock")
if err != nil {
log.Println("err:", err)
}
resp, err := fcgi.Get(env)
if err != nil {
log.Println("err:", err)
}
content, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("err:", err)
}
log.Println("content:", string(content))
}
```
or post form data
```go
func main() {
env := make(map[string]string)
env["SCRIPT_FILENAME"] = "/home/www/test.php"
fcgi, err := fcgiclient.Dial("unix", "/tmp/php-fpm.sock")
if err != nil {
log.Println("err:", err)
}
resp, err := fcgi.PostForm(env, url.Values{"foo": {"bar"}})
if err != nil {
log.Println("err:", err)
}
content, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("err:", err)
}
log.Println("content:", string(content))
}
```
or send file
```go
func main() {
env := make(map[string]string)
env["SCRIPT_FILENAME"] = "/home/www/test.php"
fcgi, err := fcgiclient.Dial("unix", "/tmp/php-fpm.sock")
if err != nil {
log.Println("err:", err)
}
resp, err := fcgi.PostFile(env, url.Values{"foo": {"bar"}}, map[string]string{"file1":"/path/to/file1"})
if err != nil {
log.Println("err:", err)
}
content, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("err:", err)
}
log.Println("content:", string(content))
}
```
More examples can be found in [fcgiclient_test.go](https://github.com/tomasen/fcgi_client/src/tip/fcgiclient_test.go)
### Functions
#### func Dial
func Dial(network, address string) (fcgi *FCGIClient, err error)
Connects to the fcgi responder at the specified network address. See func [net.Dial](http://golang.org/pkg/net/#Dial) for a description of the network and address parameters.
#### func DialTimeout
func DialTimeout(network, address string, timeout time.Duration) (fcgi *FCGIClient, err error)
Connects to the fcgi responder at the specified network address with timeout. See func [net.DialTimeout](http://golang.org/pkg/net/#DialTimeout) for a description of the network, address and timeout parameters.
#### func (*FCGIClient) Get
func (this *FCGIClient) Get(p map[string]string) (resp *http.Response, err error)
Get issues a GET request to the fcgi responder.
#### func (*FCGIClient) Post
func (this *FCGIClient) Post(p map[string]string, bodyType string,
body io.Reader, l int) (resp *http.Response, err error)
Get issues a Post request to the fcgi responder. with request body in the format that bodyType specified
#### func (*FCGIClient) PostFile
func (this *FCGIClient) PostFile(p map[string]string, data url.Values,
file map[string]string) (resp *http.Response, err error)
PostFile issues a POST to the fcgi responder in multipart(RFC 2046) standard, with form as a string key to a list values (url.Values), and/or with file as a string key to a list file path.
#### func (*FCGIClient) PostForm
func (this *FCGIClient) PostForm(p map[string]string,
data url.Values) (resp *http.Response, err error)
PostForm issues a POST to the fcgi responder, with form as a string key to a list values (url.Values)
#### func (*FCGIClient) Request
func (this *FCGIClient) Do(p map[string]string, req io.Reader) (r io.Reader, err error)
Request returns a HTTP Response with Header and Body from fcgi responder
#### func (*FCGIClient) Do
func (this *FCGIClient) Request(p map[string]string,
req io.Reader) (resp *http.Response, err error)
Do made the request and returns a io.Reader that translates the data read from fcgi responder out of fcgi packet before returning it.
#### func (*FCGIClient) Close
func (this *FCGIClient) Close()
Close fcgi connnection
|