pusher

package module
v0.0.0-...-9f6dca3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2013 License: MIT Imports: 11 Imported by: 0

README

Pusher.go - HTTP Server Push module for Google Go

Pusher.go provides Google Go applications full HTTP Server Push capabilities. Pusher.go relies and conforms to the Basic HTTP Push Relay Protocol to provide understandable publisher/subscriber mechanism above uniquely identifiable channels essentially following the footsteps of its' inspirational source, the NGiNX HTTP push module.

Documentation

See documentation and protocol specification.

Client

A reference client written in JavaScript is available under the example. It should be fairly straightforward to port it into your favourite environment.

License

(The MIT License)

Copyright (c) 2011 Jukka-Pekka Kekkonen <karatepekka@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	ConcurrencyModeBroadcast = iota // Broadcasting
	ConcurrencyModeFILO             // First-in, last-out
	ConcurrencyModeLIFO             // Last-in, first-out
)

Concurrency mode defines the behaviour of channels when there are multiple subscribers. If conflicts occur in FILO and LIFO modes, a 409 Conflict message will be broadcasted to the clients that were kicked out.

View Source
const (
	PollingMechanismLong     = iota // Long-polling
	PollingMechanismInterval        // Interval-polling
)

Polling mechanism defines the behaviour of response-cycles.

Variables

View Source
var DefaultConfiguration = Configuration{
	ChannelCapacity:    20,
	GCInterval:         60e9,
	MaxChannelIdleTime: 600e9,
	PollingTimeout:     20e9,
}

DefaultConfiguration holds some sensible defaults.

View Source
var Logger = log.New(os.Stderr, "", log.LstdFlags)

Logger is the logging facility used by Pusher

Functions

func New

func New(acceptor Acceptor, config Configuration) (p *pusher)

New creates a new pusher that is ready to be muxed into any ServeMux. The new pusher (and any channel in it's context) will behave according to the given configuration options are acceptor logic.

Types

type Acceptor

type Acceptor func(req *http.Request) string

Acceptor is a pre-flight mechanism for a) authenticating incoming subscriber/publisher request and b) extracting a channel id from a request. The channel id is gIf an acceptor decides that the request should NOT be allowed to publish/subscribe, then it must return an empty string.

func QueryParameterAcceptor

func QueryParameterAcceptor(parameterName string) Acceptor

QueryParameterAcceptor accepts all requests and uses always a provided parameter form the query as the channel id.

func StaticAcceptor

func StaticAcceptor(cid string) Acceptor

StaticAcceptor accepts all requests and uses always an static channel id.

type Configuration

type Configuration struct {
	AllowChannelCreation bool   // Can channels be created through subscriber locations.
	ChannelCapacity      int    // The capacity of the channels (queue length, 0=unlimited).
	ConcurrencyMode      int    // The behaviour of channels under concurrent subscribers
	ContentType          string // Override outgoing Content-Type headers.
	GCInterval           int64  // The interval between collecting stale channels (0=disable).
	MaxChannels          int    // Maximum amount of channels (0=unlimited).
	MaxChannelIdleTime   int64  // Maximum idle time for a channel (0=unlimited).
	PollingMechanism     int    // The behaviour of response-cycles.
	PollingTimeout       int64  // Maximum time for a long-polling connection (0=unlimited).
}

Configuration holds various parameters for the server.

type Message

type Message struct {
	ContentType string // HTTP content-type to use
	Payload     []byte // the body to use
	Status      int    // HTTP status code to use
	// contains filtered or unexported fields
}

A Message defines a single application specific data packet, containing the original content-type and body along with a HTTP status code to use when delivering it.

type Stats

type Stats struct {
	Created       int64 // The time the channel was created.
	Delivered     int64 // The amonut of messages delivered.
	LastPublished int64 // The time the last message was published.
	LastRequested int64 // The time the last message was requested.
	Published     int64 // The amount of messages published.
	Subscribers   int   // The amount of active subscribers.
	Queued        int   // The amount of messages queued.
}

Stats holds information about a channel.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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