ztripper

package module
v0.0.0-...-0869312 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2016 License: MIT Imports: 4 Imported by: 0

README

ZMQ RoundTripper support for go

ztripper is used for providing a RoundTripper interface that uses ZMQ as a transport. A RoundTripper is described as:

RoundTripper is an interface representing the ability to execute a single HTTP transaction, obtaining the Response for a given Request.

Why

After looking into HTTP2 support worked in go 1.6+ I decided it would be fun to try to make something similar work with ZMQ. The interesting result is that you can use a regular http.Client to make ZMQ requests.

Example

Run the server.py (requires pyzmq) and then run the following example:

package main

import (
	"fmt"
	"github.com/hodgesds/ztripper"
	"net/http"
)

func main() {
	t := &http.Transport{}

	zReqTripper, err := ztripper.NewZmqTripper(ztripper.NewByteSerializer())
	if err != nil {
		panic(err)
	}
	defer zReqTripper.Destroy()

	// register the zmq scheme to the transport
	// XXX: different schemes for different socket types?
	t.RegisterProtocol("zmq", zReqTripper)

	c := &http.Client{Transport: t}

	res, err := c.Get("zmq://127.0.0.1:8001/foo/bar/baz?qux=1")
	if err != nil {
		panic(err)
	}

	fmt.Println(res)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSerializer

type ByteSerializer struct{}

func NewByteSerializer

func NewByteSerializer() *ByteSerializer

func (ByteSerializer) Marshal

func (bs ByteSerializer) Marshal(req *http.Request) ([]byte, error)

func (ByteSerializer) Unmarshal

func (bs ByteSerializer) Unmarshal(b []byte) (*http.Response, error)

type Serializer

type Serializer interface {
	Marshal(*http.Request) ([]byte, error)
	Unmarshal([]byte) (*http.Response, error)
}

type ZmqTripper

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

func NewZmqTripper

func NewZmqTripper(
	serializer Serializer,
) (*ZmqTripper, error)

func (*ZmqTripper) Destroy

func (zrt *ZmqTripper) Destroy()

func (*ZmqTripper) RoundTrip

func (zrt *ZmqTripper) RoundTrip(
	req *http.Request,
) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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