Git Product home page Git Product logo

gofcgi's Introduction

Description

a golang client for fastcgi, support connection pool and easy to use.

Pool usage

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

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.