multistream

package
v0.4.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: MIT Imports: 6 Imported by: 0

README

#Multistream-select router This package implements a simple stream router for the multistream-select protocol. The protocol is defined here.

Usage:

package main

import (
	"fmt"
	ms "github.com/whyrusleeping/go-multistream"
	"io"
	"net"
)

func main() {
	mux := ms.NewMultistreamMuxer()
	mux.AddHandler("/cats", func(rwc io.ReadWriteCloser) error {
		fmt.Fprintln(rwc, "HELLO I LIKE CATS")
		return rwc.Close()
	})
	mux.AddHandler("/dogs", func(rwc io.ReadWriteCloser) error {
		fmt.Fprintln(rwc, "HELLO I LIKE DOGS")
		return rwc.Close()
	})

	list, err := net.Listen("tcp", ":8765")
	if err != nil {
		panic(err)
	}

	for {
		con, err := list.Accept()
		if err != nil {
			panic(err)
		}

		go mux.Handle(con)
	}
}

Documentation

Index

Constants

View Source
const ProtocolID = "/multistream/1.0.0"

Variables

View Source
var ErrNotSupported = errors.New("protocol not supported")
View Source
var ErrTooLarge = errors.New("incoming message was too large")

Functions

func ReadNextToken

func ReadNextToken(rw io.ReadWriter) (string, error)

func SelectOneOf

func SelectOneOf(protos []string, rwc io.ReadWriteCloser) (string, error)

func SelectProtoOrFail

func SelectProtoOrFail(proto string, rwc io.ReadWriteCloser) error

Types

type HandlerFunc

type HandlerFunc func(io.ReadWriteCloser) error

type Multistream

type Multistream interface {
	io.ReadWriteCloser
	Protocol() string
}

func NewMSSelect

func NewMSSelect(c io.ReadWriteCloser, proto string) Multistream

func NewMultistream

func NewMultistream(c io.ReadWriteCloser, proto string) Multistream

type MultistreamMuxer

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

func NewMultistreamMuxer

func NewMultistreamMuxer() *MultistreamMuxer

func (*MultistreamMuxer) AddHandler

func (msm *MultistreamMuxer) AddHandler(protocol string, handler HandlerFunc)

func (*MultistreamMuxer) Handle

func (msm *MultistreamMuxer) Handle(rwc io.ReadWriteCloser) error

func (*MultistreamMuxer) Ls

func (msm *MultistreamMuxer) Ls(rwc io.Writer) error

func (*MultistreamMuxer) Negotiate

func (msm *MultistreamMuxer) Negotiate(rwc io.ReadWriteCloser) (string, HandlerFunc, error)

func (*MultistreamMuxer) Protocols

func (msm *MultistreamMuxer) Protocols() []string

func (*MultistreamMuxer) RemoveHandler

func (msm *MultistreamMuxer) RemoveHandler(protocol string)

Jump to

Keyboard shortcuts

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