Giter VIP home page Giter VIP logo

fcgi_client's Introduction

Go fastcgi client with fcgi params support

Build Status GoDoc

Examples

simple get request

    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

    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

    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

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 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 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

fcgi_client's People

Contributors

tomasen avatar valichek avatar pigi72333 avatar ypyf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.