ggi

package module
v0.0.0-...-4e93929 Latest Latest
Warning

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

Go to latest
Published: May 2, 2016 License: GPL-3.0 Imports: 6 Imported by: 0

README

GGI

The Go Gateway Interface (GGI) is an experimental universal interface between servers and Go programs so that requests can be handled by modularized Go packages.

Basically, Go packages compile fast. Why not leverage this? This is an experimental project that takes advantage of that fact to handle web requests using the approach CGI basically takes. A request handled by GGI flows as such:

  1. Request encountered by the GGI server
  2. GGI server looks up registered routes to find a corresponding process
  3. GGI server attempts to hand off the request to that process
  • if process is already running, hand off the request and go to step 6
  1. If the process is not running the GGI server looks where the go files would be and attempts to compile them
  2. The process is then started and the request is handed to it
  3. The process returns a response
  4. The response gets returned to the request origin

Pretty basic and a bit too simplistic, but it works.

It's still buggy, but it you want to try some things using this idea I have another repository that includes an implementation of GGI for "practical" (in quotes because it's still shit) use. https://github.com/corvuscrypto/gserve

Route Registration

Route registration is handled by a single function, RegisterRoute. This is where you declare which package handles requests

E.g. if I want to have a single-file main package with the file index.go handle the top level of my site (i.e. '/') then I would just register the route using ggi.RegisterRoute("/","index.go").

Now let's say I have a larger main package under the directory test_mod/ and I want the route "/test/" to go there. Easy enough I just use ggi.RegisterRoute("/test/", "test_mod/")

Request Handling

In order to pass off your incoming requests, use the HandleRequest method. The way I do this is to add it to my webserver as a handler using the http.HandleFunc method. This works well.

Compilation

I took the lazy route with compiling main packages. I just execute the "go build" command :P. Obviously this causes issues with go packages that have special build flags that need to be applied but I will work on this at some point, just not yet.

Current Goals

Basically this was step one: Get something, anything working.

Now I'm working on getting it refined so that request data is not just essentially a ping, and responses aren't just

Benefits

The most obvious benefit is that when you have a go file that won't compile (not really an issue for those that use most modern IDE's and editors) it won't break your entire application.

A less bvious benefit is unexpected process failure due to an unexpected condition. E.g. a nil pointer error that results in an uncaught panic. While I haven't fully implemented the behavior for this situation, the idea that this process can fail without causing your entire application to go down is pretty comforting.

Also. This was done in 1.5 days as of this writing so give me a break eh? ;)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoute

func RegisterRoute(path, filepath string)

RegisterRoute registers a path from a request to a particular executable file

func Serve

func Serve()

Serve sets ggi up for communication with processes over a unix socket

Types

type PManager

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

PManager is the primary process manager

type Server

type Server struct {
	ServerPort              int
	MaxProcessManagers      int
	StartingProcessManagers int
	DynamicManagement       bool
	ProcessTimeout          int
	// contains filtered or unexported fields
}

Server contains configuration information for the ggi server. Some fields are ignored depending on settings. E.g. ProcessTimeout is only relevant if DynamicManagement is true.

func (*Server) RegisterRoute

func (s *Server) RegisterRoute(path, filepath string)

RegisterRoute registers a path from a request to a particular executable file

func (*Server) Serve

func (s *Server) Serve()

Serve using the associated Server's configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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