proxy

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2018 License: Apache-2.0 Imports: 31 Imported by: 0

README

grpc-fastcgi-proxy

Simple grpc-to-fastcgi proxy.

Status

This is little more than an experiment. It works in the trivial example cases.

Motivation

There is an official grpc client for PHP, but no server support. At my dayjob, we use a lot of PHP, so I wanted to experiment with gRPC servers in PHP.

This project is only the proxy. There is another repo with an example PHP application. That example is used in the testing of this project.

Building/Installing

You need a working Go installation.

Clone this repository into your GOPATH and build the command. For example:

cd $HOME
mkdir -p go/src/github.com/bakins
cd go/src/github.com/bakins
git clone github.com/bakins/grpc-fastcgi-proxy
cd grpc-fastcgi-proxy
go build ./cmd/grpc-fastcgi-proxy

You should now have a grpc-fastcgi-proxy binary

Usage

$ ./grpc-fastcgi-proxy --help
grpc to fastcgi proxy

Usage:
  grpc-fastcgi-proxy [flags]

Flags:
  -a, --address string   listen address (default "127.0.0.1:8080")
  -f, --fastcgi string   fastcgi to proxy (default "127.0.0.1:9000")
  -h, --help             help for grpc-fastcgi-proxy

grpc-fastcgi-proxy is intended to be used with single entrypoint applications. You should do all your routing in index.php, for example. This entry file should be passed as an argument to grpc-fastcgi-proxy:

$ ./grpc-fastcgi-proxy $HOME/git/grpc-fastcgi-example/index.php

It will set the SCRIPT_FILE and DOCUMENT_ROOT cgi variables.

TODO

  • general code cleanup
  • convert HTTP status codes to corresponding gRPC error codes

License

See LICENSE

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Codec

func Codec() grpc.Codec

Codec returns a proxying grpc.Codec with the default protobuf codec as parent.

See CodecWithParent.

func CodecWithParent

func CodecWithParent(fallback grpc.Codec) grpc.Codec

CodecWithParent returns a proxying grpc.Codec with a user provided codec as parent.

This codec is *crucial* to the functioning of the proxy. It allows the proxy server to be oblivious to the schema of the forwarded messages. It basically treats a gRPC message frame as raw bytes. However, if the server handler, or the client caller are not proxy-internal functions it will fall back to trying to decode the message using a fallback codec.

func NewLogger

func NewLogger() (*zap.Logger, error)

NewLogger creates a new logger with our preferred options

func SetAddress

func SetAddress(addr string) func(*Server) error

SetAddress creates a function that will set the listening address. Generally, used when create a new Server.

func SetAuxAddress added in v0.3.0

func SetAuxAddress(addr string) func(*Server) error

SetAuxAddress creates a function that will set the aux address. Generally, used when create a new Server.

func SetEntryFile

func SetEntryFile(f string) func(*Server) error

SetEntryFile creates a function that will set the entryfile for php. Generally, used when create a new Server.

func SetFastCGIEndpoint

func SetFastCGIEndpoint(endpoint string) func(*Server) error

SetFastCGIEndpoint creates a function that will set the fastCGI endpoint to proxy. Endpoint should be url. Default is tcp://127.0.0.1:9090 Generally, used when create a new Server.

func SetLogger

func SetLogger(l *zap.Logger) func(*Server) error

SetLogger creates a function that will set the logger. Generally, used when create a new Server.

Types

type OptionsFunc

type OptionsFunc func(*Server) error

OptionsFunc is a function passed to New to set options.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an http/2 server that proxies to fastcgi

func NewServer

func NewServer(options ...OptionsFunc) (*Server, error)

NewServer creates a new Server.

func (*Server) AddAuxPath added in v0.3.0

func (s *Server) AddAuxPath(path string, filename string) error

AddAuxPath adds a path to be served on the auxiliary port. if filename is empty, then the current working directory plus path is used

func (*Server) Run

func (s *Server) Run() error

Run starts the server. Generally this never returns.

func (*Server) Stop

func (s *Server) Stop()

Stop will stop the server

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL