gridas

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2014 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelayerHost     = "X-Relayer-Host"
	RelayerProtocol = "X-Relayer-Protocol"
	RelayerTraceID  = "X-Relayer-Traceid"
)

Constants names of the header fields used by Rush

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	//Channel for getting petitions
	GetFrom <-chan *Petition
	//Configuration object
	Cfg *config.Config
	//Session seed for mongo
	SessionSeed *mgo.Session
	//http.Client for making requests to target host
	Client http.Client
	// contains filtered or unexported fields
}

Consumer is in charge of taking up petitions from the "GetFrom" channel and making the actual request to the target host, saving the answer and deleting the petition after that.

func (*Consumer) Start

func (c *Consumer) Start(n int) <-chan bool

Start starts n goroutines for taking Petitions from the GetFrom channel. It returns a channel for notifying when the consumer has ended (hopefully after a Stop() method invocation).

func (*Consumer) Stop

func (c *Consumer) Stop()

Stop asks consumer to stop taking petitions. When the stop is complete, the fact will be notified through the channel returned by the Start() method.

type Listener

type Listener struct {
	//Channel for sending petitions
	SendTo chan<- *Petition
	//Configuration object
	Cfg *config.Config

	//Session seed for mongo
	SessionSeed *mgo.Session
	// contains filtered or unexported fields
}

Listener is responsible for receiving requests and storing them in PetitionStore. It then passes a reference to the object Petition which wraps the original HTTP request through the channel Sendto, where the Consumer should collected it for further processing

func (*Listener) ServeHTTP

func (l *Listener) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements HTTP handler interface

func (*Listener) Stop

func (l *Listener) Stop()

Stop asks listener to stop receiving petitions

type Petition

type Petition struct {
	ID           string       `json:"id"`
	TraceID      string       `json:"traceid"`
	TargetHost   string       `json:"targethost"`
	TargetScheme string       `json:"targetscheme"`
	Method       string       `json:"method"` // GET, POST, PUT, etc.
	URL          *url.URL     `json:"-"`
	URLString    string       `json:"urlstring"`
	Proto        string       `json:"proto"` // "HTTP/1.0"
	Header       http.Header  `json:"header"`
	Trailer      http.Header  `json:"trailer"`
	Body         []byte       `json:"body"`
	RemoteAddr   string       `json:"remoteaddr"`
	RequestURI   string       `json:"requesturi"`
	Host         string       `json:"host"`
	Created      time.Time    `json:"created"`
	Session      *mgo.Session `json:,omit`
}

Petition is a representation from the request received. Header fields are cooked to represent the final request meant to be sent to the target host. The relayer's own fields are removed

func (*Petition) Request

func (p *Petition) Request() (*http.Request, error)

Request returns the original http.Request with the body restored as a CloserReader so it can be used to do a request to the original target host

type Recoverer

type Recoverer struct {
	SendTo chan<- *Petition
	//Configuration object
	Cfg *config.Config
	//Session seed for mongo
	SessionSeed *mgo.Session
}

Recoverer takes the petitions stored in PetitionStore and enqueues them again into SendTo.

func (*Recoverer) Recover

func (r *Recoverer) Recover() error

Recover gets all the petitions stored and sends them to a channel for processing by a consumer. It returns when all of them are re-enqueued or when an error happens. It should be run before starting a listener (with the same PetitionStore) or new petitions could be enqueued twice. Listeners with a different PetitionStore should not be a problem. A Consumer can be started before with the same PetitionStore to avoid overflowing the queue.

type Reply

type Reply struct {
	//Reply id. Currently the same as the petition id
	ID      string `json:"id"`
	TraceID string `json:"traceid"`
	//Possible error in making the request. Could be ""
	Error      string      `json:"error"`
	StatusCode int         `json:"statuscode"` // e.g. 200
	Proto      string      `json:"proto"`      // e.g. "HTTP/1.0"
	Header     http.Header `json:"header"`
	Trailer    http.Header `json:"trailer"`
	Body       []byte      `json:"body"`
	//Petition that
	Petition *Petition `json:"petition"`
	//Beginning of the request
	Created time.Time `json:"created"`
	//Time when response was received
	Done time.Time `json:"done"`
}

Reply represents the response from the target host

type Replyer

type Replyer struct {
	Cfg         *config.Config
	SessionSeed *mgo.Session
}

Replyer provides the replies from the destination hosts through HTTP as a JSON document. The response body is encoded in base64

func (*Replyer) ServeHTTP

func (r *Replyer) ServeHTTP(w http.ResponseWriter, req *http.Request)

Directories

Path Synopsis
Package config provides types and a function for getting grush configuration.
Package config provides types and a function for getting grush configuration.
Executable of grush grush.ini contains configuration data read when starting at run-time
Executable of grush grush.ini contains configuration data read when starting at run-time

Jump to

Keyboard shortcuts

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