GithubHelp home page GithubHelp logo

kataras / gofast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yookoala/gofast

0.0 3.0 1.0 74 KB

gofast is a FastCGI client library written purely in go

License: BSD 3-Clause "New" or "Revised" License

Go 93.76% PHP 2.47% Python 3.77%

gofast's Introduction

gofast GoDoc Travis CI results

gofast is a FastCGI "client" library written purely in go.

What does it do, really?

In FastCGI specification, a FastCGI system has 2 components: (a) web server; and (b) application server. A web server should hand over request information to the application server through socket. The application server always listens to the socket and response to socket request accordingly.

visitor → web server → application server → web server → visitor

In ordinary Apache + php-fpm hosting environment, this would be:

visitor → Apache → php-fpm → Apache → visitor

gofast help you to write the code on the web server part of this picture. It helps you to pass the request to application server and receive response from it.

Why?

Many popular languages (e.g. Python, PHP, Ruby) has FastCGI server implementations. With gofast, you may mix the languages without too much complication.

Also, this is fun to do :-)

How to Use?

You basically would use the Handler as http.Handler. You can further mux it with default ServeMux or other compatible routers. You then serve your fastcgi within this golang http server.

Simple Example

Please note that this is only the web server component. You need to start your application component elsewhere.

// this is a very simple fastcgi web server
package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/yookoala/gofast"
)

// NewHandler returns a fastcgi web server implementation as an http.Handler
func NewHandler(root, network, address string) http.Handler {
	h := gofast.NewHandler(gofast.NewPHPFS(root), network, address)
	return h
}

func main() {
	// get fastcgi address from env FASTCGI_ADDR
	fcgiAddr := os.Getenv("FASTCGI_ADDR")

	// handles static assets in the assets folder
	http.Handle("/assets/",
		http.StripPrefix("/assets/",
			http.FileSystem(http.Dir("/var/www/html/assets"))))

	// handle all scripts in document root
	http.Handle("/", NewHandler("/var/www/html", "tcp", fcgiAddr))

	// serve at 8080 port
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Full Examples

Please see the example usages:

Author

This library is written by Koala Yeung.

Contirbuting

Your are welcome to contribute to this library.

To report bug, please use the issue tracker.

To fix an existing bug or implement a new feature, please:

  1. Check the issue tracker and pull requests for existing discussion.
  2. If not, please open a new issue for discussion.
  3. Write tests.
  4. Open a pull request referencing the issue.
  5. Have fun :-)

Licence

This library is release under a BSD-like licence. Please find the LICENCE file in this repository

gofast's People

Contributors

fangdingjun avatar hilyjiang avatar yookoala avatar

Watchers

 avatar  avatar  avatar

Forkers

xormplus

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.